Description
Ohana Matsumae is trying to clean a room, which is divided up into an n by n grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very strange: if she sweeps over a clean square, it will become dirty, and if she sweeps over a dirty square, it will become clean. She wants to sweep some columns of the room to maximize the number of rows that are completely clean. It is not allowed to sweep over the part of the column, Ohana can only sweep the whole column.
Return the maximum number of rows that she can make completely clean.
Input
The first line of input will be a single integer n (1 ≤ n ≤ 100).
The next n lines will describe the state of the room. The i-th line will contain a binary string with n characters denoting the state of the i-th row of the room. The j-th character on this line is '1' if the j-th square in the i-th row is clean, and '0' if it is dirty.
Output
The output should be a single line containing an integer equal to a maximum possible number of rows that are completely clean.
Sample Input
4
0101
1000
1111
0101
2
3
111
111
111
3
Hint
In the first sample, Ohana can sweep the 1st and 3rd columns. This will make the 1st and 4th row be completely clean.
In the second sample, everything is already clean, so Ohana doesn't need to do anything.
解题思路:本题主要思路在于计算有多少行相等,并输出相等最多行数
代码
#include <iostream> #include <string.h> #include <cstdio> using namespace std; string a[100]; int b[100]; int main() { int n,i=0,m=0; memset(b,0,sizeof(b)); cin>>n;int j=n; while(n--) { cin>>a[i]; for(int j=i;j>=0;j--) if(a[j]==a[i]) b[i]++; if(b[i]>m) m=b[i]; i++; } cout<<m<<endl; return 0; }
Description
Vanya got n cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1 + 2 = 3 cubes, the third level must have 1 + 2 + 3 = 6 cubes, and so on. Thus, the i-th level of the pyramid must have 1 + 2 + ... + (i - 1) + i cubes.
Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes.
Input
The first line contains integer n (1 ≤ n ≤ 104) — the number of cubes given to Vanya.
Output
Print the maximum possible height of the pyramid in the single line.
Sample Input
1
1
25
4
Hint
Illustration to the second sample:
#include <iostream> using namespace std; int main() { int n,t; cin>>n; int i,sum=0,j=1; while(sum<=n) { t=0; for(i=1;i<=j;i++) t+=i; sum+=t;j++; } cout<<j-2<<endl; return 0; }
Description
费马大定理:当n>2时,不定方程an+bn=cn没有正整数解。比如a3+b3=c3没有正整数解。为了活跃气氛,我们不妨来个搞笑版:把方程改成a3+b3=c3,这样就有解了,比如a=4, b=9, c=79时43+93=793。
输入两个整数x, y, 求满足x<=a,b,c<=y的整数解的个数。
Input
输入最多包含10组数据。每组数据包含两个整数x, y(1<=x,y<=108)。
Output
对于每组数据,输出解的个数。
Sample Input
1 10 1 20 123 456789
Sample Output
Case 1: 0 Case 2: 2 Case 3: 16
解题思路:
有了上面的分析,这道题就很简单啦;
程序代码:
#include <iostream> #include <cstdio> using namespace std; int a,b,c,d,x,y,i=0; int main() { while(cin>>x>>y) { int m=0; for(a=x;a<=y&&a<=1000;a++) for(b=x;b<=y&&b<=1000;b++) { c=a*a*a+b*b*b; if(c%10==3) { d=(c-3)/10; if(d>=x&&d<=y) m++; } } cout<<"Case "<<++i<<": "<<m<<endl; } return 0; }