永动WA题机der二周目学习摘录

  • (一)有趣的题目
    • A - 看病要排队 HDU - 1873
      • Input
      • Output
      • Sample Input
      • Sample Output
      • 对题目的理解
      • 代码
    • B - 排列2 POJ - HDU - 1716
      • Input
      • Output
      • Sample Input
      • Sample Output
      • 理解
      • AC代码
    • C - Ananagrams UVA - 156
      • Input
      • Output
      • Sample Input
      • Sample Output
      • 理解
      • AC代码
    • D - The Blocks Problem UVA - 101
      • Input
      • Output
      • Sample Input
      • Sample Output
      • 理解
      • 书本知识摘录
      • AC代码
    • E - 交换学生 UVA - 10763
      • Input
      • Output
      • Sample Input
      • Sample Output
      • 理解
      • AC代码
    • F - 代码对齐 UVA - 1593
      • Input
      • Output
      • Sample Input
      • Sample Output
      • 理解
      • AC代码
    • G - 对称轴 UVA - 1595
      • Input
      • Output
      • Sample Input
      • Sample Output
      • 理解
      • AC代码
    • H - 更新字典 UVA - 12504
      • Input
      • Output
      • Sample Input
      • Sample Output
      • 理解
      • AC代码
    • I - 图形面积
      • Input
      • Output
      • Sample Input
      • Sample Output
      • 理解
      • AC代码
    • J - 电梯问题
      • Input
      • Output
      • Sample Input
      • Sample Output
      • 理解
      • AC代码
  • (二)我get到的点
    • 1.关于STL容器
  • (三)我de感受
    • 1.关于写代码
    • 2.关于学习进度

(一)有趣的题目

A - 看病要排队 HDU - 1873

看病要排队这个是地球人都知道的常识。
不过经过细心的0068的观察,他发现了医院里排队还是有讲究的。0068所去的医院有三个医生(汗,这么少)同时看病。而看病的人病情有轻重,所以不能根据简单的先来先服务的原则。所以医院对每种病情规定了10种不同的优先级。级别为10的优先权最高,级别为1的优先权最低。医生在看病时,则会在他的队伍里面选择一个优先权最高的人进行诊治。如果遇到两个优先权一样的病人的话,则选择最早来排队的病人。
现在就请你帮助医院模拟这个看病过程。

Input

输入数据包含多组测试,请处理到文件结束。
每组数据第一行有一个正整数N(0<N<2000)表示发生事件的数目。
接下来有N行分别表示发生的事件。
一共有两种事件:
1:“IN A B”,表示有一个拥有优先级B的病人要求医生A诊治。(0<A<=3,0<B<=10)
2:“OUT A”,表示医生A进行了一次诊治,诊治完毕后,病人出院。(0<A<=3)

Output

对于每个"OUT A"事件,请在一行里面输出被诊治人的编号ID。如果该事件时无病人需要诊治,则输出"EMPTY"。
诊治人的编号ID的定义为:在一组测试中,"IN A B"事件发生第K次时,进来的病人ID即为K。从1开始编号。

Sample Input

7
IN 1 1
IN 1 2
OUT 1
OUT 2
IN 2 1
OUT 2
OUT 1
2
IN 1 1
OUT 1

Sample Output

2
EMPTY
3
1
1

对题目的理解

 题目要求医生看病的顺序首先按病人的优先级排列,若优先级相同则按先来后到的顺序看病。由此可以想到该题用优先队列来写很合适。

代码

#include <bits/stdc++.h>
using namespace std;struct node{int p; //优先级 int no; //序号 //重载<号 从大到小排序friend bool operator < (const node &a,const node &b){//若优先级不同,则按优先级看病 if(a.p != b.p) return a.p < b.p;//若优先级相同,则按序号看病 else return a.no > b.no;}
};int main(){int t;while(cin >> t){string s;int a,b,k = 1;priority_queue<node> q[4]; //代表三个医生 node dct;while(t--){cin >> s >> a;if(s == "IN"){cin >> b;dct.p = b;dct.no = k++;q[a].push(dct);}else{if(!q[a].empty()){dct = q[a].top();q[a].pop();printf("%d\n",dct.no);}else printf("EMPTY\n");}}} return 0;
}

B - 排列2 POJ - HDU - 1716

Ray又对数字的列产生了兴趣:
现有四张卡片,用这四张卡片能排列出很多不同的4位数,要求按从小到大的顺序输出这些4位数。

Input

每组数据占一行,代表四张卡片上的数字(0<=数字<=9),如果四张卡片都是0,则输入结束。

Output

对每组卡片按从小到大的顺序输出所有能由这四张卡片组成的4位数,千位数字相同的在同一行,同一行中每个四位数间用空格分隔。 每组输出数据间空一行,最后一组数据后面没有空行。

Sample Input

1 2 3 4
1 1 2 3
0 1 2 3
0 0 0 0

Sample Output

1234 1243 1324 1342 1423 1432
2134 2143 2314 2341 2413 2431
3124 3142 3214 3241 3412 3421
4123 4132 4213 4231 4312 4321

1123 1132 1213 1231 1312 1321
2113 2131 2311
3112 3121 3211

1023 1032 1203 1230 1302 1320
2013 2031 2103 2130 2301 2310
3012 3021 3102 3120 3201 3210

理解

 对排列组合函数next_permutation()的运用。该函数的返回值:若没有下一个排列的组合,返回false,否则返回true。每执行一次next_permutation(),就会把新的排列放到原来的空间里。得到字典最小的序列可用sort()。

AC代码

我当时先用一个数组存放了四张牌分别代表的数字,然后sort()排序得到最小序列,然后判断第一张牌是否为0,再用t数组规避重复数字。

#include <bits/stdc++.h>
using namespace std;int main(){int a,b,c,d,k,w = 0;while(cin >> a >> b >> c >> d){if(a == 0 && b == 0 && c == 0 && d == 0) break;int s[5] = {0},t[5] = {0};if(w) cout << endl;w++;s[1] = a;s[2] = b;s[3] = c;s[4] = d;sort(s+1,s+5);int j = 0;k = s[1];for(int i = 1;i <= 4;i++){if(s[1] != 0) cout << s[i];if(s[i] != s[i-1] && s[i] != 0){t[j++] = s[i];}}j = 0;while(next_permutation(s+1,s+5)){if(s[1] == 0) continue;if(s[1] == t[j] && k != 0) printf(" ");else if(s[1] != t[j]){printf("\n");j++;}for(int i = 1;i <= 4;i++){cout << s[i];}k = s[1];}cout << endl;}return 0;
}

C - Ananagrams UVA - 156

Most crossword puzzle fans are used to anagrams — groups of words with the same letters in different orders — for example OPTS, SPOT, STOP, POTS and POST. Some words however do not have this attribute, no matter how you rearrange their letters, you cannot form another word. Such words are called ananagrams, an example is QUIZ.
    Obviously such definitions depend on the domain within which we are working; you might think that ATHENE is an ananagram, whereas any chemist would quickly produce ETHANE. One possible domain would be the entire English language, but this could lead to some problems. One could restrict the domain to, say, Music, in which case SCALE becomes a relative ananagram (LACES is not in the same domain) but NOTE is not since it can produce TONE.
    Write a program that will read in the dictionary of a restricted domain and determine the relative ananagrams. Note that single letter words are, ipso facto, relative ananagrams since they cannot be “rearranged” at all. The dictionary will contain no more than 1000 words.

Input

Input will consist of a series of lines. No line will be more than 80 characters long, but may contain any number of words. Words consist of up to 20 upper and/or lower case letters, and will not be broken across lines. Spaces may appear freely around words, and at least one space separates multiple words on the same line. Note that words that contain the same letters but of differing case are considered to be anagrams of each other, thus ‘tIeD’ and ‘EdiT’ are anagrams. The file will be terminated by a line consisting of a single ‘#’.

Output

Output will consist of a series of lines. Each line will consist of a single word that is a relative ananagram in the input dictionary. Words must be output in lexicographic (case-sensitive) order. There will always be at least one relative ananagram.

Sample Input

ladder came tape soon leader acme RIDE lone Dreis peat
ScAlE orb eye Rides dealer NotE derail LaCeS drIed
noel dire Disk mace Rob dries

Sample Output

Disk
NotE
derail
drIed
eye
ladder
soon

理解

 题目大意是输入一段文本,判断单词能不能改变字母顺序得到一个新的文本中出现的单词。由于文本中的单词以空格分隔,我们可以直接cin输入得到单词,并用一个自定义函数将字母全变为小写然后将字母进行排序,即“标准化”。这样方便后面判断字母能否重组,因为重组的话单词字母相同,经过排序就一致了。

AC代码

#include <bits/stdc++.h>
using namespace std;
vector<string> word;
map<string,int> m;string re(string s){string a = s;for(int i = 0;i < a.length();i++){a[i] = tolower(a[i]);}sort(a.begin(),a.end());return a;
}int main(){string s;while(cin >> s && s != "#"){word.push_back(s);string t = re(s);if(!m.count(t)) m[t] = 0;m[t]++;}vector<string> b;for(int i = 0;i < word.size();i++){if(m[re(word[i])] == 1) b.push_back(word[i]);}sort(b.begin(),b.end());for(int i = 0;i < b.size();i++){cout << b[i] << endl;}return 0;
}

D - The Blocks Problem UVA - 101

Many areas of Computer Science use simple, abstract domains for both analytical and empirical studies. For example, an early AI study of planning and robotics (STRIPS) used a block world in which a robot arm performed tasks involving the manipulation of blocks.
    In this problem you will model a simple block world under certain rules and constraints. Rather than determine how to achieve a specified state, you will “program” a robotic arm to respond to a limited set of commands.
    The problem is to parse a series of commands that instruct a robot arm in how to manipulate blocks that lie on a flat table. Initially there are n blocks on the table (numbered from 0 to n − 1) with block bi adjacent to block bi+1 for all 0 ≤ i < n − 1 as shown in the diagram below:

The valid commands for the robot arm that manipulates blocks are:
• move a onto b
where a and b are block numbers, puts block a onto block b after returning any blocks that are stacked on top of blocks a and b to their initial positions.
• move a over b
where a and b are block numbers, puts block a onto the top of the stack containing block b, after returning any blocks that are stacked on top of block a to their initial positions.
• pile a onto b
where a and b are block numbers, moves the pile of blocks consisting of block a, and any blocks that are stacked above block a, onto block b. All blocks on top of block b are moved to their initial positions prior to the pile taking place. The blocks stacked above block a retain their order when moved.
• pile a over b
where a and b are block numbers, puts the pile of blocks consisting of block a, and any blocks that are stacked above block a, onto the top of the stack containing block b. The blocks stacked above block a retain their original order when moved.
• quit
terminates manipulations in the block world.
    Any command in which a = b or in which a and b are in the same stack of blocks is an illegal command. All illegal commands should be ignored and should have no affect on the configuration of blocks.

Input

The input begins with an integer n on a line by itself representing the number of blocks in the block world. You may assume that 0 < n < 25.
    The number of blocks is followed by a sequence of block commands, one command per line. Your program should process all commands until the quit command is encountered.
    You may assume that all commands will be of the form specified above. There will be no syntactically incorrect commands.

Output

The output should consist of the final state of the blocks world. Each original block position numbered i (0 ≤ i < n where n is the number of blocks) should appear followed immediately by a colon. If there is at least a block on it, the colon must be followed by one space, followed by a list of blocks that appear stacked in that position with each block number separated from other block numbers by a space. Don’t put any trailing spaces on a line.
    There should be one line of output for each block position (i.e., n lines of output where n is the
integer on the first line of input).

Sample Input

10
move 9 onto 1
move 8 over 1
move 7 over 1
move 6 over 1
pile 8 over 6
pile 8 over 5
move 2 over 1
move 4 over 9
quit

Sample Output

0: 0
1: 1 9 2 4
2:
3: 3
4:
5: 5 8 7 6
6:
7:
8:
9:

理解

 这题要求按要求移动方格。move a onto b:把a和b上方的木块全部归位,然后把a摞在b上面。move a over b:把a上方的木块全部归位,然后把a放在b所在木块堆的顶部。pile a onto b:把b上方的木块全部归位,然后把a及上面的木块整体摞在b上面。pile a over b:把a及上面的木块整体摞在b所在木块堆的顶部。每个木块堆的高度不确定,所以用vector来保存很合适;而木块堆的个数不超过n,所以用一个数组来存就可以了。这题起先没思路,看了大佬们的写法才恍然大悟,我的写法是类似刘汝佳书上的代码写法!如果想参考建议直接去康康刘汝佳的书,讲的很详细。

书本知识摘录

AC代码

#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> b[30];
//找到木块所在的位置
void find_b(int a,int& p,int& h){for(p = 0;p < n;p++){for(h = 0;h < b[p].size();h++){if(b[p][h] == a) return;}}
}
//把第p堆高度为h的木块上方的所有木块移回原位
void clear_above(int p,int h){for(int i = h + 1;i < b[p].size();i++){int t = b[p][i];b[t].push_back(t); //把木块t放回原位}//b[p].resize(h+1);b[p].erase(b[p].begin()+h+1,b[p].end());
}
//把第p堆高度为h及其上方的木块整体移动到p2 堆的顶部
void b_onto(int p,int h,int p2){for(int i = h;i < b[p].size();i++){b[p2].push_back(b[p][i]);}//b[p].resize(h);b[p].erase(b[p].begin()+h,b[p].end());
}
void print(){for(int i = 0;i < n;i++){printf("%d:",i);for(int j = 0;j < b[i].size();j++){printf(" %d",b[i][j]);}printf("\n");}
}
int main(){cin >> n;for(int i = 0;i < n;i++){b[i].push_back(i);}int a,b;string s1,s2;while(cin >> s1 && s1 != "quit"){cin >> a >> s2 >> b;int pa, pb, ha, hb;find_b(a, pa, ha);find_b(b, pb, hb);if(pa == pb) continue;if(s2 == "onto") clear_above(pb, hb);if(s1 == "move") clear_above(pa, ha);b_onto(pa, ha, pb);}print();return 0;
}

E - 交换学生 UVA - 10763

Your non-profit organization (iCORE - international Confederation of Revolver Enthusiasts) coordinates a very successful foreign student exchange program. Over the last few years, demand has sky-rocketed and now you need assistance with your task.
    The program your organization runs works as follows: All candidates are asked for their original location and the location they would like to go to. The program works out only if every student has a suitable exchange partner. In other words, if a student wants to go from A to B, there must be another student who wants to go from B to A. This was an easy task when there were only about 50 candidates, however now there are up to 500000 candidates!

Input

The first line oif the input file will contain a single integer N indicating how many test case that your program will test followed by a blank line. Each test case will contain a single character string of up to 80 non-blank characters. Two consecutive input will separated by a blank line.

Output

For each test case, print ‘YES’ on a single line if there is a way for the exchange program to work out, otherwise print ‘NO’.

Sample Input

10
1 2
2 1
3 4
4 3
100 200
200 100
57 2
2 57
1 2
2 1
10
1 2
3 4
5 6
7 8
9 10
11 12
13 14
15 16
17 18
19 20
0

Sample Output

YES
NO

理解

 这题我是用了map和pair容器的套用,首先用pair存放交换生的出发地和目的地,map用于记录是否有刚好交换的学生出现

AC代码

#include<bits/stdc++.h>
using namespace std;int main(){int n;//freopen("test.out","w",stdout);map<pair<int,int>,int> m;while(cin >> n && n){int a,b;while(n--){cin >> a >> b;pair<int,int> p1 = make_pair(a,b);pair<int,int> p2 = make_pair(b,a);if(m[p2]) m[p2]--;else m[p1]++;//cout << m[p1] << " " << m[p2] << endl;if(!m[p2]) m.erase(p2);}if(!m.size()) cout << "YES" << endl;else cout << "NO" << endl;m.clear();}return 0;
}

F - 代码对齐 UVA - 1593

You are working in a team that writes Incredibly Customizable Programming Codewriter (ICPC) which is basically a text editor with bells and whistles. You are working on a module that takes a piece of code containing some definitions or other tabular information and aligns each column on a fixed vertical position, while keeping the resulting code as short as possible, making sure that only whitespaces that are absolutely required stay in the code. So, that the first words on each line are printed at position p1 = 1; the second words on each line are printed at the minimal possible position p2, such that all first words end at or before position p2 − 2; the third words on each line are printed at the minimal possible position p3, such that all second words end at or before position p3 − 2, etc.
    For the purpose of this problem, the code consists of multiple lines. Each line consists of one or
more words separated by spaces. Each word can contain uppercase and lowercase Latin letters, all ASCII punctuation marks, separators, and other non-whitespace ASCII characters (ASCII codes 33 to 126 inclusive). Whitespace consists of space characters (ASCII code 32).

Input

The input file contains one or more lines of the code up to the end of file. All lines (including the last
one) are terminated by a standard end-of-line sequence in the file. Each line contains at least one word, each word is 1 to 80 characters long (inclusive). Words are separated by one or more spaces. Lines of the code can have both leading and trailing spaces. Each line in the input file is at most 180 characters long. There are at most 1000 lines in the input file.

Output

Write to the output file the reformatted, aligned code that consists of the same number of lines, with the same words in the same order, without trailing and leading spaces, separated by one or more spaces such that i-th word on each line starts at the same position pi.
    Note for the Sample:
The ‘⊔’ character in the example below denotes a space character in the actual files (ASCII code 32).

Sample Input

␣␣start:␣␣integer;␣␣␣␣//␣begins␣here
stop:␣integer;␣//␣␣ends␣here
␣s:␣␣string;
c:␣␣␣char;␣//␣temp

Sample Output

start:␣integer;␣//␣begins␣here
stop:␣␣integer;␣//␣ends␣␣␣here
s:␣␣␣␣␣string;
c:␣␣␣␣␣char;␣␣␣␣//␣temp

理解

 因为本题读入的文本有空格所以用getline来行读入然后用stringstream来读取行中以空格分的单词,并将单词存成一个动态数组比较不同列单词的长度,得到每列最长做标准,其余的补空格。当输出最后一个单词时换行。这题我卡了一会,起先是没有构架好思路,然后在朋友的点拨下,想起前几日课上学到的stringstream后来又粗心把比较列最长写成了行最长,还好大佬一下子就看出了我的bug(感恩紫妈)

AC代码

#include<bits/stdc++.h>
using namespace std;int main(){//freopen("test.out","w",stdout);string s;vector<string> v[2000];int maxl[1005] = {0};int t = 0,num = 0;while(getline(cin,s)){stringstream ss(s);string w;while(ss >> w){v[t].push_back(w); if(maxl[num] < w.size()) maxl[num] = w.size();num++;}num = 0;t++;}   for(int i = 0;i < t;i++){for(int j = 0;j < v[i].size();j++){cout << v[i][j];//列最长-单词长度 maxl[j]-v[i][j].size() for(int k = 0; k < maxl[j]-v[i][j].size() && j != v[i].size()-1;k++){cout << ' ';}if(j == v[i].size()-1) cout << endl;else cout << ' ';
//          system("pause");}}return 0;
}

G - 对称轴 UVA - 1595

The figure shown on the left is left-right symmetric as it is possible to fold the sheet of paper along a vertical line, drawn as a dashed line, and to cut the figure into two identical halves. The figure on the right is not left-right symmetric as it is impossible to find such a vertical line.

    Write a program that determines whether a figure, drawn with dots, is left-right symmetric or not. The dots are all distinct.

Input

The input consists of T test cases. The number of test cases T is given in the first line of the input file. The first line of each test case contains an integer N, where N (1 ≤ N ≤ 1, 000) is the number of dots in a figure. Each of the following N lines contains the x-coordinate and y-coordinate of a dot. Both x-coordinates and y-coordinates are integers between −10, 000 and 10, 000, both inclusive.

Output

Print exactly one line for each test case. The line should contain ‘YES’ if the figure is left-right symmetric, and ‘NO’, otherwise.

Sample Input

3
5
-2 5
0 0
6 5
4 0
2 3
4
2 3
0 4
4 0
0 0
4
5 14
6 10
5 10
6 14

Sample Output

YES
NO
YES

理解

 这道题要求找到使所有点对称的对称竖轴。我们可以通过x坐标相加的和sum,x和sum/n*2-x是否在众多x坐标中存在来判断,并要求y坐标的值相同。set要用迭代器来判断pair对应的first值和second值是否符合要求。

AC代码

#include <bits/stdc++.h>
using namespace std;int main(){int t;cin >> t;while(t--){int n;cin >> n;set<pair<int,int> > s;int a,b;int f = 1;double sum = 0;for(int i = 0;i < n;i++){cin >> a >> b;sum += a;pair<int,int> p = make_pair(a,b);s.insert(p);}sum = sum /(1.0*n) * 2.0;set<pair<int,int> >::iterator it;for(it = s.begin();it != s.end();it++){if(s.find(make_pair(sum-(it -> first),it -> second))==s.end()){f = 0;break;}}if(f) cout << "YES" << endl;else cout << "NO" << endl;}return 0;
}

H - 更新字典 UVA - 12504

In this problem, a dictionary is collection of key-value pairs, where keys are lower-case letters, and values are non-negative integers. Given an old dictionary and a new dictionary, find out what were changed.
    Each dictionary is formatting as follows:
        {key:value,key:value,…,key:value}
        Each key is a string of lower-case letters, and each value is a non-negative integer without leading zeros or prefix ‘+’. (i.e. -4, 03 and +77 are illegal). Each key will appear at most once, but keys can appear in any order.

Input

The first line contains the number of test cases T (T ≤ 1000). Each test case contains two lines. The first line contains the old dictionary, and the second line contains the new dictionary. Each line will contain at most 100 characters and will not contain any whitespace characters. Both dictionaries could be empty.
WARNING: there are no restrictions on the lengths of each key and value in the dictionary. That means keys could be really long and values could be really large.

Output

For each test case, print the changes, formatted as follows:
        • First, if there are any new keys, print ‘+’ and then the new keys in increasing order (lexicographically), separated by commas.
        • Second, if there are any removed keys, print ‘-’ and then the removed keys in increasing order
(lexicographically), separated by commas.
        • Last, if there are any keys with changed value, print ‘*’ and then these keys in increasing order
(lexicographically), separated by commas.
If the two dictionaries are identical, print ‘No changes’ (without quotes) instead.
Print a blank line after each test case.

Sample Input

3
{a:3,b:4,c:10,f:6}
{a:3,c:5,d:10,ee:4}
{x:1,xyz:123456789123456789123456789}
{xyz:123456789123456789123456789,x:1}
{first:1,second:2,third:3}
{third:3,second:2}

Sample Output

+d,ee
-b,f
*c
No changes
-first

理解

 这道题要求根据输入的两行文本来判断增加的元素减少的元素和改变的元素我第一反应想到的就是全部遍历一遍,所以写法比较繁琐,还听取大佬意见写了一个print输出函数,本来看起来更复杂(15555)。首先定义两个map容器来存放前后两次出现的元素以及它对应的值,然后存放时注意一个一个取字符要把字符加在前面!然后依次遍历一遍得到三种不同变化的元素,再依次输出。

AC代码

#include <bits/stdc++.h>
using namespace std;
string s[1005];void print(char c,int r){sort(s,s+r);cout << c << s[0];for(int i = 1;i < r;i++)cout << ',' << s[i];cout << endl;
}int main(){int t;cin >> t;while(t--){map<string,string> m1;map<string,string> m2;string a,b;cin >> a >> b;int j = 0;for(int i = 0;i < a.size();i++){string key,value;if(a[i]==':'){int j = i -1;while(a[j] !='{' && a[j] !=','){key = a[j] + key;j--;}j = i + 1;while(a[j] !='}' && a[j] !=','){value = a[j] + value;j++;}   m1[key] = value;}}for(int i = 0;i < b.size();i++){string key,value;if(b[i]==':'){int j = i -1;while(b[j] !='{' && b[j] !=','){key = b[j] + key;j--;}j = i + 1;while(b[j] !='}' && b[j] !=','){value = b[j] + value;j++;}    m2[key] = value;}} int w = 0,sum = 0;map<string,string>::iterator it;for(it = m2.begin();it != m2.end();it++){if(!m1.count(it->first)){s[w++] = it->first;}}if(w) print('+',w);sum += w;w = 0;for(it = m1.begin();it != m1.end();it++){if(!m2.count(it->first)){s[w++] = it->first;}}if(w) print('-',w);sum += w;w = 0;for(it = m2.begin();it != m2.end();it++){if(m1.count(it->first) && m1[it->first] != it ->second){s[w++] = it->first;}}if(w) print('*',w);sum += w;if(!sum) cout << "No changes" << endl;cout << endl;}return 0;
}

I - 图形面积

编程计算由“”号围成的下列图形的面积。面积计算方法是统计号所围成的闭合曲线中水平线和垂直线交点的数目。如下图所示,在1010的二维数组中,有“”围住了15个点,因此面积为15。

Input

输入0-1矩阵(1表示*)

Output

输出面积。

Sample Input

0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 1 1 0 0 0
0 0 0 0 1 0 0 1 0 0
0 0 0 0 0 1 0 0 1 0
0 0 1 0 0 0 1 0 1 0
0 1 0 1 0 1 0 0 1 0
0 1 0 0 1 1 0 1 1 0
0 0 1 0 0 0 0 1 0 0
0 0 0 1 1 1 1 1 0 0
0 0 0 0 0 0 0 0 0 0

Sample Output

15

理解

 这题要求你计算被0包围的1所占的面积。一直想不到思路!结果大佬的涂色法让我眼前一亮!首先开一个足够大的二维数组,将她的四边都遍历为-1即涂上一圈边框。然后进行两边遍历循环,但凡上下左右存在被涂色的-1则将该块也涂成-1。如此遍历下来,得到剩下仍是0的部分就是所求的面积。

AC代码

#include <bits/stdc++.h>
using namespace std;int main(){int a[15][15] = {0};for(int i = 0;i < 12;i++){a[0][i] = -1;a[11][i] = -1;a[i][0] = -1;a[i][11] = -1;}for(int i = 1;i < 11;i++){for(int j = 1;j < 11;j++){scanf("%d",&a[i][j]);}}for(int i = 1;i < 11;i++){for(int j = 1;j < 11;j++){if(a[i][j]==0 &&(a[i-1][j]==-1||a[i+1][j]==-1||a[i][j-1]==-1||a[i][j+1]==-1)){a[i][j] = -1;}}}for(int i = 10;i > 0;i--){for(int j = 10;j > 0;j--){if(a[i][j]==0 &&(a[i-1][j]==-1||a[i+1][j]==-1||a[i][j-1]==-1||a[i][j+1]==-1)){a[i][j] = -1;}}}int sum = 0;for(int i = 1;i < 11;i++){for(int j = 1;j < 11;j++){if(a[i][j]==0){sum++;}}}printf("%d\n",sum);return 0;
}

J - 电梯问题

•大楼的每一层楼都可以停电梯,而且第i层楼(1<=i<=N)上有一个数字Ki(0<=Ki<=N)。电梯只有四个按钮:开,关,上,下。上下的层数等于当前楼层上的那个数字。当然,如果不能满足要求,相应的按钮就会失灵。例如:3 3 1 2 5代表了Ki(K1=3,K2=3,……),从一楼开始。在一楼,按“上”可以到4楼,按“下”是不起作用的,因为没有-2楼。那么,从A楼到B楼至少要按几次按钮呢?

Input

输入数据共有二行,第一行为三个用空格隔开的正整数,表示N,A,B(1≤N≤200, 1≤A,B≤N),第二行为N个用空格隔开的正整数,表示Ki。

Output

输出数据仅一行,即最少按键次数,若无法到达,则输出-1。

Sample Input

5 1 5
3 3 1 2 5

Sample Output

3

理解

 题目要求到达目标楼层的按钮次数最少,且每层有两种情况上升或下降。排除无法完成的下降或上升的情况,遍历楼层,若楼层已经到过记为1,因为反复上同一楼层会导致无限循环。

AC代码

#include <bits/stdc++.h>
using namespace std;int n,start,y,minn = 999999;
int a[205] ={0},b[205]={0};void dfs(int m,int sum){if(m == y){minn = min(minn,sum);}else if(sum <=minn){b[m] = 1; if(m+a[m]<=n && b[m+a[m]]==0) dfs(m+a[m],sum+1); //upif(m-a[m]>=1 && b[m-a[m]]==0) dfs(m-a[m],sum+1); //downb[m] = 0; //回溯 }
}int main(){cin >> n >> start >> y;for(int i = 1;i <= n;i++){scanf("%d",&a[i]);}dfs(start,0);if(minn == 999999) cout << -1;else cout << minn;return 0;
}

(二)我get到的点

1.关于STL容器

 容器部分主要由头文件<vector>、<list>、<deque>、<set>、<map>、<stack>和<queue>组成。对于常用的一些容器和容器

1)Vector:动态数组,运行时根据需要改变数组大小。

String对象作为vector元素,类似字符串数组
s = s + “abc”;
s.append(a);
//将a添加到s尾部,如“AAA”,但字符不可,如’a’;
s.length(); //返回s的长度
s.size() //返回s的大小
s.empty();
//判断s是否为空,若空则返回true,否则返回false
s.insert(s.begin()+i,a); //在i的位置插入a
s.erase(s.begin()+i); s.erase(s.begin()+i,s.begin()+j);
//删除下标i+1的字符,也可填范围
s.replace(strbegin,strlen,a); //开始位,长度,对象
s.find(‘c’);
s.compare(“cat”);
reverse(s.begin(),s.end()); //翻转
sort(s.begin(),s.end())
可直接用的比较函数:
less (降序)
greater(升序)

2) stack:栈,基本的数据结构之一,特点:先进后出。

3) queue:队列,基本的数据结构之一,特点是“先进先出”。

4) 优先队列和poriority_queue
优先队列:优先级最高的先出队
队列和排序的完美结合,不仅可以存储数据,还可以将这些数据按照设定的规则进行排序。
每次的push和pop操作,优先队列都会动态调整,把优先级最高的元素放在前面。
STL中,优先队列是用二叉堆来实现的

5) 链表和list
STL的 list :双向链表。它的内存空间不必连续,通过指针来进行数据的访问,高效率地在任意地方删除和插入,插入和删除操作是常数时间
比较于vector:vector:插入和删除操作少,随机访问元素频繁;list:插入和删除频繁,随机访问较少。

6) Set:集合,STL的set用二叉搜索树实现

7) multiset
#include< set > multiset< string >ms
ms.insert(“abc”) ms.insert(“aaa”)
ms.srase(“aaa”) ms.find(“abc”)!=ms.end()
set集合自动过滤重复,multiset不过滤重复,两者都自动排序
8) map: map<string,int>m;

9)pair: pair<int, string> newone

10) next_permutation
next_permutation() 的返回值:如果没有下一个排列组合,返回false,否则返回true。每执行 next_permutation()一次,就会把新的排列放到原来的空间里。
与之相关的函数:
prev_permutation():求前一个排列的组合


ps:具体对应的不同容器使用的经典例题都放在word文档里了,就不重新拷贝一份了。

(三)我de感受

1.关于写代码

二周目依旧是疯狂WA题的5201大型自闭现场
    1.对于容器有了一定的认识并能运用,有些题目如此做起来的确比以前简单好多。
    2.对于写代码有了对自己更高的要求,将重复的部分自定义函数来进行操作和输出,代码看起来更舒服,给自己加注释方便以后查看自己的代码能快速得到一个清晰的思路。
       3.虽然说不上为什么,总觉得自己好菜,好多题目读题就是个问题,理解英文题题意果然还是需要锻炼的。
       4.这周布置的题集,能写完大部分的很少,还空缺着很多难题,期盼着自己有时间补一补。另外,立下一个这周写洛谷至少五题的flag(我仿佛戏台上的老将军,背上立了flag)。

2.关于学习进度

关于STL这一块与其说是从课堂上学习新的知识点,不如说是在做题中,在一次次的错误提示中搞懂各个容器的用法和优势,也逐渐学会了判断选择更优解法。
    下周的递归这一块,于思维反应迟钝的我而言是一块弱势,还是要多练,多分析,熟能生巧总不会错的。(猛男嘤嘤)感觉以上题目和知识点也没有整理的很详细,果然还是太萌新了,求大佬带,发出了蒟蒻的声音“WA”

集训der二周目学习(练习题+感悟)相关推荐

  1. 不推荐二周目跑重复剧情 不推荐开混10,建议开混11,游戏文本的奖励减半并没有生效. 混10=混11+混乱词条 1.经济获取(学自大佬:小小银Salmon【B站号】) 金币获取:刚通关开混乱11,拿主

    不推荐二周目跑重复剧情 不推荐开混10,建议开混11,游戏文本的奖励减半并没有生效. 混10=混11+混乱词条 1.经济获取(学自大佬:小小银Salmon[B站号]) 金币获取:刚通关开混乱11,拿主 ...

  2. 软件设计师:二周目下午真题

    章节 章节 01 - 计算机组成原理与体系结构 07 - 法律法规与标准化与多媒体基础 02 - 操作系统基本原理 08 - 设计模式 03 - 数据库系统 09 - 软件工程 04 - 计算机网络 ...

  3. 我的世界进入服务器显示rBAB,我的世界1.12.x RBTrixel 二周目生存服务器

    ---- 服务器名称:RBTrixel二周目 ---- 服务器版本:1.12.x ---- 服务器类型:原版生存 ---- 服务器的IP:rb.trixel.xyz ---- 服务器QQ群:78620 ...

  4. 软件设计师:二周目上午真题

    章节 章节 01 - 计算机组成原理与体系结构 07 - 法律法规与标准化与多媒体基础 02 - 操作系统基本原理 08 - 设计模式 03 - 数据库系统 09 - 软件工程 04 - 计算机网络 ...

  5. BIT2023 智慧社区综合管理系统-二周目

    智慧社区管理系统软件需求文档 目录 项目前景和范围文档 1. 业务需求 1.1 应用背景 1.2 业务机遇 1.3 业务目标 1.4 业务风险 2. 项目前景 2.1 前景概述 2.2 主要特性 2. ...

  6. 王坤杨第十二周个人学习及生活情况总结

    # 一.实验室! 1.继续进行MATLAB的安装,然而依旧泪奔!安装了编译python,(这是网址https://www.anaconda.com/)并进行了简单的练习,但是后面隔了一两天,进不去了, ...

  7. (实况野球)恶灵学院(ダンジョン高校)二周目攻略

    你好我是老牛,此篇攻略的目标是击败 普通版的最终Boss,获得光野圣良SR. 请先看完整篇攻略后,根据自己目前拥有的事件角色(イベキャラ)等级和装备,来提升不足的地方. 自2016.8.24更新1.1 ...

  8. Java8实战 阅读二周目感想

    Java8实战是我目前看过的写的水平最高的一本书,由浅入深,深入浅出,九浅一深. 之前大略的过了一遍,但是对于前几章的内容一直有点雾里看花的感觉. 又读了一遍,感觉有点新的感想. 一.其中1.2.1中 ...

  9. 【内蒙古山西の游记(7.17~7.24)】二周目

    第二天 一早起来心情还是极差的,因为好不容易放个假,但是从开始到现在十多天-- 我都没有试过睡过8:00啊!!! 好了,不吐槽造成这个事实的旅行和--(都懂得那个原因) 早上还是包头市内"自 ...

最新文章

  1. 【C++】C++11 STL算法(十):使用STL实现排序算法
  2. 用SAXBuilder、Document、Element操作xml
  3. linux c++ 得到 指定进程名 线程数
  4. c++ 12.一维数组冒泡排序
  5. 打印英文年历C语言函数,C语言打印年历
  6. 解决maven项目没有Maven Dependencies
  7. 如何制作毛玻璃效果?
  8. HttpClient 教程 (六)
  9. Markdown中插入excel表的简便方法
  10. 鸿蒙系统桌面建文件夹,怎样把桌面上的文件放在一个文件夹里
  11. 【风控模型】—WOE与IV指标的深入理解应用
  12. java 错误声音播放器_JavaME 声音播放器的使用
  13. Kafka 发送消息 Idempotent
  14. 初步了解区块链技术落地——FISCO BCOS 快速搭建区块链
  15. 磁盘阵列和存储服务器的区别
  16. 高并发抢红包系统红包随机金额生成算法
  17. Android之世面上程序锁的实现
  18. Python网络爬虫实战:抓取和分析天猫胸罩销售数据
  19. win10记住了远程连接密码,下次登录仍然需要输入密码
  20. 西游记孙悟空迅速从石猴飙升至斗战胜佛大罗金仙的辉煌人生旅程

热门文章

  1. To forever Tracy McGrady
  2. MT6572 flash验证过的时序放到6571上面无法下载
  3. 《学习记录》“Python”成绩百分制转换等级制
  4. 中国人开发的FreeIris开源网络电话通信平台
  5. nil和NULL 的区别
  6. 裸辞3个月扛不住后,随便接了offer更惨!
  7. phantom 输出中文乱码
  8. 批量重命名下载的不规则电视剧文件名
  9. PHP goto操作符使用
  10. 安卓11状态栏图标不显示问题调查