Educational Codeforces Round 8 总结

123 篇文章 0 订阅
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.


<span style="font-size:14px;">#include<stdio.h>
#include<string.h>
#include<algorithm>
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;
}</span>

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<stdio.h>
#include<string.h>
#include<string>
#include<iostream>
#include<algorithm>
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<strlen(s); i++)
        {
            if((s[i]-'0')%4==0)
                sum++;
            if(((s[i-1]-'0')*10+(s[i]-'0'))%4==0)
                sum+=i;
        }
        printf("%I64d\n",sum);
    }
    return 0;
}

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

水模拟

<span style="font-size:14px;">#include<stdio.h>
#include<string.h>
#include<string>
#include<iostream>
#include<algorithm>
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<strlen(s); i++)
        {
            if((s[i]-'a')<=12)
                sum+=(26-((s[i]-'a')+1));
            else
                sum+=(s[i]-'a');
            }
        if(sum<k)
        {
            printf("-1\n");
        }
        else
        {
            for(LL i=0; i<strlen(s)&&k!=0; i++)
            {
                if((s[i]-'a')>=(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;
}</span>



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值