ACM:Gemini's Trial(1)

For a positive integer n let’s define a function f:
f(n) =  - 1 + 2 - 3 + … + ( - 1)nn
Your task is to calculate f(n) for a given integer n.
Input
The single line contains the positive integer n (1 ≤ n ≤ 1015).
Output
Print f(n) in a single line.
Examples
Input
4
Output
2
Input
5
Output
-3
Note
f(4) =  - 1 + 2 - 3 + 4 = 2
f(5) =  - 1 + 2 - 3 + 4 - 5 =  - 3

AC:

#include<iostream> 
using namespace std; 
int main() 
{
	long long n; 
	while(cin>>n) 
	{ 
		if(n%2==0) 
			cout<< n/2<<endl; 
		else cout<< -n/2-1<<endl; 
	} 
	return 0; 
}

Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.

Let’s assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words “WUB” before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including “WUB”, in one string and plays the song at the club.

For example, a song with words “I AM X” can transform into a dubstep remix as “WUBWUBIWUBAMWUBWUBX” and cannot transform into “WUBWUBIAMWUBX”.

Recently, Petya has heard Vasya’s new dubstep track, but since he isn’t into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song.
Input
The input consists of a single non-empty string, consisting only of uppercase English letters, the string’s length doesn’t exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring “WUB” in it; Vasya didn’t change the word order. It is also guaranteed that initially the song had at least one word.
Output
Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space.
Examples
Input
WUBWUBABCWUB
Output
ABC

AC:

#include<stdio.h>
#include<string.h>
int main()
{
	int i = 0,j = 0;
	int len= 0;
	char a[500];
	
	scanf("%s",&a);
	len=strlen(a);
	for(i=0;i<len-2;i++)
	{
		if(a[i]=='W'&&a[i+1]=='U'&&a[i+2]=='B')
		{
			a[i]=' ';
			a[i+1]=' ';
			a[i+2]=' ';
			i+=2;
		}
	}

	for(i=0;i<len;i++)
	{
		if(a[i]==' ')
		{
			printf(" ");
			for(j=i;j<len;j++)
			{
				if(a[j]!=' ')
				{
					i=j-1;
					break;
				}
			}
		}
		else
			printf("%c",a[i]);
	}

	return 0;
}


After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of n horizontal and m vertical sticks.

An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick.

In the grid shown below, n = 3 and m = 3. There are n + m = 6 sticks in total (horizontal sticks are shown in red and vertical sticks are shown in green). There are n·m = 9 intersection points, numbered from 1 to 9.

The rules of the game are very simple. The players move in turns. Akshat won gold, so he makes the first move. During his/her move, a player must choose any remaining intersection point and remove from the grid all sticks which pass through this point. A player will lose the game if he/she cannot make a move (i.e. there are no intersection points remaining on the grid at his/her move).

Assume that both players play optimally. Who will win the game?

Input
The first line of input contains two space-separated integers, n and m (1 ≤ n, m ≤ 100).
Output
Print a single line containing “Akshat” or “Malvika” (without the quotes), depending on the winner of the game.
Examples
Input
2 2
Output
Malvika
Input
2 3
Output
Malvika
Input
3 3
Output
Akshat
Note
Explanation of the first sample:
The grid has four intersection points, numbered from 1 to 4.
If Akshat chooses intersection point 1, then he will remove two sticks (1 - 2 and 1 - 3). The resulting grid will look like this.
Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remove both remaining sticks. After her move the grid will be empty.
In the empty grid, Akshat cannot make any move, hence he will lose.
Since all 4 intersection points of the grid are equivalent, Akshat will lose no matter which one he picks.

#include <iostream>
#include<stdio.h>
#include<algorithm>
 using namespace std ;
int main()
{
    int n = 0, m =0,ans =0;
	scanf("%d %d",&n,&m);
	
	 ans = min(n,m) ;
	if(ans % 2)
		printf("Akshat") ;
	else 
		printf("Malvika") ;

	 return 0 ;
}

Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don’t know that Computer College had ever been split into Computer College and Software College in 2002.
The splitting is absolutely a big event in HDU! At the same time, it is a trouble thing too. All facilities must go halves. First, all facilities are assessed, and two facilities are thought to be same if they have the same value. It is assumed that there is N (0<N<1000) kinds of facilities (different value, different kinds).
Input
Input contains multiple test cases. Each test case starts with a number N (0 < N <= 50 – the total number of different facilities). The next N lines contain an integer V (0<V<=50 --value of facility) and an integer M (0<M<=100 --corresponding number of the facilities) each. You can assume that all V are different.
A test case starting with a negative integer terminates input and this test case is not to be processed.
Output
For each case, print one line containing two integers A and B which denote the value of Computer College and Software College will get respectively. A and B should be as equal as possible. At the same time, you should guarantee that A is not less than B.
Sample Input
2
10 1
20 1
3
10 1
20 2
30 1
-1
Sample Output
20 10
40 40

AC:

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int val[10000] = {0};
int dp[100000] = {0};

int main()
{
	int n = 0,i = 0,j = 0,pri = 0,count = 0,kind = 0,sum = 0;
	
    while(~scanf("%d",&n),n>0)
	{
		memset(val,0,sizeof(val));
		memset(dp,0,sizeof(dp));
		
		pri = 0,count = 0,kind = 0,sum = 0;
		for(i = 0;i<n;i++)
		{
			scanf("%d%d",&pri,&count);
			while(count--)
			{
				val[kind++] = pri;
				sum+=pri;
			}
		}
		for(i = 0;i<kind;i++)
		{
			for(j = sum/2;j>=val[i];j--)
				dp[j] = max(dp[j],dp[j-val[i]]+val[i]);
		}
		printf("%d %d\n",sum-dp[sum/2],dp[sum/2]);
	}
	

	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值