水题(1)直接计算答案

目录

CSU 1111 三家人

CSU 1018 Avatar

CSU 1039 三个数

CSU 1190 Staginner's Paper

CSU 1191 Staginner Is Smarter Than Gauss!

CSU 1192 Staginner 的手帕

CSU 1193 Staginner 的幸运数字

CSU 1194 Staginner 买蛋挞

CSU 1220 ACM小组的组长

CSU 1221 ACM小组的成绩排名

CSU 1222 ACM小组的贪食蛇

CSU 1265 Dice(骰子)

CSU 1345 Grayscale

CSU 1406 身体质量指数

CSU 1449 A+B and C

CSU 1459 Chess

CSU 1468 Level Up

CSU 1524 Tone Number of MIDI

CSU 1586 分奖金

CSU 1870 Legendary

CSU 1902 Happy Chinese Poker

CSU 2062 Z‘s Array

HDU 1000 A + B Problem

HDU 1001 Sum Problem

HDU 1212 Big Number

OpenJ_Bailian 1000 A+B Problem

OpenJ_Bailian 1019 Number Sequence


CSU 1111 三家人

题目:

Description

有三户人家共拥有一座花园,每户人家的太太均需帮忙整理花园。A 太太工作了5 天,B 太太则工作了4 天,才将花园整理完毕。C 太太因为正身怀六甲无法加入她们的行列,便出了90元。请问这笔钱如何分给A、B 二位太太较为恰当?A 应得多少元?90/(5+4)*5=$50 元?如果这么想你就上当了!正确答案是60 元。如果没想通的话再想想吧。

下面回答一个一般性的问题:假定A 太太工作了x 天,B 太太工作了y 天,C 太太出了90元,则A 太太应得多少元?输入保证二位太太均应得到非负整数元钱。三个太太工作效率相同。

友情提示:本题有个小小的陷阱哦。如果答案错的话,认真检查一下代码吧。

Input

输入第一行为数据组数T (T<=20)。每组数据仅一行,包含三个整数x, y, z (1<=x, y<=10,1<=z<=1000)。

Output

对于每组数据,输出一个整数,即A 太太应得的金额(单位:元)。

Sample Input

2
5 4 90
8 4 123

Sample Output

60
123

既然题目说了“输入保证二位太太均应得到非负整数元钱”,那自然只需要int就够了

代码:

#include<iostream>
using namespace std;
 
int main()
{
    int n;
    cin >> n;
    int x, y, z;
    while (n--)
    {
        cin >> x >> y >> z;
        cout << (x + x - y)*z / (x + y) << endl;
    }
    return 0;
}

CSU 1018 Avatar

题目:

Description

In the planet Pandora, Jake found an old encryption algorithm. The plaintext, key and ciphertext are all four decimal numbers and all greater than 0. The way to get the ciphertext from the plaintext and the key is very simple: the ciphertext is the last four digits of the product of the plaintext and the key (for example: the plaintext is 2010 and the key is 4024, and then the product is 8088240. So the ciphertext is 8240).

Note that the plaintext and the key don’t have leading 0, while the ciphertext might have. Now given the plaintext and the key, you are asked to figure out the ciphertext for Jake quickly.

Input

The first line is an integer T, which presents the number of test cases. Then there are T lines, each line has two integers, the first integer is the plaintext and the second is the key.

Output

For each test case, output the ciphertext.

Sample Input

2
2010 4024
1234 1111

Sample Output

8240
0974

代码:

#include<iostream>
using namespace std;
 
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n, m;
        cin >> n >> m;
        printf("%04d\n", n*m % 10000);
    }
    return 0;
}

CSU 1039 三个数

题目:

Description

给出三个不相等的数,求最大数减去最小数的差。

Input

 第一行为整数n,测试样例个数。

接下来n行,每行三个空格隔开的不大于100000的正整数。

Output

 每行数据对应输出一行,一个数,即最大数减去最小数的差。

Sample Input

2
1 2 3
8 5 10

Sample Output

2
5

代码:

#include<iostream>
using namespace std;
 
int main()
{
	int n, a, b, c;
	cin >> n;
	while (n--)
	{
		cin >> a >> b >> c;
		if (a > b)a ^= b ^= a ^= b;
		if (a > c)a ^= c ^= a ^= c;
		if (b > c)b ^= c ^= b ^= c;
		cout << c - a << endl;
	}
	return 0;
}

CSU 1190 Staginner's Paper

题目:

Description

It's time for Staginner to going to the test of Probability Theory , however , He is so stupid that he can't pass test by individual participate. So in order to raise the rate of pass , the professor give him the paper that only contain integer number division. And what's more , the professor told him Staginner do not need to calculate the result if two numbers cannot to be divided with no remainder . So Staginner was going to be grateful...

However , Staginner thought that it's too simple to do that , so he find you to take part in the Probability Theory test instead.

Input

There are several lines in the input which show the problems of test paper.

Each line include TWO INTEGERS a , b ( 0<a,b<10^9 ) separate by one space represent the problem a/b = ?.

Input file is end by EOF.

Output

There are several output lines carry with corresponding input lines , each line output A INTEGER represent the answer for corresponding problem. If in a problem that a cannot divide b with no reminder, output 'Don't need to calculate.'(don't include quotes )

Sample Input

6 2
2 2
3 5

Sample Output

3
1
Don't need to calculate.

代码:

#include<iostream>
using namespace std;
 
int main()
{
	int a, b;
	while (cin >> a >> b)if (a%b)cout << "Don't need to calculate.\n";else cout << a / b << endl;
	return 0;
}

CSU 1191 Staginner Is Smarter Than Gauss!

题目:

Description

While Staginner was in primary school , he heard that Gauss could easily calculate the sum of 1+2+...+100 , however , Staginner could easily calculate the sum of integers between two positive integers a,b(a<b). So he thought that he was smarter than Gauss.

So many people scorn at Staginner . So It's time for you to show to Staginner that it's a easy problem for you too.

Input

There are several lines in the input , each line has two integers a,b(0<a<b<10^4) which separate by one space.

Input file is end by EOF.

Output

There are several output lines carry with corresponding input lines , each line output a integer represent the result of a+(a+1)+...+(b-1)+b.

Sample Input

1 100
5 6

Sample Output

5050
11

代码:

#include<iostream>
using namespace std;
 
int main()
{
	int a, b;
	while (cin >> a >> b)cout << (a + b)*(b - a + 1) / 2 << endl;
	return 0;
}

CSU 1192 Staginner 的手帕

题目:

Description

又快到冬天了, Staginner 的鼻子又开始不停地流晶莹剔透的液体了,于是

Staginner 希望你能够按他制定的大小给他制作一块三角形手帕,即如样例输出的等腰三角形。

Input

输入包含多组数据,每组数据包含一个整数N(2<N<50),代表Staginner 想要的三

角形手帕的大小,并且N 均为奇数。

读入以EOF结束。

Output

对于每组数据输出Staginner 想要的三角形手帕的具体形状。每组数据后面输出一个

空行。

Sample Input

3
5

Sample Output

 *
***

  *
***
*****

Hint

每个手帕的最后一行均有N 个*,且最后一行*的左边是没有空格的,每串*的最后一个*的

后面都不应有任何多余的空格。

代码:

#include<iostream>
using namespace std;
 
int main()
{
	int n, flag = 0;
	while (cin >> n)
	{
		if (flag)cout << endl;
		for (int i = 1; i <= n; i += 2)
		{
			for (int j = 0; j < n - i; j += 2)cout << ' ';
			for (int j = 0; j < i; j++)cout << '*';
			cout << endl;
		}
		flag = 1;
	}
	return 0;
}

CSU 1193 Staginner 的幸运数字

题目:

Description

自从gestapolur 告诉Staginner 数字233 是马尔可夫方程的一个解之后,

Staginner 就把它看做是自己的幸运数字。今天,Staginner 在看概率论的书时,发现

上面有很多有趣的整数,Staginner 希望你能告诉他这些数字中一共有多少个233。

Input

输入包含若干组数据,每组数据有两行。第一行有一个整数N(1<=N<=100),代表

Staginner 一共看到了多少个数字,第二行有N 个整数,分别代表Staginner 看到的各

个数字的具体值。

读入以EOF结束。

Output

对于每组数据,输出一个整数代表这组数据中233 出现的次数。

Sample Input

3
233 233 233
4
1 2 3 4

Sample Output

3
0

代码:

#include<iostream>
using namespace std;
 
int main()
{
	int n, a;
	while (cin >> n)
	{
		int ans = 0;
		while (n--)
		{
			cin >> a;
			ans += (a == 233);
		}
		cout << ans << endl;
	}
	return 0;
}

CSU 1194 Staginner 买蛋挞

题目:

Description

Staginner 很喜欢吃蛋挞,而且他每次总想买最重的一个蛋挞,反正价格都是一样的,

为什么不多吃一点呢?现在摆在Staginner 面前的一共有N*M 个蛋挞,Staginner 可郁

闷了,到底哪个是最重的呢?

这时,gestapolur 从一旁神秘的走了过来,并且告诉了Staginner 每个蛋挞的重

量,尽管Staginner 也不知道gestapolur 究竟是如何知道每个蛋挞的重量的,但是没

关系,Staginner 相信gestapolur 说的都是对的,现在的问题就是请你找出来究竟哪

个蛋挞是最重的。

Input

输入包含若干组数据。每组数据的第一行有两个整数N、M(1<=N,M<=100),代表

Staginner 面前一共有N 行M 列共N*M 个蛋挞,接下来的N 行每行有M 个整数,位于第

i 行第j 列的整数d 代表第i 行第j 列的蛋挞的重量为d。蛋挞的重量是各不相同的。

读入以文件尾结束。

Output

对于每组数据,输出两个整数x、y,中间以一个空格隔开,代表Staginner 应该买

第x 行第y 列的那个蛋挞。

Sample Input

2 3
1 2 3
4 5 6

Sample Output

2 3

代码:

#include<iostream>
using namespace std;
 
int main()
{
	int n, m, d[101][101], max;
	while (cin >> n >> m)
	{
		max = 0;
		for (int i = 1; i <= n; i++)for (int j = 1; j <= m; j++)
		{
			cin >> d[i][j];
			if (max < d[i][j])max = d[i][j];
		}
		for (int i = 1; i <= n; i++)for (int j = 1; j <= m; j++)if (max == d[i][j])cout << i << " " << j << endl;
	}
	return 0;
}

CSU 1220 ACM小组的组长

题目:

Description

Samsara的小组需要选出一个组长。组内一共有n(不包括Samsara)个组长候选人,分别用1至n编号,小组m个人参与了投票,得票数最多的人将被选为组长。(如果出现得票数相同得情况,则选择编号最小的那个人)

Input

输入包含若干组数据,每组数据都有两行,第一行两个正整数n(1<=n<=10000)、m(1<=m<=100000),中间以空格隔开。第二行有用空格分隔的m个数a_1...a_i...a_m(1<=a_i<=n)表示第i个人投了编号为a_i的人一票。
读入以EOF结束。

Output

输出对应也有若干行,请输出组长的编号。

Sample Input

7 4
7 7 2 7
5 5
2 2 3 4 5

Sample Output

7
2

代码:

#include<iostream>
using namespace std;
 
int main()
{
	int n, m, r, ans[10000];
	while (scanf("%d%d", &n, &m) != EOF)
	{
		for (int i = 0; i < n; i++)ans[i] = 0;
		while (m--)
		{
			scanf("%d", &r);
			ans[r-1]++;
		}
		r = 0;
		for (int i = 1; i < n; i++)if (ans[r] < ans[i])r = i;
		printf("%d\n", r+1);
	}
	return 0;
}

CSU 1221 ACM小组的成绩排名

题目:

Description

为了保证每位ACMer学习的进度,检验其学习成果,每隔一段时间就要进行一次内部测验。Samsara被逼迫去评测,并且要给每个人一个分数,自然作为弱菜的他是没有时间和精力来进行排名统计了,希望会编程的你能帮他输出前三名的成绩。

Input

输入包含若干组数据,每组数据都有两行,第一行一个正整数n(3<=n<=1000000),第二行n个精确到百分位的浮点型小数,以空格隔开,分别代表第一个人到第n个人的成绩A[i](0<=A[i]<=100)。
读入以文件尾结束。

Output

对于每组输入对应一行输出。按顺序输出前三名的成绩,保留两位小数。

Sample Input

5
1.00 2.00 3.00 4.00 5.00

Sample Output

5.00 4.00 3.00

代码:

#include<iostream>
using namespace std;
 
int main()
{
	int n;
	while (scanf("%d", &n) != EOF)
	{
		double a = 0, b = 0, c = 0, d, e;
		for (int i = 0; i < n; i++)
		{
			scanf("%lf", &d);
			if (d > a)e = d, d = a, a = e;
			if (a > b)e = a, a = b, b = e;
			if (b > c)e = b, b = c, c = e;
		}
		printf("%.2f %.2f %.2f\n", c, b, a);
	}
	return 0;
}

CSU 1222 ACM小组的贪食蛇

题目:

Description

最近ACM小组养了一条贪食蛇,他们把它养在一个可看成二维空间的盒子里(因为它不会向高处爬嘛)。今天小组里的人都不知道出去干什么了,只留了n个食物 在箱子里,但是它又必须按照小组成员给出的1..n的顺序将食物吃完,贪食蛇的行进方式只能是向前,向后,向左,或者向右,而不能斜着走。请你帮它计算一 下它吃完这些食物总共要走过的路程长度。(PS这是一条不会长大的蛇,且它的身体并不会影响到自己的前进;)

Input

输入包含若干组数据,每组数据的第一行一个正整数n(1<=n<=100000)表示盒子里总共有n个食物;第二行两个正整数Sx和Sy,以 空格隔开,表示贪食蛇开始时的位置,第3至3+n-1行的数据中按顺序给出了n个食物的位置X_i和Y_i,表示第i个食物的位置 (|Sx,Sy,X_i,Y_i| <= 100000 )。
读入以EOF结束。

Output

每组数据对应一行输出,输出贪食蛇要按顺序吃完所有食物所走的路程长度。

Sample Input

2
1 1
2 2
3 3

Sample Output

4

代码:

#include<iostream>
using namespace std;
 
int main()
{
	int n;
	while (scanf("%d", &n) != EOF)
	{
		int a, b, c, d;
		long long r = 0;
		scanf("%d%d", &a, &b);
		while (n--)
		{
			scanf("%d%d", &c, &d);
			r += (a > c) ? a - c : c - a;
			r += (b > d) ? b - d : d - b;
			a = c, b = d;
		}
		cout << r << endl;
	}
	return 0;
}

CSU 1265 Dice(骰子)

题目:

Description

An example of a traditional dice is a rounded cube, with each of its six faces showing a different number of dots from 1 to 6. When thrown or rolled, the dice comes to rest showing on its upper surface a random integral points from one to six, each value being equally likely.

----wikipedia

Now we have two dices which both have six faces. Can you tell us the probability that the sum points of two dices equals S when we thrown?

Input

There is an integer T (1 <= T <= 11) in the first line, means there are T test cases in total.

For each test case, there is only one line with one integer S (2 <= S <= 12), which have the same meaning as above.

Output

For each test case, you should print the probability that the sum points of two dices equals S when we thrown. The answer should be in one line and rounding to 6 decimals.

Print a blank line after each test case.

Sample Input

2
2
3

Sample Output

0.027778

0.055556

代码:

#include<iostream>
using namespace std;
 
int main()
{
	int T, s;
	cin >> T;
	for (int i = 0; i < T; i++)
	{
		cin >> s;
		if (s > 7)s = 14 - s;
		if (i)cout << endl;
		printf("%.6f\n", (s - 1)*1.0 / 36);
	}
	return 0;
}

CSU 1345 Grayscale

题目:

Description

    We could represent a color point by a triple (RGB) (0 <= RGB <= 255). The grayscale of it could be calculated by this formula:
    Grayscale = R * 0.299 + G * 0.587 + B * 0.114

Input

    The first line has an integer T (1 <= T <= 100), means there are T test cases.
    For each test case, there are three integers RGB (0 <= RGB <= 255) in one line, which have the same meaning as above.

Output

    For each test case, print an integer in one line, indicates the integer part of the grayscale of this color point.

Sample Input

4
0 0 0
100 0 0
30 40 50
255 255 255

Sample Output

0
29
38
255

代码:

#include<iostream>
using namespace std;
 
int main()
{
	int t;
	double r, g, b;
	cin >> t;
	while (t--)
	{
		cin >> r >> g >> b;
		cout << int(r * 0.299 + g * 0.587 + b * 0.114) << endl;
	}
	return 0;
}

CSU 1406 身体质量指数

题目:

Description

身体质量指数( BMI ) 是用 一个人的体重(单位:kg) 除以身高 (单位:m)的 平方得出的 数值(单位:kg/m 2 ) ,是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。

BMI  =  体重 (kg)  /  ( 身高 (m)) 2

比如,如果一个人的体重和身高分别为 70kg ,  1.75m ,那么他的 BMI 为 70 / 1.75 2  ≈  22.86kg/m 2 。

对于中国人来讲,如果一个人的BMI小于 18.5 ,说明他体重过轻;如果BMI大于或等于23,说明他体重过重;否则,说明他的体重是正常的。

给出一个中国人的体重和身高,计算他的BMI并指出他的体重是否正常。

Input

输入的第一行包含一个整数 T  (1  ≤  T  ≤  200 ),表示一共有 T 组测试数据。

每组测试数据占一行,包含两个带有两位小数的浮点数 M ,  H  (40.00  ≤  M  ≤  1 5 0.00, 1. 3 0  ≤  H  ≤  2. 3 0),表示这个中国人的体重为 M (单位:kg),身高为 H (单位:m)。

Output

对于每组测试数据,输出一个字符串表示这个人的体重是否正常。如果这个人的体重过重,输出“ Over weight”(不包含引号);如果这个人体重过轻,输出“ Underweight ”(不包含引号);否则,输出“ Normal ”(不包含引号)。

Sample Input

5
70.00 1.75
73.99 2.00
74.00 2.00
92.00 2.00
91.99 2.00

Sample Output

Normal
Underweight
Normal
Overweight
Normal

代码:

#include<iostream>
using namespace std;
 
int main()
{
	int t;
	double m, h;
	cin >> t;
	while (t--)
	{
		cin >> m >> h;
		m /= h * h;
		if (m < 18.5)cout << "Underweight\n";
		else if (m >= 23)cout << "Overweight\n";
		else cout << "Normal\n";
	}
	return 0;
}

CSU 1449 A+B and C

题目:

Description

给出三个整数 A,B,C,判断 A+B与 C的大小关系。

Input

输入的第一行包含一个整数 T ( T > 0),表示一共有 T组测试数据。

对于每组测试数据,只有一行,包含三个整数 A,B,C( -2^63<=A,B,C< 2^63),数字之间用空格分开。

由于输入量很大,请不要使用cin而使用scanf来避免超时。

Output

对于每组测试数据,若A+B>C,输出“>”,若A+B=C,输出“=”,若A+B<C,输出“<”。

Sample Input

3
1 1 1
1 1 2
1 1 3

Sample Output

>
=
<

代码:

#include<iostream>
#include<stdio.h>
using namespace std;
 
int main()
{
	int t;
	char ans;
	long long a, b, c, max, min = 1;
	min = min << 63, max = min - 1;
	scanf("%d", &t);
	while (t--)
	{
		scanf("%lld%lld%lld", &a, &b, &c);
		if (a > 0 && b > max - a)ans = '>';
		else if (a < 0 && b < min - a)ans = '<';
		else if (a + b > c)ans = '>';
		else if (a + b < c)ans = '<';
		else ans = '=';
		printf("%c\n", ans);
	}
	return 0;
}

CSU 1459 Chess

题目:

Input

Output

Sample Input

3
E 2 E 3
F 1 E 8
A 3 A 3

Sample Output

Impossible
2 F 1 B 5 E 8
0 A 3

这个题现在可能有点问题,反正我没AC,网上的代码也都不能AC了

代码:

#include<iostream>
#include<stdio.h>
using namespace std;

int main()
{
	int t;
	char ch[10];
	char a, b, c, d;
	scanf("%d", &t);
	gets(ch);
	while (t--)
	{
		gets(ch);
		a = ch[0], b = ch[2], c = ch[4], d = ch[6];
		int xa = a - 'A', xb = b - '1', xc = c - 'A', xd = d - '1';
		if ((xa + xb + xc + xd) % 2)printf("Impossible\n");
		else if (xa == xc&&xb == xd)printf("0 %c %c\n", a, b);
		else if (xa + xb == xc + xd || xa - xb == xc - xd)printf("1 %c %c %c %c\n", a, b, c, d);
		else
		{
			int t = (xc + xd - xa - xb) / 2;
			if (xa + t >= 0 && xa + t <= 7 && xb + t >= 0 && xb + t <= 7)
				printf("2 %c %c %c %c %c %c\n", a, b, xa + t + 'A', xb + t + '1', c, d);
			else printf("2 %c %c %c %c %c %c\n", a, b, xc - t + 'A', xd - t + '1', c, d);
		}
	}
	return 0;
}

CSU 1468 Level Up

题目:

Description

  Alice loves playing a PC game recently. In this game, you can cost 1 coin to upgrade a role from level 1 to level 2, 2 coins to upgraded a role from level 2 to level 3, 3 coins to upgrade a role from level 3 to level 4, etc.
If Alice has N coins and the level of her role is L, how many levels can her role be upgraded at most? Assume the level of a role has no upper bound.

Input

  The first line contains the number of test cases T (1 ≤ T ≤ 200).
For each test case, there is only one line with two integers NL (1 ≤ NL ≤ 109) as defined above.

Output

  For each test case, output how many levels can her role be upgraded at most.

Sample Input

5
6 7
7 7
14 7
15 7
10000 3

Sample Output

0
1
1
2
138

代码:

#include<iostream>
using namespace std;
 
int main()
{
	int t, n, l;
	cin >> t;
	while (t--)
	{
		cin >> n >> l;
		int ans = 0;
		while (n >= l)n -= l, l++, ans++;
		cout << ans << endl;
	}
	return 0;
}

CSU 1524 Tone Number of MIDI

题目:

Description

Recently, we have made a little software called Query by Humming. One of the important thing is to transform the frequency of a sound to the tone number of MIDI. You can see the relations between them in the picture below:

                                        t = 12.0 * log2(f/440) + 69.0

Generally, we can transform the frequency of a sound to the tone of MIDI using the formula below:

Here f is the frequency of the sound and t is the tone of MIDI.
Then the integer nearest to t is the tone number. That is, the tone number is an integer x such that |x - t| is minimum. You can assume there is only one integer is nearest to t in this problem.

Input

The first line contains the number of test cases T (0 < T ≤ 200).
For each test case, there is only one line containing a real number f (82 < f < 1047) with at most 5 decimal places, giving the frequency of a sound.

Output

For each test case, output the tone number transformed.

Sample Input

5
440.0123
463.45678
840.003
859.99
700.5364

Sample Output

69
70
80
81
77

只有一个地方需要注意,int()这个函数,如果参数是负数,那么算出来的就和高斯函数不一样了,所以69只能放括号里面,不能放最外面。

代码:

#include<iostream>
#include<math.h>
using namespace std;

int main()
{
	int t;
	cin >> t;
	double f;
	while (t--)
	{
		cin >> f;
		cout << int(log2(f / 440) * 12 + 69.5) << endl;
	}
	return 0;
}

CSU 1586 分奖金

题目:

Description

校acm竞赛决定给参赛选手发奖金了!当然,只有做题数量最多的选手(可能有多个)能平分奖金。
今年奖金总共为C元,有n名参赛选手,已知他们的做题数量。
求做题最多的选手每人能获得多少奖金?

Input

第一行只有一个整数T(1<=T<=20),表示数据组数。
每组数据第一行有2个整数C, n(1<=C<=888, 1<=n<=100);
第二行有n个整数Pi(0<=Pi<=11), 表示每个人做题的数量。
输入保证至少有一个人做出题目。

Output

对于每一组数据输出一个整数,表示人均奖金(只保留整数部分)。

Sample Input

2
20 3
6 6 5
20 4
5 5 5 4

Sample Output

10
6

代码:

#include<iostream>
using namespace std;
 
int main()
{
	int t, c, n, num[100];
	cin >> t;
	while (t--)
	{
		cin >> c >> n;
		int max = 0, sum = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> num[i];
			if (max == num[i])sum++;
			if (max < num[i])max = num[i], sum = 1;
		}
		cout << c / sum << endl;
	}
	return 0;
}

CSU 1870 Legendary

题目:

Description

小GJ和小LMW都很喜欢LOL,他们喜欢互相吹牛,诸如“我昨天非常强,打了20把全部超神了”。但是聪明的SWB却每每都能看着数据识破他们吹牛的伎俩。已知LOL击杀、死亡和助攻可以以任意顺序发生,连续完成8次击杀即被视作超神,死亡会打断连续击杀,助攻没有影响。

Input

有T(T<=20)组数据。 每组给出N(N<=100)场比赛的数据。 每场比赛在一行里给出击杀数K死亡数D助攻数A。(K,D,A<=100)

Output

每组数据给出一定超神的数量和一定不超神的数量,格式如样例所示

Sample Input

2
3
8 0 0
0 8 0
0 0 8
2
20 0 5
8 1 0

Sample Output

1 2
1 0

Hint

注意有些数据并不能判断是一定超神或者一定不超神如8 1 0这组,因此不计入答案的两个类别。

代码:

#include<iostream>
using namespace std;
 
 
int main()
{
	int t, n, k, d, a, r1, r2;
	cin >> t;
	while (t--)
	{
		cin >> n;
		r1 = 0, r2 = 0;
		while (n--)
		{
			cin >> k >> d >> a;
			if (k >= d * 7 + 8)r1++;
			if (k < 8)r2++;
		}
		cout << r1 << " " << r2 << endl;
	}
	return 0;
}

CSU 1902 Happy Chinese Poker

题目:

Description

Happy Chinese Poker is a Chinese Poker game involved by three players. In each round, there is one player running for the landlord, while the other two players are farmers. The game always ends with the victory of the landlord or farmers, and the game uses happy beans for trading. The transaction of happy beans appears in the following cases:

  1. If a farmer wins in each round of game, then another farmer also wins. As a result, the landlord has to pay 1000 happy beans for his failure, and each farmer can get 500 happy beans.

  2. If the landlord wins in each round of game, both two farmers have to pay 500 happy beans respectively for their failure and the landlords win 1000 happy beans.

  3. Each player has to pay 100 happy beans for each round as a game fee.

The boy A is addicted to the game, Happy Chinese Poker, because he enjoys the pleasure of winning happy beans. Today he invited his friends B and C to play the game for N rounds. Assuming that all of them have enough happy beans and their wins or loses situation in each round is known, can you help A count today’s profit and loss situation of happy beans ( the difference value between the time A starts the game and finishes the game )

Input

There are multiply cases.(<=200) Each case’s first line contains an integer N represent play the game for N rounds .(N<=1000) In next N lines,every line contains three integers a,b,c(Respectively, said A, B, C game win or lose , 0 represent lose , 1represent win)

Output

For each case , output an integer represent today’s profit and loss situation of happy beans for A in one line.

Sample Input

3
0 1 1
0 0 1
1 1 0

1
1 0 0

Sample Output

-1300
900

代码:

#include<iostream>
using namespace std;
 
int main()
{
	int t,sum,a,b,c;
	while(cin>>t)
	{
		sum=-100*t;
		while(t--)
		{
			scanf("%d%d%d",&a,&b,&c);
			if(a+b+c==2)
			{
				if(a)sum+=500;
				else sum-=1000;
			}
			else
			{
				if(a)sum+=1000;
				else sum-=500;
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}

CSU 2062 Z‘s Array

题目:

Description

Z likes to play with array. One day his teacher gave him an array of n elements, and ask Z whether the array is a "m-peek" array.

A "m-peek" array is an array which has exactly m peek.

a term a[i] is called a peek if and only if a[i]>a[i − 1] and a[i]>a[i + 1]

If the array has exactly m peeks, the array is called a "m-peek" array.

Input

The first line is the case number T

each case has two integer n, m where n denotes the number of elements in the array

then followed by n 32-bit signed integers in the array.

1 ≤ T ≤ 100

1 ≤ n ≤ 1000000

0 ≤ m ≤ n

Output

For each case,

print a single word "Yes" without quotation when the array is a "m-peek" array.

print "No" without quotation otherwise.

Sample Input

2
5 1
5 7 11 2 1
4 1
4 5 5 6

Sample Output

Yes
No

代码:

#include<iostream>
using namespace std;
 
int main()
{
	int t, n, m, a, b, c;
	scanf("%d", &t);
	while (t--)
	{
		scanf("%d%d%d", &n, &m, &a);
		if (n == 1)
		{
			cout << "No\n";
			continue;
		}
		scanf("%d", &b);
		n -= 2;
		while (n--)
		{
			scanf("%d", &c);
			if (a<b && b>c)m--;
			a = b, b = c;
		}
		if (m)cout << "No\n";
		else cout << "Yes\n";
	}
	return 0;
}

HDU 1000 A + B Problem

Calculate A + B.

Input

Each line will contain two integers A and B. Process to end of file.

Output

For each case, output A + B in one line.

Sample

InputcopyOutputcopy
1 1
2
#include<iostream>
using namespace std;

int main()
{
	int a, b;
	while (cin >> a >> b)
		cout << a + b << endl;
	return 0;
}

HDU 1001 Sum Problem

Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).

In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.

Input

The input will consist of a series of integers n, one integer per line.

Output

For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.

Sample

InputcopyOutputcopy
1
100
1

5050
#include<iostream>
using namespace std;
 
int main()
{
    long long a;
    while (cin >> a)
        cout << a * (a+1) / 2 << endl;
    return 0;
}

HDU 1212 Big Number

 题目:

Description

As we know, Big Number is always troublesome. But it's really important in our ACM. And today, your task is to write a program to calculate A mod B. 

To make the problem easier, I promise that B will be smaller than 100000. 

Is it too hard? No, I work it out in 10 minutes, and my program contains less than 25 lines. 

Input

The input contains several test cases. Each test case consists of two positive integers A and B. The length of A will not exceed 1000, and B will be smaller than 100000. Process to the end of file. 

Output

For each test case, you have to ouput the result of A mod B. 

Sample Input

2 3
12 7
152455856554521 3250

Sample Output

2
5
1521

这个题目很简单,就是输入a,b 输出a%b
因为a很大,所以要用到Java的大数类
代码:

import java.util.*;
import java.math.BigInteger;
public class Main {

    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        String s;
        while(cin.hasNext())
        {
        	s=cin.next();
        	BigInteger a=new BigInteger(s);
        	s=cin.next();
        	BigInteger b=new BigInteger(s);      
            a=a.mod(b);
            System.out.println(a.toString());
        }        
    }
}

OpenJ_Bailian 1000 A+B Problem

 题目:

描述

Calculate a + b

输入

Two integer a,,b (0 ≤ a,b ≤ 10)

输出

Output a + b

样例输入

1 2

样例输出

3

代码:

s=input().split()
print(int(s[0])+int(s[1]))

如果是输入多组数据:(这个代码用于本题同样AC)

while True:
    try:
        s=input().split()
        print(int(s[0])+int(s[1]))
    except:
        break

OpenJ_Bailian 1019 Number Sequence

题目:

描述

A single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number groups S1S2...Sk. Each group Sk consists of a sequence of positive integer numbers ranging from 1 to k, written one after another.
For example, the first 80 digits of the sequence are as follows:
11212312341234512345612345671234567812345678912345678910123456789101112345678910

输入

The first line of the input file contains a single integer t (1 ≤ t ≤ 10), the number of test cases, followed by one line for each test case. The line for a test case contains the single integer i (1 ≤ i ≤ 2147483647)

输出

There should be one output line per test case containing the digit located in the position i.

样例输入

2
8
3

样例输出

2
2

代码:

n=int(input())
def sum(i):#从1到i一共多少个数字
    if(i<10):
        return i
    if(i<100):
        return i*2-9
    if(i<1000):
        return (i-99)*3+sum(99)
    if(i<10000):
        return (i-999)*4+sum(999)
    return (i-9999)*5+sum(9999)

while n:
    n=n-1
    k=int(input())
    i=1
    while sum(i)<k:   
        i=i+1
        k=k-sum(i-1)
    i=1
    while sum(i)<k:
        i=i+1
    k=k-sum(i-1)
    #i的第k位
    print(str(i)[k-1])

这个代码十分有意思,第-10行到第-7行 和 第-6行到第-3行 只有缩进不一样

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值