codeforces-746【思维】【模拟】

题目链接:点击打开链接

A. Compote
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard 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 ratio1: 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.


#include<cstdio>
#include<algorithm>
using namespace std;
int a,b,c;
int main()
{
	while(~scanf("%d%d%d",&a,&b,&c))
	{
		int x1=a;
		int x2=b/2;
		int x3=c/4;
		printf("%d\n",min(x1,min(x2,x3))*7);
	}
	return 0;
}

题目链接: 点击打开链接

B. Decoding
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard 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: contestinfo. 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 gwhich was at the second position, the word became va. Then he wrote down the letter v, then the letter a. Thus, the encoding looked likelogva.

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 letterb, which was at the position 1, the word looked like a, and he wrote down that letter a. Thus, the encoding is abba.


大意:给出一种编码方式,告诉你某单词的编码结果,求原单词

思路:观察可以看出,按编码结果字母的顺序,中间的位置开始:左边一个,右边一个,排完之后就是原单词。

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<stack>
using namespace std;
int n;
char str[2010];
int main()
{
	while(~scanf("%d",&n))
	{
		scanf("%s",str);
		stack<char> l;
		char r[1010];
		bool flag=0;
		char ch;
		if(n&1)
		{
			flag=1;
			ch=str[0];
		}
		int temp=0,num=0;
		for(int i=0;i<n;i++)
		{
			if(i==0&&flag)
				continue;
			temp++;
			if(temp&1)
				l.push(str[i]);
			else
				r[num++]=str[i];
		}
		while(!l.empty())
		{
			printf("%c",l.top());
			l.pop();
		}
		if(flag)
			putchar(ch);
		for(int i=0;i<num;i++)
			putchar(r[i]);
		puts("");
	}
	return 0;
}

题目链接: 点击打开链接

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

The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s.

Igor is at the point x1. He should reach the point x2. Igor passes 1 meter per t2 seconds.

Your task is to determine the minimum time Igor needs to get from the point x1 to the point x2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point x1.

Igor can enter the tram unlimited number of times at any moment when his and the tram's positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per t2 seconds). He can also stand at some point for some time.

Input

The first line contains three integers sx1 and x2 (2 ≤ s ≤ 10000 ≤ x1, x2 ≤ sx1 ≠ x2) — the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to.

The second line contains two integers t1 and t2 (1 ≤ t1, t2 ≤ 1000) — the time in seconds in which the tram passes 1 meter and the time in seconds in which Igor passes 1 meter.

The third line contains two integers p and d (1 ≤ p ≤ s - 1d is either 1 or ) — the position of the tram in the moment Igor came to the point x1 and the direction of the tram at this moment. If , the tram goes in the direction from the point s to the point 0. If d = 1, the tram goes in the direction from the point 0 to the point s.

Output

Print the minimum time in seconds which Igor needs to get from the point x1 to the point x2.

Examples
input
4 2 4
3 4
1 1
output
8
input
5 4 0
1 2
3 1
output
7
Note

In the first example it is profitable for Igor to go by foot and not to wait the tram. Thus, he has to pass 2 meters and it takes 8 seconds in total, because he passes 1 meter per 4 seconds.

In the second example Igor can, for example, go towards the point x2 and get to the point 1 in 6 seconds (because he has to pass 3meters, but he passes 1 meters per 2 seconds). At that moment the tram will be at the point 1, so Igor can enter the tram and pass 1meter in 1 second. Thus, Igor will reach the point x2 in 7 seconds in total.


大意:给出人和电车的起始位置,以及速度,人可以在合适的位置上乘坐电车,求从出发点到终点的最小时间

思路:

1)人在某一时刻可以坐顺风车,那么求人和电车到达 x2 点的时间的最小值即可;

2)人全程都坐不上顺风车,那么只能是人到达 x2 的时间

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int s,x1,x2,t1,t2,p,d;
int main()
{
	while(~scanf("%d%d%d%d%d%d%d",&s,&x1,&x2,&t1,&t2,&p,&d))
	{
		int ans1=0;
		int ans2=abs(x1-x2)*t2;
		bool flag=0;
		while(1)
		{
			if(p==x1)
				flag=1;
			if(p==x2&&flag) // 保证电车是从 x1 开向 x2 
				break;
			if(p==0&&d==-1)
				d=1;
			if(p==s&&d==1)
				d=-1;
			if(d==1)
				p++;
			else
				p--;
			ans1+=t1;
		}
		printf("%d\n",min(ans1,ans2));
	}
	return 0;
}

题目链接: 点击打开链接

D. Green and Black Tea
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Innokentiy likes tea very much and today he wants to drink exactly n cups of tea. He would be happy to drink more but he had exactly ntea bags, a of them are green and b are black.

Innokentiy doesn't like to drink the same tea (green or black) more than k times in a row. Your task is to determine the order of brewing tea bags so that Innokentiy will be able to drink n cups of tea, without drinking the same tea more than k times in a row, or to inform that it is impossible. Each tea bag has to be used exactly once.

Input

The first line contains four integers nka and b (1 ≤ k ≤ n ≤ 1050 ≤ a, b ≤ n) — the number of cups of tea Innokentiy wants to drink, the maximum number of cups of same tea he can drink in a row, the number of tea bags of green and black tea. It is guaranteed thata + b = n.

Output

If it is impossible to drink n cups of tea, print "NO" (without quotes).

Otherwise, print the string of the length n, which consists of characters 'G' and 'B'. If some character equals 'G', then the corresponding cup of tea should be green. If some character equals 'B', then the corresponding cup of tea should be black.

If there are multiple answers, print any of them.

Examples
input
5 1 3 2
output
GBGBG
input
7 2 2 5
output
BBGBGBB
input
4 3 4 0
output
NO

大意:一个人有两种茶,但是他喝一种茶最多连续 k 次,输出一种合法的喝茶方案

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,k,a,b;
char A='G',B='B';
int pos[100010]; // 表示第 i 个位置之后喝另一种茶的次数 
int main()
{
	while(~scanf("%d%d%d%d",&n,&k,&a,&b))
	{
		if(a<b)
		{
			swap(a,b);
			swap(A,B);
		}
		int x=a/k;
		if(a%k==0)
			x--;
		if(x>b) // 最少要换 x 次茶喝 
		{
			puts("NO");
			continue;
		}
		memset(pos,0,sizeof(pos)); 
		for(int i=k;i<a;i+=k) // 保证要换 x 次茶喝 
		{
			b--;
			pos[i]++;
		}
		for(int i=1;i<=a;i++)
		{
			while(b&&pos[i]<k)
			{
				b--;
				pos[i]++;
			}
		}
		while(b--) // b 不为 0,就在前面输出 
			putchar(B);
		for(int i=1;i<=a;i++)
		{
			putchar(A);
			for(int j=1;j<=pos[i];j++)
				putchar(B);
		}
		puts("");
	}
	return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值