B - B
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

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

Input
4
0101
1000
1111
0101
Output
2
Input
3
111
111
111
Output
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;
}

 



C - C
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

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

Input
1
Output
1
Input
25
Output
4

Hint

Illustration to the second sample:

解题思路:本题主要思路是累加思想,第N行的数就要从1+2+....+N,所以一个N行高的金字塔总和即是1+(1+2)+(1+2+3)+.....+(1+2+3+..+N)
代码:
 
#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;
}

 

 
F - F
Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format:%lld & %llu

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 


解题思路:
虽然x和y的范围都是10^8,但是如果a 是大于1000的话,那么a^3就会大于10^9,这样等号的右边只有一个10 * c + 3,这个最大只能达到10^9数量级,所以,不管输入的x跟y是多少,我们只要取其中的在1到1000的区间就可以了,枚举a和b,那么c就可以得到,然 后判断c的范围是不是在x到y之间,这样时间复杂度就降到了10^6.
有了上面的分析,这道题就很简单啦;
程序代码:

#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;
}