Like many other organic chemists, you are busy in synthesizing, separating, purifying and identifying new chemical compounds all year round. Getting bored with traditional substance isolation and identification methods, such as column chromatography, a bold idea comes to your mind: Computer Assisted Molecule Identification (CAMI). With this technology, millions of chemists can be freed from arduous manual labor. How promising!
Currently, you are developing a simplified version of CAMI that works for hydrocarbons (organic compounds consisting of hydrogen and carbon only). All hardware-side technologies are done, and you are just going to write the program. The sensor reports all carbon atoms as well as the chemical bonds between them. This naturally forms a graph, where carbon atoms are vertices, and the bonds are edges. Each connected component of this graph corresponds to a molecule, and the component itself is called hydrogen-depleted molecular graph (HDMG) of the molecule, since we generally do not care about hydrogen atoms.
The sensor has just detected some hexane molecules, which is a specific kind of hydrocarbons, consisting of 6 carbon atoms and 14 hydrogen atoms per molecule. There are five essentially different hexanes, also known as isomers:
Your task is to identify, for each hexane molecule detected, which specific type of hexane isomer it is. A molecule should be identified as any of the above isomers if its hydrogen-depleted molecular graph is isomorphic to the HDMG presented in the above table.
输入描述:
1 2 3 4 5
The firstlineof input consists of only a single integer T (1≤T≤200000), denoting thenumberof hexane molecules detected.
Every fivelinesofthe remaining part ofthe input specify a molecule detected. Each ofthefivelinescontainstwo integers a, b (1≤a,b≤6,a≠b), denoting a bond between carbon atoms aand b. In each molecule, the carbon atoms are numbered 1 through 6.
It is guaranteed that, foreach molecule inthe input, it is exactly one type ofthe hexane isomers listed above.
输出描述:
1
For each molecule inthe input, display the name ofthe isomer inoneline.
voidsolve(){ int p[10] = {0}; int d[10] = {0}; vector<int> ne[10]; int c = 0; bool flag = false; for (int i = 1; i <= 5; i++) { int a, b; cin >> a >> b; ne[a].push_back(b); ne[b].push_back(a); p[a] ++; p[b] ++; }
for (int i = 1; i <= 6; i++) { d[p[i]]++; } for (int i = 1; i <= 6; i++) { if (p[i] != 2) continue; for (int k = 0; k < ne[i].size(); k++) { if (p[i] == p[ne[i][k]] && p[i] == 2) { flag = true; break; } } }
Dr. JYY has just created the Coffee Chicken strings, denoted as S(n). They are quite similar to the Fibonacci soup — today’s soup is made by mingling yesterday’s soup and the day before yesterday’s soup: $ S(1)=”COFFEE”S(1) = \texttt{“COFFEE”}S(1)=”COFFEE”;$ $- S(2)=”CHICKEN”S(2) = \texttt{“CHICKEN”}S(2)=”CHICKEN”;$ $- S(n) = S(n-2) :: S(n-1), where :: denotes string concatenation.$ The length of S(n) quickly gets out of control as n increases, and there would be no enough memory in JYY’s game console to store the entire string. He wants you to find 10 contiguous characters in S(n), starting from the kth character.
输入描述:
The first line of input is a single integer$(1 \leq T \leq 1000)$, denoting the number of test cases. Each of the following T lines is a test case, which contains two integers n, k $(1 \leq n \leq 500, 1 \leq k \leq \min{|S(n)|, 10^{12}}$). |S| denotes the length of string S.
输出描述:
1
For each test case, print the answer inoneline. If there are no enough charactersfromthe kth character, output all charactersuntiltheendofthestring.
Recently, an interesting balloon-popping game can be commonly found near the streets. The rule of this game is quite simple: some balloons are tied to cells of a lattice, and you are allowed to throw some darts to prick the balloons. The more balloons you pierce, the more incredible prize you will get.
Probably because too many people have got bored with this childish game, a new variation of the game has appeared. In this variation, you should prick the balloons by shooting an air rifle instead of throwing darts. You can make six shots in total, three horizontally and three vertically. If you shoot horizontally (vertically, resp.), all balloons in the row (column, resp.) are popped. In order to increase the difficulty, there is one restriction imposed on your shots: the distances between any two adjacent horizontal shots and any two adjacent vertical shots must all equal to a given number r. The problem is, what is the maximum number of balloons you can pop by making three horizontal and three vertical shots, under the aforementioned restriction.
输入描述:
1 2 3
The firstlineof input is two integers n, r (1≤n,r≤105), thenumberof balloons andthe distance between anytwo adjacent horizontal or vertical shots.
The remaining part ofthe input is n lines, specifying the positions ofthe balloons. Each of these linescontainstwo integers x, y (0≤x,y≤105), denoting a balloon positioned at (x, y). Note that multiple balloons may lie inthe same position.
int cnt[maxn]; // cnt[i] 表示第 i 列的气球数量 vector <int> h[maxn]; // h[i] 存的是以 i 行为中心位置的所有气球的行数 multiset<int> s; // 存放各行的气球数量 voidadd(int x){ // 这个地方存在着一个非常妙的贪心,比如说有2行的气球总数是相同的,但是由于我们是从低行到高行的顺序枚举的,所以这里对应的 p 一定是对应的低行的数据,而且找到了之后我们就会更新,也不会影响之后高行的查找,非常妙的一个思想 auto p = s.find(cnt[x]); // 非常需要注意这里返回的是迭代器而不是下标 s.erase(p); cnt[x]++; s.insert(cnt[x]); }
// 更新对于第 x 列里的气球与 s 中出现冲突的列的数量,什这样讲可能会比较绕,什么意思呢?比如下面的例子(这里必须很清楚): // 0 0 0 0 1 // 1 1 1 0 0 // 1 0 0 0 0 // 1 1 1 0 0 // 0 0 0 0 1 // 我们在枚举行的时候: // 第1行:和第5列冲突,在排除冲突之后我们直接行的所有气球数量 + 最大竖着的三列的气球数量就可以求出最终的以第1行为中心的 // 第2行:和第1,2,3列冲突,.... // ...... voiddel(int x){ // 这可以实现:如果之前不存在,我们就按照普通情况加上这个数就OK了,反之更新一下再插回去就可以了 auto p = s.find(cnt[x]); s.erase(p); cnt[x]--; s.insert(cnt[x]); } //multiset + 思维 intmain() { int n, r, x, y, ans = 0; scanf("%d%d", &n, &r); for (int i = 0; i < n; i++) { scanf("%d%d", &x, &y); h[x].push_back(y); if (x - r >= 0) h[x - r].push_back(y); if (x + r <= M) h[x + r].push_back(y); cnt[y]++; if (y - r >= 0) cnt[y - r]++; if (y + r <= M) cnt[y + r]++; }
for (int i = 0; i <= M; i++) s.insert(cnt[i]);// 往multiset里添加列的气球数
for (int i = 0; i <= M; i++) { int res = (int) h[i].size(); // 三行的气球总数 for (int j = 0; j < res ; j++) { //如果影响了列,就更新 del(h[i][j]); if (h[i][j] - r >= 0) del(h[i][j] - r); if (h[i][j] + r <= M) del(h[i][j] + r); } ans = max(ans, res + (int)(*s.rbegin()));//取最大值 for (int j = 0; j < res ; j++) {//再更新回去 add(h[i][j]); if (h[i][j] - r >= 0) add(h[i][j] - r); if (h[i][j] + r <= M) add(h[i][j] + r); } } printf("%d\n", ans); return0; }
His majesty chatted with Han Xin about the capabilities of the generals. Each had their shortcomings. His majesty asked, How many troops could I lead?" Han Xin replied, Your highness should not lead more than 100000.” His majesty said, And what about you?" For your humble servant, the more the merrier!” said Han Xin.
—Records of the Grand Historian
Han Xin was a military general who served Liu Bang during the Chu-Han contention and contributed greatly to the founding of the Han dynasty. Your friend, in a strange coincidence, also named Han Xin, is a military general as well.
One day you asked him how many troops he led. He was reluctant to tell you the exact number, but he told you some clues in certain form, for example:
- if we count the troops by threes, we have two left over; - if we count by fives, we have three left over; - if we count by sevens, two are left over; - … You wonder the number of his troops, or he was simply lying. More specifically, you would like to know the minimum possible number of troops he leads, and if the minimum number is too large, then you suspect he was lying.
输入描述:
1 2 3
The firstlineof input containstwo integers n, m (1≤n≤100,1≤m≤1018), thenumberof clues he told you andthe threshold that you think he was probably lying.
The remaining part ofthe input are n lines, specifying the clues, Each line consists oftwo integers a, b (0≤b<a<105), representing a clue that b troops are left over if we count them bya's.
输出描述:
1
If there does not exist a non-negative number of troops satisfying all clues, print he was definitely lying; otherwise, if the minimum non-negative possible number of troops is greater than m, print he was probably lying; otherwise, print the minimum non-negative number.