Educational Codeforces Round 39 (Rated for Div. 2)

原创 2018年04月15日 19:38:24

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

You are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequences.

Let B be the sum of elements belonging to b, and C be the sum of elements belonging to c (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of B - C?

Input

The first line contains one integer n (1 ≤ n ≤ 100) — the number of elements in a.

The second line contains n integers a1, a2, ..., an ( - 100 ≤ ai ≤ 100) — the elements of sequence a.

Output

Print the maximum possible value of B - C, where B is the sum of elements of sequence b, and C is the sum of elements of sequence c.

Examples
Input
Copy
3
1 -2 0
Output
Copy
3
Input
Copy
6
16 23 16 15 42 8
Output
Copy
120
Note

In the first example we may choose b = {1, 0}, c = { - 2}. Then B = 1, C =  - 2, B - C = 3.

In the second example we choose b = {16, 23, 16, 15, 42, 8}, c = {} (an empty sequence). Then B = 120, C = 0, B - C = 120.

题意:输入n个数,输出最大和和最小和只差。

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn = 110;
int vis[maxn];

int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		for(int i = 1; i <= n; i ++)
			scanf("%d",&vis[i]);
		sort(vis+1,vis+1+n);
		int sum1 = 0;
		int sum2 = 0;
		for(int i = 1; i <= n;i ++)
		{
			if(vis[i] <= 0)
				sum1 += vis[i];
			else
				sum2 += vis[i];
		}
		printf("%d\n",sum2-sum1);
	}
	return 0;
}

B. Weird Subtraction Process
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have two variables a and b. Consider the following sequence of actions performed with these variables:

  1. If a = 0 or b = 0, end the process. Otherwise, go to step 2;
  2. If a ≥ 2·b, then set the value of a to a - 2·b, and repeat step 1. Otherwise, go to step 3;
  3. If b ≥ 2·a, then set the value of b to b - 2·a, and repeat step 1. Otherwise, end the process.

Initially the values of a and b are positive integers, and so the process will be finite.

You have to determine the values of a and b after the process ends.

Input

The only line of the input contains two integers n and m (1 ≤ n, m ≤ 1018). n is the initial value of variable a, and m is the initial value of variable b.

Output

Print two integers — the values of a and b after the end of the process.

Examples
Input
Copy
12 5
Output
Copy
0 1
Input
Copy
31 12
Output
Copy
7 12
Note

Explanations to the samples:

  1. a = 12, b = 5 a = 2, b = 5 a = 2, b = 1 a = 0, b = 1;
  2. a = 31, b = 12 a = 7, b = 12.

题意:按照题目所述,输出a和b的值。

思路:一开始是模拟,因为没有看数据范围,后来企图用大数的方式过,其实longl long 就行了啊,当时估计脑子抽了~~最后还是不行,百度题解才知道是辗转相除。。。。嗯嗯 ,仔细想想确实也是啊,反正就两种情况,a>=2*b,b>=2*a,相减改为取余。

#include<stdio.h>

int main()
{
	long long a,b;
	while(scanf("%lld%lld",&a,&b)!=EOF)
	{
		int flag = 1;
		while(a&&b)
		{
			if(a>=2*b)
				a = a%(2*b);
			else if( b >= 2*a)
				b = b%(2*a);
			else
				break;
		}
		printf("%lld %lld\n",a,b);
	}
	return 0;
}

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

You are given a string s consisting of |s| small english letters.

In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter.

Your target is to make some number of moves (not necessary minimal) to get string abcdefghijklmnopqrstuvwxyz (english alphabet) as a subsequence. Subsequence of the string is the string that is obtained by deleting characters at some positions. You need to print the string that will be obtained from the given string and will be contain english alphabet as a subsequence or say that it is impossible.

Input

The only one line of the input consisting of the string s consisting of |s| (1 ≤ |s| ≤ 105) small english letters.

Output

If you can get a string that can be obtained from the given string and will contain english alphabet as a subsequence, print it. Otherwise print «-1» (without quotes).

Examples
Input
Copy
aacceeggiikkmmooqqssuuwwyy
Output
Copy
abcdefghijklmnopqrstuvwxyz
Input
Copy
thereisnoanswer
Output
Copy
-1

题意:给定的字符串,有字母a~z组成,任意一个字母可以变成它在字母表中的下一个字母,比如a可以变成b,z不能变,问,输入的字符串在经过改变后能否存在a~z字母组成的子序列。

思路:题意有点难理解,交上去WA一次,其实就是从a开始,往后遍历,只要遇到小于等于a的字母,就赋值为a,并且a的值也要增加,这样才能保证形成a~z的序列。

结:虽然这道题,看了题解以后发觉并不难,而且思路和当时我脑海中的一种想法很符合,但是我没有继续想下去,总是怕错。。。。这样可不行,写不出来题的情况下,想法再离谱也得去尝试,否则,比赛的时候,谁来帮自己呢~~~


#include<stdio.h>
#include<string.h>
const int maxn = 100010;
char vis[maxn];
char str[26] ;
int main()
{
	while(scanf("%s",vis)!=EOF)
	{
		char ch = 'a';
		for(int i = 0;vis[i]!='\0';i++)
		{
			if(ch == 'z'+1)
				break;
			if(vis[i] <= ch)
				vis[i] = ch ++;
		}
		
		if(ch == 'z'+1)
			printf("%s\n",vis);
		else
			printf("-1\n");
	}
	return 0;
}



版权声明:转载的时候给我说一声哦~~~ https://blog.csdn.net/hello_sheep/article/details/79952104

Educational Codeforces Round 39 (Rated for Div. 2) D Timetable

题目链接:点击打开链接题意:某大学一周有n天,一天有m小时工作/上课时间。给定n行m列0 和 1组成的字符,当第i行第j列为1时表示第i天第j小时有课。主角每天在学校的时间为第一节课到最后一节课之间(...
  • Lfhase
  • Lfhase
  • 2018年03月07日 02:10
  • 83

Educational Codeforces Round 34 (Rated for Div. 2)

这是我这个弱渣第一次正儿八经打codeforce的比赛 只水出来A题一道签到题,B题和C题只是有思路 但是并没有写出来 至于D E F就根本没有看 可能没有挑战的欲望吧 以后就算做不出来也会想一想思路...
  • hdsdogge
  • hdsdogge
  • 2017年12月13日 16:57
  • 91

Educational Codeforces Round 36 (Rated for Div. 2) 题解

先总结一波 第一次打cf,感觉还不错,题目做得挺顺手。虽然开始30min才想起来有这么个比赛来着。。 纪念一下第一次的rank,话说题真是水 这是大概还剩下5min的时候截的,实际可能会...
  • jpwang8
  • jpwang8
  • 2018年01月13日 23:16
  • 361

Educational Codeforces Round 39 (Rated for Div. 2) D. Timetable (背包)

题意:    一个周期有n天,每天有m节课,一个周期的时间可以逃课k次。问至少要在学校里待多久。(从早上去的第一节课到最后一节课,如果没有课就不去)分析:    每天有x节课,我们需要考虑旷课[0,x...
  • lj130lj
  • lj130lj
  • 2018年03月08日 20:20
  • 17

Educational Codeforces Round 41 (Rated for Div. 2)

A:找出现次数最少的 B:贪心,寻找长度为k区间的,标记0的最大和,预处理下标记为0的前缀和 C:对于四块板子,可行的方案中. 1/3板子一样,2/4板子一样,并且有2种方案 1...
  • Haipai1998
  • Haipai1998
  • 2018年04月05日 10:33
  • 61

Educational Codeforces Round 41 (Rated for Div. 2)(持续更新中)

题目原文懒得放了,丢个链接:点击打开链接A:平台上有n个槽,然后要往里面放1*1的方块,如果n个槽的底部同时有方块那么所有槽底下的方块同时去掉,然后你得一分!……想起了什么经典游戏呢哈哈哈……数据较小...
  • Cutec_lbq
  • Cutec_lbq
  • 2018年04月05日 09:18
  • 59

Educational Codeforces Round 40 (Rated for Div. 2) G. Castle Defense

http://codeforces.com/contest/954/problem/G题目很巧妙的第一个地方在于把弓箭手讷讷感覆盖到的第一个位置 +1,不能覆盖到的位置 -1,后面的加前面的遍历一遍就...
  • qq_36706625
  • qq_36706625
  • 2018年03月24日 00:51
  • 26

Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2)

题目A. Vicious Keyboardtime limit per test2 seconds memory limit per test256 megabytes inputstandard...
  • wwx233
  • wwx233
  • 2017年04月18日 19:46
  • 280

Educational Codeforces Round 38 (Rated for Div. 2) 【B】 【双指针】

B. Run For Your Prize time limit per test 1 second memory limit per test 256 megabytes ...
  • Head_Hard
  • Head_Hard
  • 2018年02月21日 16:56
  • 59

Educational Codeforces Round 35 (Rated for Div. 2) A

A. Nearest Minimums time limit per test2 seconds memory limit per test256 megabytes inputstandard...
  • zxy160
  • zxy160
  • 2018年01月11日 21:13
  • 132
收藏助手
不良信息举报
您举报文章:Educational Codeforces Round 39 (Rated for Div. 2)
举报原因:
原因补充:

(最多只允许输入30个字)