Educational Codeforces Round 8 总结

A. Tennis Tournament
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.

The tournament takes place in the following way (below, m is the number of the participants of the current round):

  • let k be the maximal power of the number 2 such that k ≤ m,
  • k participants compete in the current round and a half of them passes to the next round, the other m - k participants pass to the next round directly,
  • when only one participant remains, the tournament finishes.

Each match requires b bottles of water for each participant and one bottle for the judge. Besides p towels are given to each participant for the whole tournament.

Find the number of bottles and towels needed for the tournament.

Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).

Input

The only line contains three integers n, b, p (1 ≤ n, b, p ≤ 500) — the number of participants and the parameters described in the problem statement.

Output

Print two integers x and y — the number of bottles and towels need for the tournament.

Examples
input
5 2 3
output
20 15
input
8 2 4
output
35 32
Note

In the first example will be three rounds:

  1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge),
  2. in the second round will be only one match, so we need another 5 bottles of water,
  3. in the third round will also be only one match, so we need another 5 bottles of water.

So in total we need 20 bottles of water.

In the second example no participant will move on to some round directly.


#include
#include
#include
using namespace std;
#define LL __int64
int main()
{
    LL n,b,p;
    while(scanf("%I64d%I64d%I64d",&n,&b,&p)!=EOF)
    {
        LL x=0,y=0;
        y=n*p;
        while(n>0)
        {
            x+=((n/2)*(2*b+1));
            n=n-n/2;
            if(n==1)
                break;
        }
        printf("%I64d %I64d\n",x,y);
    }
    return 0;
}

B. New Skateboard
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4.

You are given a string s consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero.

A substring of a string is a nonempty sequence of consecutive characters.

For example if string s is 124 then we have four substrings that are divisible by 412424 and 124. For the string 04 the answer is three: 0404.

As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to usegets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead ofScanner/System.out in Java.

Input

The only line contains string s (1 ≤ |s| ≤ 3·105). The string s contains only digits from 0 to 9.

Output

Print integer a — the number of substrings of the string s that are divisible by 4.

Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.

Examples
input
124
output
4
input
04
output
3
input
5810438174
output
9

大致题意:

给出一串数,从中找出连续的字串,求能够整除4的字串的个数

方法:

从后往前遍历

如果一个数的后两位能被4整除,则这个数就是4的倍数

#include
#include
#include
#include
#include
using namespace std;
#define LL __int64
const LL maxm=1e6+10;
char s[maxm];
int main()
{
    while(scanf("%s",s)!=EOF)
    {
        LL sum=0;
        if((s[0]-'0')%4==0)
        {
            sum++;
        }
        for(LL i=1; i
C. Bear and String Distance
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Limak is a little polar bear. He likes nice strings — strings of length n, consisting of lowercase English letters only.

The distance between two letters is defined as the difference between their positions in the alphabet. For example, , and .

Also, the distance between two nice strings is defined as the sum of distances of corresponding letters. For example, , and .

Limak gives you a nice string s and an integer k. He challenges you to find any nice string s' that . Find any s' satisfying the given conditions, or print "-1" if it's impossible to do so.

As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to usegets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead ofScanner/System.out in Java.

Input

The first line contains two integers n and k (1 ≤ n ≤ 1050 ≤ k ≤ 106).

The second line contains a string s of length n, consisting of lowercase English letters.

Output

If there is no string satisfying the given conditions then print "-1" (without the quotes).

Otherwise, print any nice string s' that .

Examples
input
4 26
bear
output
roar
input
2 7
af
output
db
input
3 1000
hey
output
-1

水模拟

#include
#include
#include
#include
#include
using namespace std;
#define LL __int64
const LL maxm=1e6+10;
char s[maxm];
int main()
{
    LL n,k;
    while(scanf("%I64d%I64d",&n,&k)!=EOF)
    {
        scanf("%s",s);
        LL sum=0;
        for(int i=0; i=(LL)12)
                {
                    if((s[i]-'a')<=k)
                    {
                        k=k-(s[i]-'a');
                        s[i]='a';
                    }
                    else
                    {
                        s[i]=(s[i]-k);
                        k=0;
                    }
                }
                else
                {
                    if(('z'-s[i])<=k)
                    {
                        k-=('z'-s[i]);
                        s[i]='z';
                    }
                    else
                    {
                        s[i]=(s[i]+k);
                        k=(LL)0;
                    }
                }
            }
            printf("%s\n",s);
        }
    }
    return 0;
}



你可能感兴趣的:(ACM,CoderForce)