Codeforces Round #218,#217 (Div. 2) A.B.C

这两天不知道怎么了啊....CF一直跌啊.....老错在一些小的问题上啊.....写一下算是一个教训....

#217 A

这道题目之前在CF上见到过类似的了,一开始思路是对的,但是无奈,考虑的太少了啊,把象的走法弄少了啊,结果就悲剧的锁上了代码,还改不了了啊....

通过坐标进行判断就行了啊,尽然有同学谢了搜索,真是膜拜啊.....

A. Rook, Bishop and King
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8 × 8 table. A field is represented by a pair of integers (r, c) — the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules:

  • A rook moves any number of fields horizontally or vertically.
  • A bishop moves any number of fields diagonally.
  • A king moves one field in any direction — horizontally, vertically or diagonally.

The pieces move like that

Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field(r1, c1) to field (r2, c2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem.

Input

The input contains four integers r1, c1, r2, c2 (1 ≤ r1, c1, r2, c2 ≤ 8) — the coordinates of the starting and the final field. The starting field doesn't coincide with the final one.

You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8.

Output

Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (r1, c1) to field (r2, c2). If a piece cannot make such a move, print a 0 instead of the corresponding number.

Sample test(s)
input
4 3 1 6
output
2 1 3
input
5 5 5 6
output
1 0 1
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#define M 10010
#define INF 1 << 30;


using namespace std;

int main()
{
    int x1, y1, x2, y2;
    int x, y;
    int s1, s2, s3;
    cin >>x1>>y1>>x2>>y2;
    x = abs(x1-x2);
    y = abs(y1-y2);
    if(x1 == x2 || y1 == y2)
        s1 = 1;
    else
        s1 = 2;
    s3 = max(x, y);
    if((x1+y1)%2 != (x2+y2)%2)
        s2 = 0;
    else if(x == y)
        s2 = 1;
    else
        s2 = 2;
    cout <<s1<<' '<<s2<<' '<<s3<<endl;
    return 0;
}

B题,读懂题意就很简单了啊,就是暴力求解就行了啊.....

但是老手残啊....

B. Berland Bingo
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Lately, a national version of a bingo game has become very popular in Berland. There are n players playing the game, each player has a card with numbers. The numbers on each card are distinct, but distinct cards can have equal numbers. The card of the i-th player contains mi numbers.

During the game the host takes numbered balls one by one from a bag. He reads the number aloud in a high and clear voice and then puts the ball away. All participants cross out the number if it occurs on their cards. The person who crosses out all numbers from his card first, wins. If multiple people cross out all numbers from their cards at the same time, there are no winners in the game. At the beginning of the game the bag contains 100 balls numbered 1 through 100, the numbers of all balls are distinct.

You are given the cards for each player. Write a program that determines whether a player can win the game at the most favorable for him scenario or not.

Input

The first line of the input contains integer n (1 ≤ n ≤ 100) — the number of the players. Then follow n lines, each line describes a player's card. The line that describes a card starts from integer mi (1 ≤ mi ≤ 100) that shows how many numbers the i-th player's card has. Then follows a sequence of integers ai, 1, ai, 2, ..., ai, mi (1 ≤ ai, k ≤ 100) — the numbers on the i-th player's card. The numbers in the lines are separated by single spaces.

It is guaranteed that all the numbers on each card are distinct.

Output

Print n lines, the i-th line must contain word "YES" (without the quotes), if the i-th player can win, and "NO" (without the quotes) otherwise.

Sample test(s)
input
3
1 1
3 2 4 1
2 10 11
output
YES
NO
YES
input
2
1 1
1 1
output
NO
NO
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#define M 10010
#define INF 1 << 30;


using namespace std;

int f[1010][1010];
int main()
{
    int n, i, j, m[M], k, t;
    int dp[1010];
    memset(dp , 0 , sizeof(dp));
    cin >>n;
    for(i = 0; i < n; i++)
    {
        cin >>m[i];
        for(j = 0; j < m[i]; j++)
            cin >>f[i][j];
        sort(f[i], f[i]+m[i]);
    }
    for(i = 0; i < n-1; i++)
    {
        for(j = i+1; j < n; j++)
        {
            if(m[i] >= m[j])
            {
                t = 0;
                for(k = 0; k < m[i]; k++)
                {
                    if(f[i][k] == f[j][t])
                        t++;
                }
                if(t >= m[j])
                    dp[i] = 1;
                if(m[j] == m[i] && t >= m[j])
                    dp[j] = 1;
            }
            else
            {
                t = 0;
                for(k = 0; k < m[j]; k++)
                    if(f[i][t] == f[j][k])
                        t++;
                if(t >= m[i])
                    dp[j] = 1;
            }
        }
    }
    for(i = 0; i < n; i++)
    {
        if(!dp[i])
            cout <<"YES"<<endl;
        else
            cout <<"NO"<<endl;
    }
    return 0;
}

#218 A

依旧是水题:

找到每一数列最多有多少个一样的,把不一样的改一下就行了啊......

A. K-Periodic Array
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2.

Array a is k-period if its length is divisible by k and there is such array b of length k, that a is represented by array b written exactly times consecutively. In other words, array a is k-periodic, if it has period of length k.

For example, any array is n-periodic, where n is the array length. Array [2, 1, 2, 1, 2, 1] is at the same time 2-periodic and 6-periodic and array [1, 2, 1, 1, 2, 1, 1, 2, 1] is at the same time 3-periodic and 9-periodic.

For the given array a, consisting only of numbers one and two, find the minimum number of elements to change to make the array k-periodic. If the array already is k-periodic, then the required value equals 0.

Input

The first line of the input contains a pair of integers nk (1 ≤ k ≤ n ≤ 100), where n is the length of the array and the value n is divisible by k. The second line contains the sequence of elements of the given array a1, a2, ..., an (1 ≤ ai ≤ 2), ai is the i-th element of the array.

Output

Print the minimum number of array elements we need to change to make the array k-periodic. If the array already is k-periodic, then print0.

Sample test(s)
input
6 2
2 1 2 2 2 1
output
1
input
8 4
1 1 2 1 1 1 2 1
output
0
input
9 3
2 1 1 1 2 1 1 1 2
output
3
Note

In the first sample it is enough to change the fourth element from 2 to 1, then the array changes to [2, 1, 2, 1, 2, 1].

In the second sample, the given array already is 4-periodic.

In the third sample it is enough to replace each occurrence of number two by number one. In this case the array will look as [1, 1, 1, 1, 1, 1, 1, 1, 1] — this array is simultaneously 1-, 3- and 9-periodic.

#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#define M 10010
#define INF 1 << 30;


using namespace std;

int f[1010][1010];

int main()
{
    int n, k;
    int i, j;
    int sum = 0;
    cin >>n>>k;
    for(i = 1; i <= n/k; i++)
        for(j = 1; j <= k; j++)
            cin >>f[i][j];
    int sum1, sum2;
    for(j = 1; j <= k; j++)
    {
        sum1 = sum2 = 0;
        for(i = 1; i <= n/k; i++)
        {
            if(f[i][j] == 1)
                sum1 ++;

            else
                sum2 ++;
        }
        int kk = max(sum1, sum2);
        sum += n/k - kk;
    }
    cout <<sum<<endl;
    return 0;
}

B题,也很水啊,求出他们之间的最大公约数,然后看看a,b除以gcd的数,是不是2,3,5的倍数,是的话就算出来次数,不是输出-1。

B. Fox Dividing Cheese
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Two little greedy bears have found two pieces of cheese in the forest of weight a and b grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it fox, how are you going to do that?", the curious bears asked. "It's easy", said the fox. "If the mass of a certain piece is divisible by two, then I can eat exactly a half of the piece. If the mass of a certain piece is divisible by three, then I can eat exactly two-thirds, and if the mass is divisible by five, then I can eat four-fifths. I'll eat a little here and there and make the pieces equal".

The little bears realize that the fox's proposal contains a catch. But at the same time they realize that they can not make the two pieces equal themselves. So they agreed to her proposal, but on one condition: the fox should make the pieces equal as quickly as possible. Find the minimum number of operations the fox needs to make pieces equal.

Input

The first line contains two space-separated integers a and b (1 ≤ a, b ≤ 109).

Output

If the fox is lying to the little bears and it is impossible to make the pieces equal, print -1. Otherwise, print the required minimum number of operations. If the pieces of the cheese are initially equal, the required number is 0.

Sample test(s)
input
15 20
output
3
input
14 8
output
-1
input
6 6
output
0

#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#define M 10010
#define LL __int64
#define INF 1 << 30;


using namespace std;
int gcd(int n,int m)
{
    if(n>m)swap(n,m);
    return m%n==0?n:gcd(m%n,n);
}

int main()
{
    LL a, b;
    cin >>a>>b;
    if(a > b)
        swap(a,b);
    if(a == b)
    {
        cout <<'0'<<endl;
        return 0;
    }
    LL t = gcd(a,b);
    LL aa = a/t;
    LL bb = b/t;
    if(aa==1)aa=aa;
    else if(((aa%2!=0 && aa%3!=0 && aa%5!= 0) || (bb%2!= 0 && bb%3!= 0 && bb%5!=0)))
    {
        cout<<"-1"<<endl;
        return 0;
    }
    LL cnt = 0;
    while(aa != 1)
    {
        if(aa%5 == 0)
        {
            aa /= 5;
            cnt ++;
        }
        else if(aa%3 == 0)
        {
            aa /= 3;
            cnt ++;
        }
        else if(aa%2 == 0)
        {
            aa/=2;
            cnt ++;
        }
        else break;
    }
    while(bb != 1)
    {
        if(bb%5 == 0)
        {
            bb /= 5;
            cnt ++;
        }
        else if(bb%3 == 0)
        {
            bb /= 3;
            cnt ++;
        }
        else if(bb%2 == 0)
        {
            bb/=2;
            cnt ++;
        }
        else break;
    }
    if(aa!=1||bb!=1)
    {
        cout<<-1<<endl;
        return 0;
    }
    cout <<cnt<<endl;
    return 0;
}

C题,其实也挺简单的就是得想明白过程,注意要充分用到所有给的材料,然后贪心就可以了啊。。。。

C. Hamburgers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (bread), 'S' (sausage) и 'C' (cheese). The ingredients in the recipe go from bottom to top, for example, recipe "ВSCBS" represents the hamburger where the ingredients go from bottom to top as bread, sausage, cheese, bread and sausage again.

Polycarpus has nb pieces of bread, ns pieces of sausage and nc pieces of cheese in the kitchen. Besides, the shop nearby has all three ingredients, the prices are pb rubles for a piece of bread, ps for a piece of sausage and pc for a piece of cheese.

Polycarpus has r rubles and he is ready to shop on them. What maximum number of hamburgers can he cook? You can assume that Polycarpus cannot break or slice any of the pieces of bread, sausage or cheese. Besides, the shop has an unlimited number of pieces of each ingredient.

Input

The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C).

The second line contains three integers nbnsnc (1 ≤ nb, ns, nc ≤ 100) — the number of the pieces of bread, sausage and cheese on Polycarpus' kitchen. The third line contains three integers pbpspc (1 ≤ pb, ps, pc ≤ 100) — the price of one piece of bread, sausage and cheese in the shop. Finally, the fourth line contains integer r (1 ≤ r ≤ 1012) — the number of rubles Polycarpus has.

Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cincout streams or the %I64dspecifier.

Output

Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0.

Sample test(s)
input
BBBSSC
6 4 1
1 2 3
4
output
2
input
BBC
1 10 1
1 10 1
21
output
7
input
BSC
1 1 1
1 1 3
1000000000000
output
200000000001

#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#define M 10010
#define LL long long
#define INF 1 << 30;


using namespace std;


int main()
{
    char str[1010];
    int i;
    LL need[10], p[10], h[10], vis[10];
    LL f[10];
    LL r, sum = 0;
    LL cnt = 0;
    memset(need , 0 , sizeof(need));
    memset(vis , 0 , sizeof(vis));
    cin >>str;
    for(i = 1; i <= 3; i++)
        cin >>h[i];
    for(i = 1; i <= 3; i++)
        cin >>p[i];
    cin >>r;
    int k = strlen(str);
    for(i = 0; i < k; i++)
    {
        if(str[i] == 'B')
            need[1] ++;
        if(str[i] == 'S')
            need[2] ++;
        if(str[i] == 'C')
            need[3] ++;
    }
    for(i = 1; i <= 3; i++)
        cnt += need[i]*p[i];
    for(i = 1; i <= 3; i++)
    {
        if(!need[i])
            vis[i] = 1;
    }
    LL _max = -1;
    //cout <<need[1]<<' '<<need[2]<<' '<<need[3]<<endl;
    for(i = 1; i <= 3; i++)
    {
        if(!vis[i])
        {
            f[i] = h[i]/need[i];
            if(f[i] > _max)
                _max = f[i];
        }
    }
    //cout <<_max<<endl;
    for(i = 1; i <= _max+1; i++)
    {
        for(int j = 1; j <= 3; j++)
        {
            if(!vis[j])
            {
                if(h[j] >= need[j])
                {
                    h[j] -= need[j];
                }
                else
                {
                    LL pp = need[j] - h[j];
                    h[j] = 0;
                    if(r >= pp*p[j])
                        r -= pp*p[j];
                    else
                    {
                        cout <<i-1<<endl;
                        return 0;
                    }
                }
            }
        }
    }
    sum = _max+1;
    LL t = r/cnt;
    sum += t;
    cout <<sum<<endl;
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值