这学期会不会好好上ACM呢

本文最后更新于:2021年10月17日 晚上

新学期开始了,又报了 ACM,这次会不会中途跑路呢?坚持更新!

WEEK 1

1001

Problem Description

1
2
3
Your task is to Calculate a + b.
Too easy?! Of course! I specially designed the problem for acm beginners.
You must have found that some problems have the same titles with this one, yes, all these problems were designed for the same aim.

Input

1
The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.

Output

1
For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.

Sample Input

1
2
1 5
10 20

Sample Output

1
2
6
30

MyResult

1
2
3
4
5
6
7
8
9
10
11
12
//
// Created by Wu Junyi on 2021/9/28.
//
#include "stdio.h"

int main(void) {
int a, b;
while (scanf("%d %d", &a, &b) !=EOF) {
printf("%d\n", a+ b);
}
return 0;
}

1002

Problem Description

1
Your task is to Calculate a + b.

Input

1
Input contains an integer N in the first line, and then N lines follow. Each line consists of a pair of integers a and b, separated by a space, one pair of integers per line.

Output

1
For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.

Sample Input

1
2
3
2
1 5
10 20

Sample Output

1
2
6
30

MyResult

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//
// Created by Wu Junyi on 2021/9/28.
//

#include "stdio.h"

int main(void) {
int a, b, n;
scanf("%d", &n);
while (n--) {
scanf("%d %d", &a, &b);
printf("%d\n", a + b);
}
return 0;
}

1003

Problem Description

1
Your task is to Calculate a + b.

Input

1
Input contains multiple test cases. Each test case contains a pair of integers a and b, one pair of integers per line. A test case containing 0 0 terminates the input and this test case is not to be processed.

Output

1
For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.

Sample Input

1
2
3
1 5
10 20
0 0

Sample Output

1
2
6
30

MyResult

1
2
3
4
5
6
7
8
9
10
11
12
13
//
// Created by Wu Junyi on 2021/9/28.
//

#include "stdio.h"

int main(void) {
int a, b;
while (scanf("%d %d", &a, &b) && (a || b)) {
printf("%d\n", a + b);
}
return 0;
}

1004

Problem Description

1
Your task is to Calculate the sum of some integers.

Input

1
Input contains multiple test cases. Each test case contains a integer N, and then N integers follow in the same line. A test case starting with 0 terminates the input and this test case is not to be processed.

Output

1
For each group of input integers you should output their sum in one line, and with one line of output for each line in input.

Sample Input

1
2
3
4 1 2 3 4
5 1 2 3 4 5
0

Sample Output

1
2
10
15

MyResult

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//
// Created by Wu Junyi on 2021/9/28.
//


#include "stdio.h"

int main(void) {
int n, a, b;
while (scanf("%d", &n) && (n)) {
a = 0;
while (n--) {
scanf("%d", &b);
a += b;
}
printf("%d\n", a);
}
return 0;
}

1005

Problem Description

1
Your task is to calculate the sum of some integers.

Input

1
Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.

Output

1
For each group of input integers you should output their sum in one line, and with one line of output for each line in input.

Sample Input

1
2
3
2
4 1 2 3 4
5 1 2 3 4 5

Sample Output

1
2
10
15

MyResult

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//
// Created by Wu Junyi on 2021/9/28.
//

#include "stdio.h"

int main(void) {
int m, n, a, b;
scanf("%d", &m);

while (m--) {
scanf("%d", &n);
a = 0;
while (n--) {
scanf("%d", &b);
a += b;
}
printf("%d\n", a);
}
return 0;
}

1006

Problem Description

1
Your task is to calculate the sum of some integers.

Input

1
Input contains multiple test cases, and one case one line. Each case starts with an integer N, and then N integers follow in the same line.

Output

1
For each test case you should output the sum of N integers in one line, and with one line of output for each line in input.

Sample Input

1
2
4 1 2 3 4
5 1 2 3 4 5

Sample Output

1
2
10
15

MyResult

1
2
3
4
5
6
7
8
9
10
11
12
13
//
// Created by Wu Junyi on 2021/9/28.
//

#include "stdio.h"

int main(void) {
int a, b;
while (scanf("%d%d", &a, &b) != EOF) {
printf("%d\n\n", a + b);
}
return 0;
}

1007

Problem Description

1
Your task is to Calculate a + b.

Input

1
The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.

Output

1
For each pair of input integers a and b you should output the sum of a and b, and followed by a blank line.

Sample Input

1
2
1 5
10 20

Sample Output

1
2
3
4
6

30

MyResult

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//
// Created by Wu Junyi on 2021/9/28.
//

#include "stdio.h"

int main(void) {
int m, n, a, b;
scanf("%d", &m);

while (m--) {
scanf("%d", &n);
a = 0;
while (n--) {
scanf("%d", &b);
a += b;
}
if (m) printf("%d\n\n", a);
else printf("%d\n", a);
}
return 0;
}

1008

Problem Description

1
Your task is to calculate the sum of some integers.

Input

1
Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.

Output

1
For each group of input integers you should output their sum in one line, and you must note that there is a blank line between outputs.

Sample Input

1
2
3
4
3
4 1 2 3 4
5 1 2 3 4 5
3 1 2 3

Sample Output

1
2
3
4
5
10

15

6

MyResult

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//
// Created by Wu Junyi on 2021/9/29.
//


#include "stdio.h"

int main(void) {
int n;
while (scanf("%d", &n) != EOF) {
int sum = 0;
for (int i = 1; i <= n; i++) {
sum = sum + i;
}
printf("%d\n\n", sum);
}
return 0;
}

1009

Problem Description

1
2
Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).
In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.

Input

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

Output

1
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 Input

1
2
1
100

Sample Output

1
2
3
4
1

5050

MyResult

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//
// Created by Wu Junyi on 2021/9/29.
//

#include "stdio.h"
#include "math.h"

int main(void) {
float a, b, c, d;
while (scanf("%f%f%f%f", &a, &b, &c, &d) != EOF) {
float i= sqrtf((a-c) * (a-c) + (b-d) * (b-d));
printf("%.2f\n", i);
}
return 0;
}

1010

Problem Description

1
输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离。

Input

1
输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔开。

Output

1
对于每组输入数据,输出一行,结果保留两位小数。

Sample Input

1
2
0 0 0 1
0 1 1 0

Sample Output

1
2
1.00
1.41

MyResult

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//
// Created by Wu Junyi on 2021/9/29.
//

#include "stdio.h"

int main(void){
int s,n;

//检测
while ((n=scanf("%d",&s))!=EOF){
if (s>=0&&s<=59){
printf("%s\n","E");
} else if(s>=60&&s<=69){
printf("%s\n","D");
} else if(s>=70&&s<=79){
printf("%s\n","C");
} else if(s>=80&&s<=89){
printf("%s\n","B");
}else if(s>=90&&s<=100){
printf("%s\n","A");
} else{
puts("Score is error!");
if(n==0){
getchar();
}
}
s=-1;
}
return 0;
}

这里要考虑如果输入不是数字该如何处理

1011

Problem Description

1
2
3
4
5
6
输入一个百分制的成绩t,将其转换成对应的等级,具体转换规则如下:
90~100为A;
80~89为B;
70~79为C;
60~69为D;
0~59为E;

Input

1
输入数据有多组,每组占一行,由一个整数组成。

Output

1
对于每组输入数据,输出一行。如果输入数据不在0~100范围内,请输出一行:“Score is error!”。

Sample Input

1
2
3
4
56
67
100
123

Sample Output

1
2
3
4
E
D
A
Score is error!

MyResult

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//
// Created by Wu Junyi on 2021/9/29.
//

#include "stdio.h"

int main(void) {
int n, a, b;
while (scanf("%d", &n) != EOF) {
a = 1;
while (n--) {
scanf("%d", &b);
if (b % 2) {
a *= b;
}
}
printf("%d\n", a);
}
return 0;
}

WEEK 2

1001

Problem Description

1
2
3
4
Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).

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

Input

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

Output

1
2
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 Input

1
2
3
1
100

Sample Output

1
2
3
4
5
1

5050


MyResult

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//
// Created by Wu Junyi on 2021/9/30.
//

#include "stdio.h"

int main(void) {
long n;
while (scanf("%ld", &n) != EOF) {
int sum = 0;
for (int i = 1; i <= n; i++) {
sum = sum + i;
}
printf("%d\n\n", sum);
}
return 0;
}

1002

Problem Description

1
2
3
4
The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.

For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.

Input

1
2
There are multiple test cases. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100. A test case with N = 0 denotes the end of input. This test case is not to be processed.

Output

1
2
Print the total time on a single line for each test case.

Sample Input

1
2
3
4
1 2
3 2 3 1
0

Sample Output

1
2
3
17
41

MyResult

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//
// Created by Wu Junyi on 2021/9/30.
//

#include "stdio.h"

int main(void){
int n;
while (scanf("%d",&n)&&n){
int i,j,time;
j=0;
time=n*5;
while (n--){
scanf("%d",&i);
if (i>j)
time+=(i-j)*6;
else
time+=(j-i)*4;
j=i;
}
printf("%d\n",time);
}
return 0;
}


1003

Problem Description

1
2
3
The least common multiple (LCM) of a set of positive integers is the smallest positive integer which is divisible by all the numbers in the set. For example, the LCM of 5, 7 and 15 is 105.


Input

1
2
Input will consist of multiple problem instances. The first line of the input will contain a single integer indicating the number of problem instances. Each instance will consist of a single line of the form m n1 n2 n3 ... nm where m is the number of integers in the set and n1 ... nm are the integers. All integers will be positive and lie within the range of a 32-bit integer.

Output

1
2
For each problem instance, output a single line containing the corresponding LCM. All results will lie in the range of a 32-bit integer.

Sample Input

1
2
3
4
2
3 5 7 15
6 4 10296 936 1287 792 1

Sample Output

1
2
3
105
10296

MyResult

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//
// Created by Wu Junyi on 2021/9/30.
//

#include "stdio.h"

int gcd(int a, int b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}

int lcm(int a, int b) {
return a / gcd(a, b) * b;
}

int main(void) {
int n;
scanf("%d", &n);
while (n--) {
int j, k = 1, e;
scanf("%d", &j);
while (j--) {
scanf("%d", &e);
k = lcm(k, e);
}
printf("%d\n", k);
}
return 0;
}

1004

Problem Description

1
2
3
4
5
6
A number sequence is defined as follows:

f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.

Given A, B, and n, you are to calculate the value of f(n).

Input

1
The input consists of multiple test cases. Each test case contains 3 integers A, B and n on a single line (1 <= A, B <= 1000, 1 <= n <= 100,000,000). Three zeros signal the end of input and this test case is not to be processed.

Output

1
2
For each test case, print the value of f(n) on a single line.

Sample Input

1
2
3
4
1 1 3
1 2 10
0 0 0

Sample Output

1
2
3
2
5

MyResult

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//
// Created by Wu Junyi on 2021/9/30.
//

#include "stdio.h"

int main(void) {
int A, B, n;
// for (int i = 3 ; i <100 ; ++i) {
// f[i] = (f[i-1] + f[i-2])%7;
// printf("%d: %d\n",i,f[i]);
// }

while (scanf("%d%d%d", &A, &B, &n) && (A || B || n)) {
int f[50] = {0, 1, 1};
for (int i = 3; i < 50; ++i) {
f[i] = (A * f[i - 1] + B * f[i - 2]) % 7;
}

printf("%d\n", n % 48 == 0 ? f[48] : f[n % 48]);
}
return 0;
}

1005

Problem Description

1
2
There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n&amp;gt;=2).

Input

1
2
Input consists of a sequence of lines, each containing an integer n. (n < 1,000,000).

Output

1
2
3
4
Print the word &quot;yes&quot; if 3 divide evenly into F(n).

Print the word &quot;no&quot; if not.

Sample Input

1
2
3
4
5
6
7
0
1
2
3
4
5

Sample Output

1
2
3
4
5
6
7
no
no
yes
no
no
no

MyResult

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//
// Created by Wu Junyi on 2021/10/9.
//

#include "stdio.h"

int main(void) {
// int n, ta = 7, tb = 11;
// while (scanf("%d", &n) != EOF) {
// if (n < 2) {
// printf("no\n");
// continue;
// }
// int res;
// for (int i = 2; i <= n; ++i) {
// res = ta + tb;
// ta = tb;
// tb = res;
// printf("%d\n", res);
// }
// printf("%d\n", res);
// if (!(res % 3)) printf("yes\n");
// else printf("no\n");
// }
int n;
while(scanf("%d", &n) != EOF)
{
if(n % 8 == 2 || n % 8 == 6)
printf("yes\n");
else
printf("no\n");
}
return 0;
}

1006

Problem Description

1
2
HOHO,终于从Speakless手上赢走了所有的糖果,是Gardon吃糖果时有个特殊的癖好,就是不喜欢将一样的糖果放在一起吃,喜欢先吃一种,下一次吃另一种,这样;可是Gardon不知道是否存在一种吃糖果的顺序使得他能把所有糖果都吃完?请你写个程序帮忙计算一下。

Input

1
2
第一行有一个整数T,接下来T组数据,每组数据占2行,第一行是一个整数N0<N<=1000000),第二行是N个数,表示N种糖果的数目Mi(0<Mi<=1000000)。

Output

1
2
对于每组数据,输出一行,包含一个&quot;Yes&quot;或者&quot;No&quot;

Sample Input

1
2
3
4
5
6
2
3
4 1 1
5
5 4 3 2 1

Sample Output

1
2
3
4
5
6
No
Yes

# HintHint</div>
Please use function scanf

MyResult

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//
// Created by Wu Junyi on 2021/10/10.
//

#include "stdio.h"

int main(void) {
int i, j, a = 0, t;
scanf("%d", &i);
while (i--) {
__int64 n = 0;
scanf("%d", &j);
while (j--) {
scanf("%d", &t);
n += t;
if (t > a)a = t;
}
if (a - (n - a) <= 1)printf("Yes\n");
else printf("No\n");
a = 0;
}
return 0;
}

1007

Problem Description

1
2
3
A^B的最后三位数表示的整数。
说明:A^B的含义是“A的B次方”

Input

1
输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1<=A,B<=10000),如果A=0, B=0,则表示输入数据的结束,不做处理。

Output

1
2
对于每个测试实例,请输出A^B的最后三位表示的整数,每个输出占一行。

Sample Input

1
2
3
4
5
2 3
12 6
6789 10000
0 0

Sample Output

1
2
3
4
8
984
1

MyResult

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//
// Created by Wu Junyi on 2021/10/10.
//

#include "stdio.h"

int main() {
int a, b;
while (scanf("%d %d", &a, &b) && (a || b)) {
int i, s = a;
for (i = 0; i < b - 1; i++)
s = s * a % 1000;
printf("%d\n", s);
}
return 0;
}

1008

Problem Description

1
2
Given a positive integer N, you should output the most right digit of N^N.

Input

1
2
3
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains a single positive integer N(1<=N<=1,000,000,000).

Output

1
2
For each test case, you should output the rightmost digit of N^N.

Sample Input

1
2
3
4
2
3
4

Sample Output

1
2
3
4
5
6
7
7
6

# Hint
In the first case, 3 * 3 * 3 = 27, so the rightmost digit is 7.
In the second case, 4 * 4 * 4 * 4 = 256, so the rightmost digit is 6.
</div>

MyResult

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//
// Created by Wu Junyi on 2021/10/10.
//

#include "stdio.h"

int my_power(int m, int n); // 求m的n次方的尾数
int main(void) {
int cases, n;
scanf("%d", &cases);
while (cases--) {
scanf("%d", &n);
printf("%d\n", my_power(n, n));
}

return 0;
}

int my_power(int m, int n) {
m = m % 10;
if (n == 1)
return m;
if (n % 2 == 0)
return (my_power(m * m, n / 2)) % 10;
else
return (my_power(m * m, n / 2) * m) % 10;
}

1009

Problem Description

1
给定两个正整数,计算这两个数的最小公倍数。

Input

1
输入包含多组测试数据,每组只有一行,包括两个不大于1000的正整数.

Output

1
2
对于每个测试用例,给出这两个数的最小公倍数,每个实例输出一行。

Sample Input

1
2
10 14

Sample Output

1
2
70

MyResult

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//
// Created by Wu Junyi on 2021/9/30.
//

#include "stdio.h"

int gcd(int a, int b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}

int lcm(int a, int b) {
return a / gcd(a, b) * b;
}

int main(void) {
int a, b;
while (scanf("%d%d", &a, &b) != EOF) {
printf("%d\n", lcm(a, b));
}
return 0;
}

1010

Problem Description

1
2
数列的定义如下:
数列的第一项为n,以后各项为前一项的平方根,求数列的前m项的和。

Input

1
输入数据有多组,每组占一行,由两个整数nn<10000)和m(m<1000)组成,n和m的含义如前所述。

Output

1
对于每组输入数据,输出该数列的和,每个测试实例占一行,要求精度保留2位小数。

Sample Input

1
2
81 4
2 2

Sample Output

1
2
94.73
3.41

MyResult

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//
// Created by Wu Junyi on 2021/10/7.
//
#include "stdio.h"
#include "math.h"

int main(void){
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
double sum=0,a=(double)n;
for(int i=0;i<m;i++) sum+=a,a=sqrt(a);
printf("%.2lf\n",sum);
}
return 0;
}


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!