A: Taro's Shopping
Mammy decided to give Taro his first shopping experience. Mammy tells him to choose any two items he wants from those listed in the shopping catalogue, but Taro cannot decide which two, as all the items look attractive. Thus he plans to buy the pair of two items with the highest price sum, not exceeding the amount Mammy allows. As getting two of the same item is boring, he wants two different items.
You are asked to help Taro select the two items. The price list for all of the items is given. Among pairs of two items in the list, find the pair with the highest price sum not exceeding the allowed amount, and report the sum. Taro is buying two items, not one, nor three, nor more. Note that, two or more items in the list may be priced equally.
You are asked to help Taro select the two items. The price list for all of the items is given. Among pairs of two items in the list, find the pair with the highest price sum not exceeding the allowed amount, and report the sum. Taro is buying two items, not one, nor three, nor more. Note that, two or more items in the list may be priced equally.
输入
The input consists of multiple datasets, each in the following format.
n m
a1 a2 … an
A dataset consists of two lines. In the first line, the number of items n and the maximum payment allowed m are given. n is an integer satisfying 2 ≤ n ≤ 1000. m is an integer satisfying 2 ≤ m ≤ 2,000,000. In the second line, prices of n items are given. ai (1 ≤ i ≤ n) is the price of the i-th item. This value is an integer greater than or equal to 1 and less than or equal to 1,000,000.
The end of the input is indicated by a line containing two zeros. The sum of n's of all the datasets does not exceed 50,000.
n m
a1 a2 … an
A dataset consists of two lines. In the first line, the number of items n and the maximum payment allowed m are given. n is an integer satisfying 2 ≤ n ≤ 1000. m is an integer satisfying 2 ≤ m ≤ 2,000,000. In the second line, prices of n items are given. ai (1 ≤ i ≤ n) is the price of the i-th item. This value is an integer greater than or equal to 1 and less than or equal to 1,000,000.
The end of the input is indicated by a line containing two zeros. The sum of n's of all the datasets does not exceed 50,000.
输出
For each dataset, find the pair with the highest price sum not exceeding the allowed amount m and output the sum in a line. If the price sum of every pair of items exceeds m, output NONE instead.
样例输入
3 45
10 20 30
6 10
1 2 5 8 9 11
7 100
11 34 83 47 59 29 70
4 100
80 70 60 50
4 20
10 5 10 16
0 0
样例输出
40 10 99 NONE 20
#include <bits/stdc++.h> using namespace std; bool cmp(int x,int y) { return x>y; } int n,m,a[1005]; int main() { while(1) { scanf("%d%d",&n,&m); if(n==0&&m==0) return 0; for(int i=0;i<n;i++) scanf("%d",&a[i]); sort(a,a+n,cmp); int flag=0,ans=-1; for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { if(a[i]+a[j]<=m) { ans=max(ans,a[i]+a[j]); } } } if(ans==-1) { printf("NONE\n"); } else { printf("%d\n",ans); } } // cout << "Hello world!" << endl; return 0; }
问题 B: Almost Identical Programs
题目描述
The programming contest named Concours de Programmation Comtemporaine Interuniversitaire (CPCI) has a judging system similar to that of ICPC; contestants have to submit correct outputs for two different inputs to be accepted as a correct solution. Each of the submissions should include the program that generated the output. A pair of submissions is judged to be a correct solution when, in addition to the correctness of the outputs, they include an identical program.
Many contestants, however, do not stop including a different version of their programs in their second submissions, after modifying a single string literal in their programs representing the input file name, attempting to process different input. The organizers of CPCI are exploring the possibility of showing a special error message for such close submissions, indicating contestants what's wrong with such submissions. Your task is to detect such close submissions.
Many contestants, however, do not stop including a different version of their programs in their second submissions, after modifying a single string literal in their programs representing the input file name, attempting to process different input. The organizers of CPCI are exploring the possibility of showing a special error message for such close submissions, indicating contestants what's wrong with such submissions. Your task is to detect such close submissions.
输入
The input consists of at most 100 datasets, each in the following format.
s1
s2
Each of s1 and s2 is a string written in a line, with the length between 1 and 200, inclusive. They are the first and the second submitted programs respectively. A program consists of lowercase letters (a, b, ..., z), uppercase letters (A, B, ..., Z), digits (0, 1, ..., 9), double quotes ("), and semicolons (;). When double quotes occur in a program, there are always even number of them.
The end of the input is indicated by a line containing one ‘.’ (period).
s1
s2
Each of s1 and s2 is a string written in a line, with the length between 1 and 200, inclusive. They are the first and the second submitted programs respectively. A program consists of lowercase letters (a, b, ..., z), uppercase letters (A, B, ..., Z), digits (0, 1, ..., 9), double quotes ("), and semicolons (;). When double quotes occur in a program, there are always even number of them.
The end of the input is indicated by a line containing one ‘.’ (period).
输出
For each dataset, print the judge result in a line.
If the given two programs are identical, print IDENTICAL. If two programs differ with only one corresponding string literal, print CLOSE. Otherwise, print DIFFERENT. A string literal is a possibly empty sequence of characters between an odd-numbered occurrence of a double quote and the next occurrence of a double quote.
If the given two programs are identical, print IDENTICAL. If two programs differ with only one corresponding string literal, print CLOSE. Otherwise, print DIFFERENT. A string literal is a possibly empty sequence of characters between an odd-numbered occurrence of a double quote and the next occurrence of a double quote.
样例输入
print"hello";print123
print"hello";print123
read"B1input";solve;output;
read"B2";solve;output;
read"C1";solve;output"C1ans";
read"C2";solve;output"C2ans";
""""""""
"""42"""""
slow"program"
fast"code"
"super"fast"program"
"super"faster"program"
X""
X
I"S""CREAM"
I"CE""CREAM"
11"22"11
1"33"111
.
样例输出
IDENTICAL
CLOSE
DIFFERENT
CLOSE
DIFFERENT
DIFFERENT
DIFFERENT
CLOSE
DIFFERENT
#include <iostream> #include<bits/stdc++.h> using namespace std; char str1[220],str2[220]; int main() { //freopen("in.txt","r",stdin); while(1) { scanf("%s",str1); if(str1[0]=='.') { break; } scanf("%s",str2); int dif=0,cnt=0; int len1=strlen(str1),len2=strlen(str2); int i,j; int flag=0; for(i=0,j=0; i<len1&&j<len2; i++,j++) { if(str1[i]!=str2[j]&&cnt==0) { printf("DIFFERENT\n"); flag=1; break; } else if(str1[i]!=str2[j]&&cnt==1) { dif++; if(dif==2) { printf("DIFFERENT\n"); flag=1; break; } while(str1[i]!='"') { i++; } while(str2[j]!='"') { j++; } } if(str1[i]==str2[j]&&str1[i]=='"') { cnt++; if(cnt==2) { cnt=0; } } } if(i==len1&&j==len2) { if(dif==0) { printf("IDENTICAL\n"); } else if(dif==1) { printf("CLOSE\n"); } } else { if(flag==0) { printf("DIFFERENT\n"); } } } return 0; }
题目描述
Mr. Gardiner is a modern garden designer who is excellent at utilizing the terrain features. His design method is unique: he first decides the location of ponds and design them with the terrain features intact.
According to his unique design procedure, all of his ponds are rectangular with simple aspect ratios. First, Mr. Gardiner draws a regular grid on the map of the garden site so that the land is divided into cells of unit square, and annotates every cell with its elevation. In his design method, a pond occupies a rectangular area consisting of a number of cells. Each of its outermost cells has to be higher than all of its inner cells. For instance, in the following grid map, in which numbers are elevations of cells, a pond can occupy the shaded area, where the outermost cells are shaded darker and the inner cells are shaded lighter. You can easily see that the elevations of the outermost cells are at least three and those of the inner ones are at most two.
A rectangular area on which a pond is built must have at least one inner cell. Therefore, both its width and depth are at least three.
When you pour water at an inner cell of a pond, the water can be kept in the pond until its level reaches that of the lowest outermost cells. If you continue pouring, the water inevitably spills over. Mr. Gardiner considers the larger capacity the pond has, the better it is. Here, the capacity of a pond is the maximum amount of water it can keep. For instance, when a pond is built on the shaded area in the above map, its capacity is (3 − 1) + (3 − 0) + (3 − 2) = 6, where 3 is the lowest elevation of the outermost cells and 1, 0, 2 are the elevations of the inner cells. Your mission is to write a computer program that, given a grid map describing the elevation of each unit square cell, calculates the largest possible capacity of a pond built in the site.
Note that neither of the following rectangular areas can be a pond. In the left one, the cell at the bottom right corner is not higher than the inner cell. In the right one, the central cell is as high as the outermost cells.
According to his unique design procedure, all of his ponds are rectangular with simple aspect ratios. First, Mr. Gardiner draws a regular grid on the map of the garden site so that the land is divided into cells of unit square, and annotates every cell with its elevation. In his design method, a pond occupies a rectangular area consisting of a number of cells. Each of its outermost cells has to be higher than all of its inner cells. For instance, in the following grid map, in which numbers are elevations of cells, a pond can occupy the shaded area, where the outermost cells are shaded darker and the inner cells are shaded lighter. You can easily see that the elevations of the outermost cells are at least three and those of the inner ones are at most two.
![](http://exam.upc.edu.cn/upload/image/20180817/20180817155415_41826.png)
When you pour water at an inner cell of a pond, the water can be kept in the pond until its level reaches that of the lowest outermost cells. If you continue pouring, the water inevitably spills over. Mr. Gardiner considers the larger capacity the pond has, the better it is. Here, the capacity of a pond is the maximum amount of water it can keep. For instance, when a pond is built on the shaded area in the above map, its capacity is (3 − 1) + (3 − 0) + (3 − 2) = 6, where 3 is the lowest elevation of the outermost cells and 1, 0, 2 are the elevations of the inner cells. Your mission is to write a computer program that, given a grid map describing the elevation of each unit square cell, calculates the largest possible capacity of a pond built in the site.
Note that neither of the following rectangular areas can be a pond. In the left one, the cell at the bottom right corner is not higher than the inner cell. In the right one, the central cell is as high as the outermost cells.
![](http://exam.upc.edu.cn/upload/image/20180817/20180817155425_85256.png)
输入
The input consists of at most 100 datasets, each in the following format.
d w
e1, 1 ... e1, w
...
ed, 1 ... ed, w
The first line contains d and w, representing the depth and the width, respectively, of the garden site described in the map. They are positive integers between 3 and 10, inclusive. Each of the following d lines contains w integers between 0 and 9, inclusive, separated by a space. The x-th integer in the y-th line of the d lines is the elevation of the unit square cell with coordinates (x, y).
The end of the input is indicated by a line containing two zeros separated by a space.
d w
e1, 1 ... e1, w
...
ed, 1 ... ed, w
The first line contains d and w, representing the depth and the width, respectively, of the garden site described in the map. They are positive integers between 3 and 10, inclusive. Each of the following d lines contains w integers between 0 and 9, inclusive, separated by a space. The x-th integer in the y-th line of the d lines is the elevation of the unit square cell with coordinates (x, y).
The end of the input is indicated by a line containing two zeros separated by a space.
输出
For each dataset, output a single line containing the largest possible capacity of a pond that can be built in the garden site described in the dataset. If no ponds can be built, output a single line containing a zero.
样例输入
3 3
2 3 2
2 1 2
2 3 1
3 5
3 3 4 3 3
3 1 0 2 3
3 3 4 3 2
7 7
1 1 1 1 1 0 0
1 0 0 0 1 0 0
1 0 1 1 1 1 1
1 0 1 0 1 0 1
1 1 1 1 1 0 1
0 0 1 0 0 0 1
0 0 1 1 1 1 1
6 6
1 1 1 1 2 2
1 0 0 2 0 2
1 0 0 2 0 2
3 3 3 9 9 9
3 0 0 9 0 9
3 3 3 9 9 9
0 0
样例输出
0 3 1 9
#include <bits/stdc++.h> using namespace std; int Map[15][15]; int n,m; int cal(int nn,int mm,int k,int p) { int Min = 100; for(int i=k;i<k+nn;i++) { Min = min(Map[i][p],Min); Min = min(Map[i][p+mm-1],Min); } for(int i=p;i<p+mm;i++) { Min = min(Map[k][i],Min); Min = min(Map[k+nn-1][i],Min); } int anst = 0; for(int i=k+1;i<k+nn-1;i++) { for(int j=p+1;j<p+mm-1;j++) { if(Map[i][j]>=Min) return 0; anst+=(Min-Map[i][j]); } } return anst; } int main() { while(scanf("%d%d",&n,&m)) { if(n==0&&m==0) break; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) scanf("%d",&Map[i][j]);//>>Map[i][j]; int ans = 0; for(int i=3;i<=n;i++) { for(int j=3;j<=m;j++) { for(int k=1;i+k-1<=n;k++) { for(int p=1;p+j-1<=m;p++) { ans = max(ans,cal(i,j,k,p)); //cout<<cal(i,j,k,p)<<endl; } } } } printf("%d\n",ans); } }
问题 F: Folding a Ribbon
Think of repetitively folding a very long and thin ribbon. First, the ribbon is spread out from left to right, then it is creased at its center, and one half of the ribbon is laid over the other. You can either fold it from the left to the right, picking up the left end of the ribbon and laying it over the right end, or from the right to the left, doing the same in the reverse direction. To fold the already folded ribbon, the whole layers of the ribbon are treated as one thicker ribbon, again from the left to the right or the reverse.
After folding the ribbon a number of times, one of the layers of the ribbon is marked, and then the ribbon is completely unfolded restoring the original state. Many creases remain on the unfolded ribbon, and one certain part of the ribbon between two creases or a ribbon end should be found marked. Knowing which layer is marked and the position of the marked part when the ribbon is spread out, can you tell all the directions of the repeated folding, from the left or from the right?
The figure below depicts the case of the first dataset of the sample input.
After folding the ribbon a number of times, one of the layers of the ribbon is marked, and then the ribbon is completely unfolded restoring the original state. Many creases remain on the unfolded ribbon, and one certain part of the ribbon between two creases or a ribbon end should be found marked. Knowing which layer is marked and the position of the marked part when the ribbon is spread out, can you tell all the directions of the repeated folding, from the left or from the right?
The figure below depicts the case of the first dataset of the sample input.
![](http://exam.upc.edu.cn/upload/image/20180817/20180817155846_92154.png)
输入
The input consists of at most 100 datasets, each being a line containing three integers.
n i j
The three integers mean the following: The ribbon is folded n times in a certain order; then, the i-th layer of the folded ribbon, counted from the top, is marked; when the ribbon is unfolded completely restoring the original state, the marked part is the j-th part of the ribbon separated by creases, counted from the left. Both i and j are one-based, that is, the topmost layer is the layer 1 and the leftmost part is numbered 1. These integers satisfy 1 ≤ n ≤ 60, 1 ≤ i ≤ 2n, and 1 ≤ j ≤ 2n.
The end of the input is indicated by a line with three zeros.
n i j
The three integers mean the following: The ribbon is folded n times in a certain order; then, the i-th layer of the folded ribbon, counted from the top, is marked; when the ribbon is unfolded completely restoring the original state, the marked part is the j-th part of the ribbon separated by creases, counted from the left. Both i and j are one-based, that is, the topmost layer is the layer 1 and the leftmost part is numbered 1. These integers satisfy 1 ≤ n ≤ 60, 1 ≤ i ≤ 2n, and 1 ≤ j ≤ 2n.
The end of the input is indicated by a line with three zeros.
输出
For each dataset, output one of the possible folding sequences that bring about the result specified in the dataset.
The folding sequence should be given in one line consisting of n characters, each being either L or R. L means a folding from the left to the right, and R means from the right to the left. The folding operations are to be carried out in the order specified in the sequence.
The folding sequence should be given in one line consisting of n characters, each being either L or R. L means a folding from the left to the right, and R means from the right to the left. The folding operations are to be carried out in the order specified in the sequence.
样例输入
3 3 2
12 578 2214
59 471605241352156968 431565444592236940
0 0 0
样例输出
LRR
RLLLRRRLRRLL
LRRRLRRLLRRRRLLLLRLLRRRLRRLLRLLLLLLRLRLLRLRLLLRLRLLRLLRRRLL
参考:https://blog.csdn.net/winter2121/article/details/82344071
分析:很巧妙的一道题 先从最后叠起到展开
1.你可以先看i,看i在当前被子的上半部还是下半部,如果是上半部,则需要翻开,下半部,则是被压着的那部分。每次判断上下部分,并记录n次,每次更新原本i层现在是几层。
2.现在你已经知道怎么叠的了(该次是被压着 还是要盖着另一半) 然后就要看方向 如果j在需要盖着并在左半部分 则需要从右半部分盖过来 则是“R” 然后更新j 以此类推(在右半部分的j的更新需要在更新处注意)
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll pow_2[62]; void init() { pow_2[0] = 1; for(int i=1;i<=61;i++) { pow_2[i] = pow_2[i-1]<<1; } } int main() { init(); long long int n,x,y; bool flag[65]; while(cin>>n>>x>>y) { if(n==0&&x==0&&y==0) break; for(int i=n;i>0;i--) { if(x>pow_2[i-1]) //ya zhe { flag[i] = 1; x -= pow_2[i-1]; } else //xian kai { flag[i] = 0; x = pow_2[i-1]+1-x; } } for(int i=1;i<=n;i++) { if(y<=pow_2[n-i]) { if(flag[i]) //ya zhe printf("R"); else { printf("L"); y = pow_2[n-i] +1 -y; } } else { if(flag[i]) { printf("L"); y-=pow_2[n-i]; } else { printf("R"); y = pow_2[n-i+1]+1-y; } } } printf("\n"); } return 0; }