东北大学校赛重现

LIST has a list

Problem Description

A famous ACMer named LIST.He is very rich,so he has infinite coins of some par value(面值).One day he has a list of things he want

to buy.And he is so rich,he can buy a things for many ways.for example,if he want to spend 5 yuan to buy a things,he will give the seller five coins (1,1,1,1,1) or three coins (2,2,1) or two coins (3,2) and so on.Now he wants to ask you to help him calculate how many ways he can pay m yuan.

Input

In the first line is a number T means the amount of cases(T<=50).And in each case,the first line has two numbers ,n(the amount of the par value, n<=30) and m(the sum of money LIST has to spend, m<=150).

In the next line has n numbers mean the different par value(each par value is no more than 35).

Output

Each case output one line,like"Case #i: Ai"(i is the number of case and Ai is the number of ways in this case).

Ai might be big,but it can't be very big.

Sample Input

1

5 13

1 2 3 5 10

Sample Output

Case #1: 37

//题意:输入n,m,接着输入n个数

表示给你n张钞票,每张钞票的面值不同,问现在要用这n张钞票组合成m,问总共有几种组合方法

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
const int MAXN = 300;
LL a[MAXN], b[MAXN];
int num[MAXN];
int main(){
	int T, n, m, kase = 0;
	scanf("%d", &T);
	while(T--){
		scanf("%d%d", &n, &m);
		for(int i = 0; i < n; i++){
			scanf("%d", num + i);
		}
		memset(a, 0, sizeof(a));
		memset(b, 0, sizeof(b));
		for(int i = 0; i <= m; i += num[0])
			a[i] = 1, b[i] = 0;
		for(int i = 1; i < n; i++){
			for(int j = 0; j <= m; j++){
				for(int k = 0; j + k * num[i] <= m; k++){
					if(j + k * num[i] <= m){
						b[j + k * num[i]] += a[j];
					}
				}
			}
			for(int j = 0; j <= m; j++)a[j] = b[j], b[j] = 0;
		}
		printf("Case #%d: %lld\n", ++kase, a[m]);
	}
	return 0;
}


 

So Easy!!!

Problem Description

yizhen has no girlfriend due to his stupid brain that he even can’t solve a simple arithmetic roblem. Can you help him? If you solve it and tell him the result, then he can find his lovers! So beautiful!

Input

The input consists of multiple test cases. Each test case contains some integers (every number is smaller than 2^31-1)and operator on a single line (operator including *,+,-,/ )  Process to end of file.

There are no space between number and operator and I promise that all those results of A/B is integer.

Output

For each test case, output the result of the arithmetic problem.( All those results isn’t decimal number)

Sample Input

1+2+3

1*2+2+4-5

Sample Output

6

3

//题意:

给你一串数学计算公式,只有+,-,*,/,四种运算符,问最终结果是多少?

//思路:

直接栈模拟

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<stack>
using namespace std;
typedef long long LL;
char s[1000010];
bool is_diget(int x)
{
	if(x >= '0' && x <= '9')return true;
	else return false;
}
int main()
{
	while(~scanf("%s", s))
	{
		stack<LL>S;
		LL temp, temp1;
		for(int i = 0; s[i];)
		{
			if(is_diget(s[i]))
			{
				 temp = 0;
				while(is_diget(s[i]))
				{
					temp = temp * 10 + s[i] - '0';
					i++;
				}
				S.push(temp);
			}
			else
			{
				switch(s[i])
				{
					case '+':
						i++;
						break;
					case '-':
						i++;
						temp = 0;
						while(is_diget(s[i]))
						{
							temp = temp * 10 + s[i] - '0';
							i++;
						}
						temp = -temp; 
						S.push(temp);
						break;
					case '*':
						i++;
						temp = 0;
						while(is_diget(s[i]))
						{
							temp = temp * 10 + s[i] - '0';
							i++;
						}
						temp1 = S.top();
						S.pop();
						S.push(temp1 * temp);
						break;
					case '/':
						i++;
						temp = 0;
						while(is_diget(s[i]))
						{
							temp = temp * 10 + s[i] - '0';
							i++;
						}
						temp1 = S.top();
						S.pop();
						S.push(temp1 / temp);
						break;
				}
			}
		}
		temp = 0;
		while(!S.empty())
		{
			temp += S.top();
			S.pop();
		}
		printf("%lld\n",temp);
	}
	return 0;
}


 

Sum it up

Problem Description

Given a integer n (0 < n < 1e6), find the sum of x, which x meet the following conditions: gcd(x, n)!=1 && 0<x<=n. BTW, gcd(m, n) means greatest common divisor between m and n.

Input

The first line of the input file contains T (T<500), indicating the number of test cases.

There is only one number in each test cases: n, the meaning of which has been described above.

Output

For each test case, output one line containing “Case #x: y”, where x is the test case number (starting from 1) and y is the sum. (without quotation)

Sample Input

2

3

10

Sample Output

Case #1: 3

Case #2: 35

//题意:给你一个数n,让你找出在[1---n]之间与n不互质的数的和。

//思路:欧拉函数先求出与n互质的数的个数,再根据公式求得与n互质的数的和ans=eulor(n)*n/2,再用总和减去就行了sum=(n+1)*n/2-ans;

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
ll oula(int x)
{
	int ans = x;
	for(int i = 2; i <= sqrt(x); i++)
	{
		if(x % i == 0)
		{
			ans = ans * (i - 1)/i;
			while(x % i == 0)
			{
				x /= i;
			}	
		}
		
	}
	if(x > 1)
		ans = ans * (x - 1)/x;
	return ans;
}
int main()
{
	int T, n, kase = 0;	
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d", &n);
		ll sum=(ll)n*(n+1)/2;
		ll ans=oula(n)*n/2;
		printf("Case #%d: %lld\n",++kase,sum-ans);
	}
	return 0;
}


 

Drink It

Problem Description

来来来,做道题,一起防老年痴呆。啤酒2元一瓶,4个瓶盖换一瓶,2个空瓶换一瓶。问:n元可换几瓶。不可以赊账不可以买半瓶酒.

Input

多组数据,输入文件第一行是一个整数T,接下来T行,每行一个整数n(0<=n<=10000000)

Output

问最多能够得到多少瓶啤酒

Sample Input

2

0

10

Sample Output

0

15

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#include<algorithm>
#include<iostream>
#define INF 0x3f3f3f3f
#define ull unsigned long long
#define ll long long
#define N 100010
#define M 1000000007
using namespace std;
int main()
{
	int i,j,k;
	int n,m,t;
	scanf("%d",&t);
	while(t--)
	{
		int sum=0;
		scanf("%d",&n);
		int p=n/2;
		int pg=p;
		sum+=p;
		while(1)
		{
			if(p>=2)
			{
				int s=p/2;
				sum+=s;p=p-(2*s)+s;pg+=s;
			}
			if(pg>=4)
			{
				int ss=pg/4;
				sum+=ss;p+=ss;pg=pg-(4*ss)+ss;
			}
			if(p<2&&pg<4)
				break;
		}
		printf("%d\n",sum);
	}
	return 0;
}
<h3>一个经典问题</h3><h3>Problem Description</h3><div class="fr-view word_cut"><p style="margin: 0px 0px 10px; font-family: Roboto;">有两个字符串,比如:abedc与acbde,它们公共的序列有许多种,这个序列在原串中可以是不连续的,比如ab,ad,abe,e等都可算做他们的公共序列,但是最长的序列为abe,长度为3,那么怎么求出这个序列最长是多少呢?</p></div><h3>Input</h3><div class="fr-view word_cut"><p style="margin: 0px 0px 10px; font-family: Roboto;">第一行是一个整数T,代表多少组数据(T<=15)</p><p style="margin: 0px 0px 10px; font-family: Roboto;">每组数据给出两个字符串(由小写字符组成),长度都小于5000</p></div><h3>Output</h3><div class="fr-view word_cut"><p style="margin: 0px 0px 10px; font-family: Roboto;">按题意输出一个整数</p></div><h3>Sample Input</h3><p class="word_cut">2</p><p class="word_cut">abcde</p><p class="word_cut">edcba</p><p class="word_cut">abedc</p><p class="word_cut">acbde</p><h3>Sample Output</h3><p class="word_cut">1</p><p class="word_cut">3</p>
<pre class="cpp" name="code">#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
const int MAXN = 5050;
int dp[MAXN][MAXN];
char s1[MAXN], s2[MAXN];
int main()
{
	int T, len1, len2;
	scanf("%d", &T);
	while(T--)
	{
		scanf("%s%s", s1 + 1, s2 + 1);
		memset(dp, 0, sizeof(dp));
		len1 = strlen(s1 + 1);
		len2 = strlen(s2 + 1);
		for(int i = 1; i <= len1; i++)
		{
			for(int j = 1; j <= len2; j++)
			{
				if(s1[i] == s2[j])
				{
					dp[i][j] = max(dp[i - 1][j - 1] + 1, dp[i][j]);
				}
				else
				{
					dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
				}
			}
		}
		printf("%d\n",dp[len1][len2]);
	}
	return 0;
}
 
 

判断回文数

Problem Description

如果一个数是左右对称,那么就是回文数。比如1、1221、121、1234567890987654321是回文数,而100、12345432不是。

Input

多组测试数据,每个一行,每行一个数,无前导0

Output

每组数据一行,如果是回文数输出Yes,否则为NO

Sample Input

1

1221

33333

76543

Sample Output

Yes

Yes

Yes

NO

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
const int MAXN = 100010;
char s[MAXN];
int main()
{
	int T, len;
	while(scanf("%s",s)!=EOF)
	{
		len = strlen(s);
		int ans = 1;
		for(int i = 0, j = len - 1; i < j; i++, j--)
		{
			if(s[i] != s[j])
			{
				ans = 0;
				break;
			}
		}
		if(ans)
			puts("Yes");
		else 
			puts("NO");
	}
	return 0;
}
I



 

你可能感兴趣的:(东北大学校赛重现)