Codeforces Round #469 (Div. 2) a,b,c,d

Source: Internet
Author: User
Tags printf split time limit
A. Left-handers, right-handers and ambidexters time limit per test 1 second memory limit per test, megabytes input Stan Dard Input Output Standard output

You is at a water bowling training. There is l people who play with their-left hand, R-People, who play with their right hand, and Aambidexters, who can play With left or right hand.

The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, And exactly half of the players should play with their left hand. One player should use is on the of his hands.

Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand.

Please find the maximum possible size of the team, where equal number of players use their left and right hands, Respectiv Ely. Input

The only line contains three integers L, R and a (0≤l, R, a≤100)-the number of left-handers, the number of Right-han DERs and the number of ambidexters at the training. Output

Print a single even integer-the maximum number of players in the team. It is possible, the team can only has a zero number of players. Examples input Copy

1 4 2
Output
6
Input Copy
5 5 5
Output
14
Input Copy
0 2 0
Output
0
Note

In the first example you can form a team of 6 players. You should take the only left-hander and both ambidexters to play with left hand, and three right-handers to play with Righ T hand. The only person who left can ' t is taken into the team.

In the second example you can form a team of people. Five left-handers, all five right-handers, both ambidexters to play with left hand and both ambidexters To play with the right hand.

Test instructions: There are three parts of people, the first part can only use the left hand, the second part can only use the right hand, the third part of two hands can be used, the third section can be added to 122 part, the three parts of the people into two groups, asked two groups of the same number, asked the two groups combined up the maximum value

A discussion on the number relationship of three parts directly

Code

#include <cstdio>
#include <math.h>

int max (int x, int y)
{
	if (x >= y) return x;
	else return y;
}

int main ()
{
	int L, R, A;
	while (scanf ("%d%d", &l, &r, &a)! = EOF)
	{
		if (L + a <= R)
		{
			printf ("%d\n", (L + a) );
			Continue;
		}
		if (R + a <= L)
		{
			printf ("%d\n", (R + a));
			Continue;
		}
		int x = fabs (l-r);
		int y = a-x;
		int maxx = MAX (L, R);
		int ans = 2*maxx;
		if (y% 2 = = 0)
		{
			ans = ans + y;
		}
		else
		{
			ans = ans + y-1;
		}
		printf ("%d\n", ans);
	}
	return 0;
}

B. Intercepted Message time limit per test 1 second memory limit per test megabytes input standard input output Standa RD output

Hacker Zhorik wants to decipher, secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information.

Zhorik knows that each of the messages are an archive containing one or more files. Zhorik knows how each of the these archives is transferred through the Network:if an archive consists of K files of sizes L1 , L2, ..., lk bytes, then the i-th file was split to one or more blocks bi, 1, Bi, 2, ..., Bi, MI (here the total length of The blocks bi, 1 + bi, 2 + ... + bi, MI is equal to the length of the file Li), and after this all blocks are transferred Through the network, maintaining the order of files in the archive.

Zhorik thinks that the and the messages contain the same archive, because their total lengths is equal. However, each file can is split in blocks in different ways in the same as messages.

You is given the lengths of blocks in each of the messages. Help Zhorik to determine what's the maximum number of files could be in the archive, if the Zhorik ' s assumption are correc T. Input

The first line contains-integers n, m (1≤n, m≤105)-the number of blocks in the first and in the second messages.

The second line contains n integers x1, x2, ..., xn (1≤xi≤106)-the length of the blocks that form the first message.

The third line contains m integers y1, y2, ..., ym (1≤yi≤106)-the length of the blocks that form the second message.

It is guaranteed that x1 + ... + xn = y1 + ... + ym. Also, it's guaranteed that x1 + ... + xn≤106. Output

Print the maximum number of files The intercepted array could consist of. Examples input Copy

7 6
2 5 3 1 each 4 4 7
8 2 4 1 8
Output
3
Input Copy
3 3
1
1 100 10
Output
2
Input Copy
1 4
4
1 1 1 1
Output
1
Note

The first example the maximum number of files in the archive is 3. For example, it's possible that in the archive is three files of sizes 2 + 5 = 7, 3 + 1 + one = 8 + 2 + 4 + 1 and 4 + 4 = 8.

In the second example it's possible that the archive contains the files of sizes 1 and 110 = 10 + 100 = 100 + 10. Note that the order of files was kept while transferring archives through the network, so we can ' t say that there was three Files of sizes 1, and 100.

The third example the only possibility is, the archive contains a single file of size 4.

Test instructions: A method of data encryption, block encryption, each chunk encrypted memory size is the same, give two encrypted sequences, the same encryption method, the number of encrypted chunks

Puzzle: Direct violence aside, use two variables to record the memory of the current chunk of two data, and if the two variables are equal, then the number of chunks + +, then reset the two variables

Code

#include <cstdio>
#define MAX 100010

int A[max], B[max];

int max (int x, int y)
{
	if (x >= y) return x;
	else return y;
}

int main ()
{
	int n, m;
	while (scanf ("%d%d", &n, &m)! = EOF)
	{
		for (int i = 0; i < n; i++)
			scanf ("%d", &a[i]);
		for (int i = 0; i < m; i++)
			scanf ("%d", &b[i]);
			
			
		int ans = 0;
		int sum1 = A[0], sum2 = b[0];
		for (int i = 1, j = 1; i <= n;)
		{
			if (Sum1 < sum2)
			{
				sum1 + = A[i];
				i++;
			}
			else if (sum1 > Sum2)
			{
				sum2 + = b[j];
				j + +;
			}
			else if (sum1 = = sum2)
			{
				ans++;
				SUM1 = a[i++];
				sum2 = b[j++];
				/*printf ("ans =%d\n", ans);
				printf ("sum1 =%d\n", sum1);
				printf ("sum2 =%d\n", sum2); */
			}
		}
		printf ("%d\n", ans);
	}
	return 0;
}

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

Oleg writes down the history of the the and he lived. For each day he decides if it is good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days a Re alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 is zebras, while sequences 1,

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.