Codeforces Round #386 (Div. 2)(A+B)

来源:互联网 发布:数据库面试问答题 编辑:程序博客网 时间:2024/06/14 03:07

A. Compote
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Nikolay has a lemons, b apples and c pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1: 2: 4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can’t crumble up, break up or cut these fruits into pieces. These fruits — lemons, apples and pears — should be put in the compote as whole fruits.

Your task is to determine the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. It is possible that Nikolay can’t use any fruits, in this case print 0.

Input
The first line contains the positive integer a (1 ≤ a ≤ 1000) — the number of lemons Nikolay has.

The second line contains the positive integer b (1 ≤ b ≤ 1000) — the number of apples Nikolay has.

The third line contains the positive integer c (1 ≤ c ≤ 1000) — the number of pears Nikolay has.

Output
Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote.

Examples
input
2
5
7
output
7
input
4
7
13
output
21
input
2
3
2
output
0
Note
In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7.

In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21.

In the third example Nikolay don’t have enough pears to cook any compote, so the answer is 0.
题意:做一个东西需要A材料1份,B材料2份,C材料4份,东西价值7,问最大价值为多少。
题解:水题
代码:

#include <bits/stdc++.h>#define ll long long#define babab printf("!!!!!\n")using namespace std;int main(){    ll a,b,c;    cin>>a>>b>>c;    cout<<min(min(a,b/2),c/4)*7<<endl;}

B. Decoding
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word’s length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, info. If the word consists of single letter, then according to above definition this letter is the median letter.

Polycarp encodes each word in the following way: he writes down the median letter of the word, then deletes it and repeats the process until there are no letters left. For example, he encodes the word volga as logva.

You are given an encoding s of some word, your task is to decode it.

Input
The first line contains a positive integer n (1 ≤ n ≤ 2000) — the length of the encoded word.

The second line contains the string s of length n consisting of lowercase English letters — the encoding.

Output
Print the word that Polycarp encoded.

Examples
input
5
logva
output
volga
input
2
no
output
no
input
4
abba
output
baba
Note
In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word became va. Then he wrote down the letter v, then the letter a. Thus, the encoding looked like logva.

In the second example Polycarp encoded the word no. He wrote down the letter n, the word became o, and he wrote down the letter o. Thus, in this example, the word and its encoding are the same.

In the third example Polycarp encoded the word baba. At first, he wrote down the letter a, which was at the position 2, after that the word looked like bba. Then he wrote down the letter b, which was at the position 2, his word looked like ba. After that he wrote down the letter b, which was at the position 1, the word looked like a, and he wrote down that letter a. Thus, the encoding is abba.
题意:给出一种字符串变化规则,每次从原串中取出中间值(操作完删除),输出。现在给出新串,问原串?
题解:多写几次就明白了。。
代码:

#include <bits/stdc++.h>using namespace std;char a[60000];char ans[600000];int main(){    int n;    cin>>n;      cin>>a;        int l=20000;        int r=20001;        for(int i=0;i<n;i++)        {            if(i%2==0)            {                ans[l]=a[i];                l--;            }            else            {                ans[r]=a[i];                r++;            }        }        if(n&1)        {            for(int i=r-1;i>=l+1;i--)            {               cout<<ans[i];            }            cout<<endl;        }        else        {            for(int i=l+1;i<=r-1;i++)            {                cout<<ans[i];            }           cout<<endl;        }    }
0 0
原创粉丝点击