A
We often compute the average as the first step in processing statistical data. Yes, the average is a good tendency measure of data, but it is not always the best. In some cases, the average may hinder the understanding of the data.
For example, consider the national income of a country. As the term income inequality suggests, a small number of people earn a good portion of the gross national income in many countries. In such cases, the average income computes much higher than the income of the vast majority. It is not appropriate to regard the average as the income of typical people.
Let us observe the above-mentioned phenomenon in some concrete data. Incomes of n people, a1, ... , an, are given. You are asked to write a program that reports the number of people whose incomes are less than or equal to the average (a1 + ... + an) / n.
Input
The input consists of multiple datasets, each in the following format.
n
a1 a2 ... an
A dataset consists of two lines. In the first line, the number of people n is given. n is an integer satisfying 2 ≤ n ≤ 10 000. In the second line, incomes of n people are given. ai (1 ≤ i ≤ n) is the income of the i-th person. This value is an integer greater than or equal to 1 and less than or equal to 100 000.
The end of the input is indicated by a line containing a zero. The sum of n's of all the datasets does not exceed 50 000.
Output
For each dataset, output the number of people whose incomes are less than or equal to the average.
Sample Input
7
15 15 15 15 15 15 15
4
10 20 30 60
10
1 1 1 1 1 1 1 1 1 100
7
90 90 90 90 90 90 10
7
2 7 1 8 2 8 4
0
Output for the Sample Input
7
3
9
1
4
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#define MOD 10000000
using namespace std;
typedef long long LL;
long long quickpow(long long n, long long base) {
long long res = 1;
while(n) {
if(n & 1) {
res = res * base % MOD;
}
n >>= 1;
base = base * base % MOD;
}
return res;
}//¿ìËÙÃÝ
int A[10050];
int ans[50010];
int main()
{
int n;
int flag=1;
cin>>n;
int j=0;
while(n)
{
++j;
int sum=0;
for(int i=1;i<=n;i++)
{
cin>>A[i];
sum+=A[i];
}
ans[j]=0;
float ave=1.0*sum/n;
for(int i=1;i<=n;i++)
{
if(A[i]<=ave)
ans[j]++;
}
cin>>n;
}
for(int i=1;i<=j;i++)
cout<<ans[i]<<endl;
}
A题可能第一次比赛有点紧张,交了半天的C....然后测试的时候写了输出平均数,交的时候又没有改...反正各种傻逼
L
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.
Input
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.
Output
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.
Sample Input
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
Output for the Sample Input
40
10
99
NONE
20
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#define MOD 10000000
using namespace std;
typedef long long LL;
long long quickpow(long long n, long long base) {
long long res = 1;
while(n) {
if(n & 1) {
res = res * base % MOD;
}
n >>= 1;
base = base * base % MOD;
}
return res;
}//???
int A[2000];
int ans[50010];
int main()
{
int n,m;
cin>>n>>m;
int sum;
int k=0;
memset(ans,0,sizeof(ans));
while(n!=0||m!=0)
{
++k;
for(int i=1;i<=n;i++)
cin>>A[i];
sort(A+1,A+1+n);
for(int i=n;i>=2;i--)
{
for(int j=i-1;j>=1;j--)
{
sum=A[i]+A[j];
if(sum<=m)
{
ans[k]=max(ans[k],sum);
}
}
}
cin>>n>>m;
}
for(int i=1;i<=k;i++)
{
if(ans[i]!=0)
cout<<ans[i]<<endl;
else cout<<"NONE"<<endl;
}
}
前面两题比较简单就不说了。
C
Skyscraper "MinatoHarukas"
Mr. Port plans to start a new business renting one or more floors of the new skyscraper with one giga floors, MinatoHarukas. He wants to rent as many vertically adjacent floors as possible, because he wants to show advertisement on as many vertically adjacent windows as possible. The rent for one floor is proportional to the floor number, that is, the rent per month for the n-th floor is n times that of the first floor. Here, the ground floor is called the first floor in the American style, and basement floors are out of consideration for the renting. In order to help Mr. Port, you should write a program that computes the vertically adjacent floors satisfying his requirement and whose total rental cost per month is exactly equal to his budget.
For example, when his budget is 15 units, with one unit being the rent of the first floor, there are four possible rent plans, 1+2+3+4+5, 4+5+6, 7+8, and 15. For all of them, the sums are equal to 15. Of course in this example the rent of maximal number of the floors is that of 1+2+3+4+5, that is, the rent from the first floor to the fifth floor.
Input
The input consists of multiple datasets, each in the following format.
b
A dataset consists of one line, the budget of Mr. Port b as multiples of the rent of the first floor. b is a positive integer satisfying 1 < b < 109.
The end of the input is indicated by a line containing a zero. The number of datasets does not exceed 1000.
Output
For each dataset, output a single line containing two positive integers representing the plan with the maximal number of vertically adjacent floors with its rent price exactly equal to the budget of Mr. Port. The first should be the lowest floor number and the second should be the number of floors.
Sample Input
15
16
2
3
9699690
223092870
847288609
900660121
987698769
999999999
0
Output for the Sample Input
1 5
16 1
2 1
1 2
16 4389
129 20995
4112949 206
15006 30011
46887 17718
163837 5994
C题是比较需要推一下的题目,我当时想的过分麻烦了,我讨论了从1开始的,12345这种以3为中心的,4567以5、6为中心,思想基本没有问题,但是疯狂TLE。
这题利用等差公式求和。 a1*n+n*(n-1)/2=S,我们枚举首项肯定要TLE...因为数据范围10e9*1000组数据,S已知,化简公式。
2n*a1+n^2-n-2s=0,n^2+(2*a1-1)n-2s=0,n的数量较小,我们枚举n就好,又因为,根据韦达定理,两根相乘为2s,两根相加为2*a1-1,后者相加为整数,而又必定存在一个根是N为整数,所以两根都为整数,也就是说,n一定是2*n的因数(可大可小)
这样我们对于sqrt(2*n)的情况下,枚举小因数和大因数即可。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#define MOD 10000000
using namespace std;
typedef long long LL;
long long quickpow(long long n, long long base) {
long long res = 1;
while(n) {
if(n & 1) {
res = res * base % MOD;
}
n >>= 1;
base = base * base % MOD;
}
return res;
}//¿ìËÙÃÝ
int A[10050];
struct node
{
int a;
int b;
}ans[50010];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int n;
int k=0;
cin>>n;
int flag=1;
int sum;
int j;
while(n)
{
int flag=0;
for(int i=sqrt(2*n);i>=1;i--)
{
if(2*n%i==0)
{
j=(-i*i+2*n+i)/(2*i);
if(j*i+i*(i-1)/2==n)
{
cout<<j<<" "<<i<<endl;
flag=1;
break;
}
int x=n/i;
j=(-x*x+2*n+x)/(2*x);
if(j*i+i*(i-1)/2==n)
{
cout<<j<<" "<<i<<endl;
flag=1;
break;
}
}
}
if(!flag)cout<<n<<" "<<"1"<<endl;
cin>>n;
}
}
K
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.
Input
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).
Output
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.
Sample Input
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
.
Output for the Sample Input
IDENTICAL
CLOSE
DIFFERENT
CLOSE
DIFFERENT
DIFFERENT
DIFFERENT
CLOSE
DIFFERENT
碰了很多次壁才读懂了题意,题意是说,完全相同输出IDENTCAL,双引号内的代表字符串,只有有一个字符串不同,输出CLOSE,如果不只一个字符串不同或者双引号之外的内容不同,输出DIFFERENT。
也是一道模拟题,需要判断双引号的开始和结束,还需要判断是否有一个字符串提前结束(提前结束是不能发现不同的需要单独判断在双引号内的提前结束和双引号外的提前结束)
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#define MOD 10000000
using namespace std;
typedef long long LL;
long long quickpow(long long n, long long base) {
long long res = 1;
while(n) {
if(n & 1) {
res = res * base % MOD;
}
n >>= 1;
base = base * base % MOD;
}
return res;
}//¿ìËÙÃÝ
char A[100050];
char B[100050];
int main()
{
cin>>A+1;
while(A[1]!='.')
{
cin>>B+1;
int lenA=strlen(A+1);
int lenB=strlen(B+1);
int i=1,j=1;
int flag=0;
int k=0;
while(i<=lenA&&j<=lenB)
{
if(A[i]==B[j])
{
if(A[i]=='"'&&k){k=0;}
else if(A[i]=='"'&&!k){k=1;}
i++;j++;
}
else if(k==1)
{
while(A[i]!='"'&&i<=lenA)
i++;
while(B[j]!='"'&&j<=lenB)
j++;
flag++;
i++;j++;
k=0;
}
else if(k==0)
{
flag+=2;break;
}
}
if(k==0&&i>lenA&&j<=lenB)flag+=2;
if(k==0&&j>lenB&&i<=lenA)flag+=2;
if(j>lenB&&A[i]=='"')flag+=2;
else if(i>lenA&&B[j]=='"')flag+=2;
else if(i>lenA&&j<=lenB)flag++;
else if(j>lenB&&i<=lenA)flag++;
if(flag==0)cout<<"IDENTICAL"<<endl;
if(flag==1)cout<<"CLOSE"<<endl;
if(flag>1)cout<<"DIFFERENT"<<endl;
cin>>A+1;
}
}
B
Master Grus is a famous origami (paper folding) artist, who is enthusiastic about exploring the possibility of origami art. For future creation, he is now planning fundamental experiments to establish the general theory of origami.
One rectangular piece of paper is used in each of his experiments. He folds it horizontally and/or vertically several times and then punches through holes in the folded paper.
The following figure illustrates the folding process of a simple experiment, which corresponds to the third dataset of the Sample Input below. Folding the 10 × 8 rectangular piece of paper shown at top left three times results in the 6 × 6 square shape shown at bottom left. In the figure, dashed lines indicate the locations to fold the paper and round arrows indicate the directions of folding. Grid lines are shown as solid lines to tell the sizes of rectangular shapes and the exact locations of folding. Color densities represent the numbers of overlapping layers. Punching through holes at A and B in the folded paper makes nine holes in the paper, eight at A and another at B.
Your mission in this problem is to write a computer program to count the number of holes in the paper, given the information on a rectangular piece of paper and folding and punching instructions.
Input
The input consists of at most 1000 datasets, each in the following format.
n m t p
d1 c1
...
dt ct
x1 y1
...
xp yp
n and m are the width and the height, respectively, of a rectangular piece of paper. They are positive integers at most 32. t and p are the numbers of folding and punching instructions, respectively. They are positive integers at most 20. The pair of di and ci gives the i-th folding instruction as follows:
- di is either 1 or 2.
- ci is a positive integer.
- If di is 1, the left-hand side of the vertical folding line that passes at ci right to the left boundary is folded onto the right-hand side.
- If di is 2, the lower side of the horizontal folding line that passes at ci above the lower boundary is folded onto the upper side.
After performing the first i−1 folding instructions, if di is 1, the width of the shape is greater than ci. Otherwise the height is greater than ci. ( xi + 1/2, yi + 1/2) gives the coordinates of the point where the i-th punching instruction is performed. The origin (0, 0) is at the bottom left of the finally obtained shape. xi and yi are both non-negative integers and they are less than the width and the height, respectively, of the shape. You can assume that no two punching instructions punch holes at the same location.
The end of the input is indicated by a line containing four zeros.
Output
For each dataset, output p lines, the i-th of which contains the number of holes punched in the paper by the i-th punching instruction.
Sample Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output for the Sample Input
2
3
8
1
3
6
大家用的都是直接折叠...数组会越来越大,但是数据只有32不怕...如果数据再大点就只能用我这种方法了...就是每次折叠完之后重塑新的数组。就是各种模拟罢了...判断折过去盖不住,折过去盖住了两种情况。
唯一需要注意盖住了之后对于多出的部分的回溯,没办法用一个数组实现,(自己试一下就知道了因为我卡这个所以卡了六个多小时)然后用个新数组记录一下,再复制到重塑的数组中就好。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#define MOD 10000000
using namespace std;
typedef long long LL;
long long quickpow(long long n, long long base) {
long long res = 1;
while(n) {
if(n & 1) {
res = res * base % MOD;
}
n >>= 1;
base = base * base % MOD;
}
return res;
}//???
int ans[50];int B[100][100];
int A[100][100];
int main()
{
int n,m,t,p;
cin>>n>>m>>t>>p;
int d,c,x,y;
while(n!=0||m!=0||t!=0||p!=0)
{
for(int i=1;i<=m;i++)
for(int j=1;j<=n;j++)
{
A[i][j]=1;
}
for(int i=1;i<=t;i++)
{
cin>>d>>c;
if(d==1)
{
if(c<=(n/2))
{
for(int i=1;i<=m;i++)
for(int j=c+1;j<=(2*c);j++)
A[i][j]+=A[i][(2*c)+1-j];
for(int i=1;i<=m;i++)
for(int j=1;j<=(n-c);j++)
A[i][j]=A[i][j+c];
n-=c;
}
else
{
for(int i=1;i<=m;i++)
for(int j=c+1;j<=n;j++)
A[i][j]+=A[i][(2*c)+1-j];
for(int i=1;i<=m;i++)
for(int j=n-c+1;j<=c;j++)
B[i][j]=A[i][c+1-j];
for(int i=1;i<=m;i++)
for(int j=n-c+1;j<=c;j++)
A[i][j]=B[i][j];
for(int i=1;i<=m;i++)
for(int j=1;j<=n-c;j++)
A[i][j]=A[i][j+c];
n=c;
}
}
if(d==2)
{
if(c<=(m/2))
{
for(int i=c+1;i<=(2*c);i++)
for(int j=1;j<=n;j++)
A[i][j]+=A[(2*c)+1-i][j];
for(int i=1;i<=m-c;i++)
for(int j=1;j<=n;j++)
A[i][j]=A[i+c][j];
m-=c;
}
else
{
for(int i=c+1;i<=m;i++)
for(int j=1;j<=n;j++)
A[i][j]+=A[(2*c)+1-i][j];
for(int i=m-c+1;i<=c;i++)
for(int j=1;j<=n;j++)
B[i][j]=A[c+1-i][j];
for(int i=m-c+1;i<=c;i++)
for(int j=1;j<=n;j++)
A[i][j]=B[i][j];
for(int i=1;i<=m-c;i++)
for(int j=1;j<=n;j++)
A[i][j]=A[i+c][j];
m=c;
}
}
}
int j=0;
for(int i=1;i<=p;i++)
{
cin>>x>>y;
ans[++j]=A[y+1][x+1];
}
for(int i=1;i<=j;i++)
{
cout<<ans[i]<<endl;
}
cin>>n>>m>>t>>p;
}
}
补题先到这里,马上又要开始比赛了。
接下来首先补的是dfs加优化的D题和还没有看的J题。E\F\G\H\I暂且放着。
J题:宇宙无敌大水题
就是暴力暴力,数据范围太小了,暴力枚举四条边界10e4的复杂度,枚举出边界之后走一遍边界找出最小值作为判断符合与否的标准,现在10e5的复杂度,最后跑一遍边界内的元素,算出容量然后比较出最大容量,总共10e7的复杂度,完全能过。
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.
Input
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.
Output
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.
Sample Input
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
Output for the Sample Input
0 3 1 9
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
int A[20][20];
int main()
{
int n,m;
cin>>n>>m;
int maxsum=0;
int pre;
int minsum;
while(n!=0&&m!=0)
{
maxsum=0;
memset(A,0,sizeof(A));
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>A[i][j];
}
}
for(int i1=1;i1<n-1;i1++)
for(int i2=i1+2;i2<=n;i2++)
for(int j3=1;j3<m-1;j3++)
for(int j2=j3+2;j2<=m;j2++)
{
pre=0;minsum=100000000;
for(int i=i1;i==i1;i++)
{
for(int j=j3;j<=j2;j++)
{
minsum=min(minsum,A[i][j]);
}
}
for(int i=i2;i==i2;i++)
{
for(int j=j3;j<=j2;j++)
{
minsum=min(minsum,A[i][j]);
}
}
for(int j=j3;j==j3;j++)
{
for(int i=i1+1;i<=i2-1;i++)
{
minsum=min(minsum,A[i][j]);
}
}
for(int j=j2;j==j2;j++)
{
for(int i=i1+1;i<=i2-1;i++)
minsum=min(minsum,A[i][j]);
}
// cout<<i1<<" "<<i2<<" "<<j3<<" "<<j2<<endl;
// cout<<minsum<<endl;
int flag=1;
for(int i=i1+1;i<=i2-1;i++)
{
for(int j=j3+1;j<=j2-1;j++)
{
if(A[i][j]>=minsum)flag=0;
else pre+=(minsum-A[i][j]);
}
}
if(flag)
maxsum=max(maxsum,pre);
}
cout<<maxsum<<endl;
cin>>n>>m;
}
}