2016 qut第一次训练赛简单题

来源:互联网 发布:海阔淘宝客助手 编辑:程序博客网 时间:2024/06/14 17:03

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:

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),
in the second round will be only one match, so we need another 5 bottles of water,
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 <iostream>#include <cstdio>#include <cstring>using namespace std;int n,p,b;int num;int main(){    scanf("%d %d %d",&n,&b,&p);    num = 0;    int k = n;    while(n!=1)    {        num += n/2;        n = n/2 + n%2;    }    printf("%d %d\n",num*2*b+num,p*k);    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 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04.

As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/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

解题思路:能被四整除的数个位为0,4,8,十位必须是偶数。个位为2,6,十位是奇数。

#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int maxn = 300010;char str[maxn];int main(){    scanf("%s",str);    __int64 len = strlen(str);    __int64 i= len-1;    __int64 num = 0;    for(;i>=0;i--)    {        int k = str[i]-'0';        int b = str[i-1]-'0';        if(k%4 == 0){            num++;        }        if((k==0 || k==4 || k==8)&& b%2==0)        {            num += i;        }        if((k==2||k==6)&& b%2==1)            num+=i;    }    printf("%I64d\n",num);    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 use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
Input

The first line contains two integers n and k (1 ≤ n ≤ 105, 0 ≤ 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 <bits/stdc++.h>using namespace std;const int maxn = 100010;char num[maxn];int n,k;int main(){    scanf("%d %d",&n,&k);    getchar();    scanf("%s",num);    for(int i=0;i<n;i++)    {        if(k == 0)            break;        int a = num[i]-'a';        int b = 'z' - num[i];        if(a > b)        {            if(k >= a)            {                k -= a;                num[i] = 'a';            }            else            {                //k = 0;                num[i] = num[i]-k;                k = 0;            }        }        else        {            if(k >= b)            {                k -= b;                num[i] = 'z';            }            else            {                //k = 0;                num[i] = num[i]+k;                k = 0;            }        }    }    if(k)        printf("-1\n");    else        puts(num);    return 0;}


                                                          D - Harmonic Number
Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Submit Status Practice LightOJ 1234

Description

In mathematics, the nth harmonic number is the sum of the reciprocals of the first n natural numbers:

In this problem, you are given n, you have to find Hn.

Input

Input starts with an integer T (≤ 10000), denoting the number of test cases.

Each case starts with a line containing an integer n (1 ≤ n ≤ 108).

Output

For each case, print the case number and the nth harmonic number. Errors less than 10-8 will be ignored.

Sample Input

12

1

2

3

4

5

6

7

8

9

90000000

99999999

100000000

Sample Output

Case 1: 1

Case 2: 1.5

Case 3: 1.8333333333

Case 4: 2.0833333333

Case 5: 2.2833333333

Case 6: 2.450

Case 7: 2.5928571429

Case 8: 2.7178571429

Case 9: 2.8289682540

Case 10: 18.8925358988

Case 11: 18.9978964039

Case 12: 18.9978964139

#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int maxn = 100001;double num[maxn];int t,n;int main(){    num[0] = 0.0;    double sum = 0.0;    int cnt = 1;    for(int i=1;i<=maxn*1000;i++){        //num[i] = num[i-1]+1.0/i;        sum += 1.0/i;        if(i%1000==0)            num[cnt++] = sum;    }    scanf("%d",&t);    int kase = 1;    while(t--)    {        scanf("%d",&n);        double ans = num[n/1000];        int i = n/1000*1000;        i++;        for(;i<=n;i++)            ans += 1.0/i;        printf("Case %d: %.8lf\n",kase++,ans);    }    return 0;}


1 0
原创粉丝点击