cf141div2

来源:互联网 发布:柴犬为什么会笑 知乎 编辑:程序博客网 时间:2024/06/15 08:32

http://codeforces.com/contest/228/problem/A

A. Is your horseshoe on the other hoof?
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Valera the Horse is going to the party with friends. He has beenfollowing the fashion trends for a while, and he knows that it isvery popular to wear all horseshoes of different color. Valera hasgot four horseshoes left from the last year, but maybe some of themhave the same color. In this case he needs to go to the store andbuy some few more horseshoes, not to lose face in front of hisstylish comrades.

Fortunately, the store sells horseshoes of all colors under thesun and Valera has enough money to buy any four of them. However,in order to save the money, he would like to spend as little moneyas possible, so you need to help Valera and determine what is theminimum number of horseshoes he needs to buy to wear fourhorseshoes of different colors to a party.

Input

The first line contains four space-separated integerss1, s2, s3, s4 (1 ≤ s1, s2, s3, s4 ≤ 109)— the colors of horseshoes Valera has.

Consider all possible colors indexed with integers.

Output

Print a single integer — the minimum number of horseshoes Valeraneeds to buy.

Sample test(s)
Input
1 7 3 3
Output
1
Input
7 7 7 7
Output
3
第一题是个大水题,当时没想到用unique()来做直接暴力做的。。哦忘了就4组数据,怎么做都行,如果数据量大的话用unique()会好很多。。。
 
#include #include#include#includeint a[10];using namespace std;int main(){    int b,c,d;    while(scanf("%d",&a[0])!=EOF)    {        scanf("%d%d%d",&a[1],&a[2],&a[3]);        sort(a,a+4);        int i;        int count=0;        for(i=0;i<</SPAN>4;i++)        {            if(a[i]==a[i+1])            {                count++;            }        }        printf("%d\n",count);    }    return 0;}
 
解法2:
#include 
#include
#include
using namespace std;
int main()
{
    int a[10];
    //int i;
    while(scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3])!=EOF)
    {
        sort(a,a+4);
        printf("%d\n",4-(unique(a,a+4)-a));
    }
    return 0;
}
 
http://codeforces.com/contest/228/problem/B
B. Two Tables
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You've got two rectangular tables with sizes na × ma and nb × mb cells. The tables consist ofzeroes and ones. We will consider the rows and columns of bothtables indexed starting from 1. Then we will define the element ofthe first table, located at the intersection of the i-th row and the j-th column, as ai, j; we will define theelement of the second table, located at the intersection of thei-th row and the j-th column, as bi, j.

We will call the pair of integers (x, y) a shift of the second table relative tothe first one. We'll call the overlap factor of the shift (x, y) value:

cf141div2

where the variables i, j take only such values, inwhich the expression ai, j·bi + x, j + ymakes sense. More formally, inequalities 1 ≤ i ≤ na, 1 ≤ j ≤ ma, 1 ≤ i + x ≤ nb, 1 ≤ j + y ≤ mbmust hold. If there are no values of variables i, j, that satisfy the giveninequalities, the value of the sum is considered equal to 0.

Your task is to find the shift with the maximum overlap factoramong all possible shifts.

Input

The first line contains two space-separated integersna, ma (1 ≤ na, ma ≤ 50) — the number of rows andcolumns in the first table. Then nalines contain ma characters each — the elementsof the first table. Each character is either a "0", or a "1".

The next line contains two space-separated integers nb, mb (1 ≤ nb, mb ≤ 50) — the number of rows andcolumns in the second table. Then follow the elements of the secondtable in the format, similar to the first table.

It is guaranteed that the first table has at least one number"1". It is guaranteed thatthe second table has at least one number "1".

Output

Print two space-separated integers x, y (|x|, |y| ≤ 109) — a shift with maximum overlapfactor. If there are multiple solutions, print any of them.

Sample test(s)
Input
3 2
01
10
00
2 3
001
111
Output
0 1
Input
3 3
000
010
000
1 1
1
Output
-1 -1
表示题目没读懂。。下次题意没读懂的情况下可以直接按照题目要求直接做。。。
#include 
#include
#include
using namespace std;
char a[100][100],b[100][100];
int main()
{
    int na,nb,ma,mb;
    scanf("%d%d",&na,&ma);
        int i,j;
        for(i=1;i<=na;i++)
        {
            getchar();
            for(j=1;j<=ma;j++)
            {
                scanf("%c",&a[i][j]);
            }
        }
        scanf("%d%d",&nb,&mb);
        for(i=1;i<=nb;i++)
        {
            getchar();
            for(j=1;j<=mb;j++)
            {
                scanf("%c",&b[i][j]);
            }
        }
        int x,y,tx,ty;
        int sum=0;
        int max=-1000;
        for(x=-50;x<=50;x++)
        {
            for(y=-50;y<=50;y++)
            {
                sum=0;
                for(i=1;i<=na;i++)
                {
                    for(j=1;j<=ma;j++)
                    {
                        if(i+x<=nb&&i+x>=1&&j+y<=mb&&j+y>=1)
                        {
                           // if(i+x<=nb&&i+x>0&&j+y>0&&j+y<=mb)
                            sum+=(a[i][j]-48)*(b[i+x][j+y]-48);
                        }
                    }
                }
                if(sum>max)
                {
                    max=sum;
                    tx=x;
                    ty=y;
                }
            }
        }
        printf("%d %d\n",tx,ty);
    return 0;
}