2021灵动冬令营Day1

A - Specialized Four-Digit Numbers

Description

Find and list all four-digit numbers in decimal notation that have the property that the sum of its four digits equals the sum of its digits when represented in hexadecimal (base 16) notation and also equals the sum of its digits when represented in duodecimal (base 12) notation.
For example, the number 2991 has the sum of (decimal) digits 2 + 9 + 9 + 1 = 21 2+9+9+1 = 21 2+9+9+1=21. Since 2991 = 1 ∗ 1728 + 8 ∗ 144 + 9 ∗ 12 + 3 2991 = 1 * 1728 + 8*144 + 9*12 + 3 2991=11728+8144+912+3, its duodecimal representation is 189 3 12 1893_{12} 189312, and these digits also sum up to 21. But in hexadecimal 2991 is B A F 16 BAF_{16} BAF16, and 11 + 10 + 15 = 36 11+10+15 = 36 11+10+15=36, so 2991 2991 2991 should be rejected by your program.
The next number ( 2992 ) (2992) (2992), however, has digits that sum to 22 22 22 in all three representations (including B B 0 16 BB0_{16} BB016), so 2992 2992 2992 should be on the listed output. (We don’t want decimal numbers with fewer than four digits – excluding leading zeroes – so that 2992 2992 2992 is the first correct answer.)

Input

There is no input for this problem

Output

Your output is to be 2992 2992 2992 and all larger four-digit numbers that satisfy the requirements (in strictly increasing order), each on a separate line with no leading or trailing blanks, ending with a new-line character. There are to be no blank lines in the output. The first few lines of the output are shown below.

Sample Input
There is no input for this problem
Sample Output
2992
2993
2994
2995
2996
2997
2998
2999
...
解题思路

直接判断从2992开始的所有四位数,判断是不是这三个进制的每位和是否相同即可

AC代码
#include<cstdio>

using namespace std;
int a[5], cnt;

int cal(int k, int x) {
	cnt = 0;
	for(int i = 0; i < 5; i++) a[i] = 0;
	while(x) {
		a[cnt++] = x % k;
		x /= k;
	}
	int ans = 0;
	for(int i = 0; i < 4; i++) {
		ans += a[i];
	}
	return ans;
}

int main() {
	for(int i = 2992; i <= 9999; i++) {
		if(cal(16, i) == cal(12, i) && cal(10, i) == cal(12, i)) {
			printf("%d\n", i);
		}
	}
	return 0;
}

B - Pig-Latin

Description

You have decided that PGP encryptation is not strong enough for your email. You have decided to supplement it by first converting your clear text letter into Pig Latin before encrypting it with PGP.

Input and Output

You are to write a program that will take in an arbitrary number of lines of text and output it in Pig Latin. Each line of text will contain one or more words. A “word” is defined as a consecutive sequence of letters (upper and/or lower case). Words should be converted to Pig Latin according to the following rules (non-words should be output exactly as they appear in the input):

  1. Words that begin with a vowel (a, e, i, o, or u, and the capital versions of these) should just have the string “ay” (not including the quotes) appended to it. For example, “apple” becomes “appleay”.
  2. Words that begin with a consonant (any letter than is not A, a, E, e, I, i, O, o, U or u) should have the first consonant removed and appended to the end of the word, and then appending “ay” as well. For example, “hello” becomes “ellohay”.
  3. Do not change the case of any letter.
Sample Input
This is the input.
Sample Output
hisTay isay hetay inputay.
解题思路

这题就是判断是不是单词,如果不是字母先把前面的字母判断下输出然后再将当前字符输出即可

AC代码
#include<cstdio>
#include<cstring>
using namespace std;
const int N = 1e6 + 10;
char s[N], cnt;

int main() {
	char c;
	while(~scanf("%c", &c)) {
		if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
			s[cnt++] = c;
		} else {
			if(cnt == 0) {
				printf("%c", c);
				continue;
			}
			if(s[0] == 'a' || s[0] == 'e' || s[0] == 'i' || s[0] == 'o' || s[0] == 'u'
				|| s[0] == 'A' || s[0] == 'E' || s[0] == 'I' || s[0] == 'O' || s[0] == 'U') {
				for(int i = 0; i < cnt; i++) {
					printf("%c", s[i]);
				}
				printf("ay%c", c);
			} else {
				for(int i = 1; i < cnt; i++) {
					printf("%c", s[i]);
				}
				printf("%cay%c", s[0], c);
			}
			cnt = 0;
		}
	}
	return 0;
}

C - Tic Tac Toe

Description

Tic Tac Toe is a child’s game played on a 3 by 3 grid. One player, X, starts by placing an X at an unoccupied grid position. Then the other player, O, places an O at an unoccupied grid position. Play alternates between X and O until the grid is filled or one player’s symbols occupy an entire line (vertical, horizontal, or diagonal) in the grid.
We will denote the initial empty Tic Tac Toe grid with nine dots. Whenever X or O plays we fill in an X or an O in the appropriate position. The example below illustrates each grid configuration from the beginning to the end of a game in which X wins.

...  X..  X.O  X.O  X.O  X.O  X.O  X.O
...  ...  ...  ...  .O.  .O.  OO.  OO.
...  ...  ...  ..X  ..X  X.X  X.X  XXX

Your job is to read a grid and to determine whether or not it could possibly be part of a valid Tic Tac Toe game. That is, is there a series of plays that can yield this grid somewhere between the start and end of the game?

Input

The first line of input contains N, the number of test cases. 4N-1 lines follow, specifying N grid configurations separated by empty lines.

Output

For each case print “yes” or “no” on a line by itself, indicating whether or not the configuration could be part of a Tic Tac Toe game.

Sample Input
2
X.O
OO.
XXX

O.X
XX.
OOO
Sample Output
yes
no
解题思路

首先判断 x 和 o棋子的数目是不是相等的或者前者比后者只多1个,如果不满足就直接输出no

如果相等:就去看x 的棋子是否存在胜利的情况,如果存在,输出no

多1:就去看 o 的棋子是否存在胜利的情况,如果存在,输出no

AC代码
#include<cstdio>
#include<cstring>

using namespace std;
char s[5][5];

bool judge() {
	int sum1 = 0, sum2 = 0;
	for(int i = 0; i < 3; i++) {
		for(int j = 0; j < 3; j++) {
			if(s[i][j] == 'X') sum1++;
			else if(s[i][j] == 'O') sum2++;
		}
	}
	if(sum1 < sum2 || sum1 - sum2 > 1) return false;
	if(sum1 == sum2) {
		for(int i = 0; i < 3; i++) {
			int sum = 0;
			for(int j = 0; j < 3; j++) {
				if(s[i][j] == 'X') sum++;
				else break;
			}
			if(sum == 3) return false;
			sum = 0;
			for(int j = 0; j < 3; j++) {
				if(s[j][i] == 'X') sum++;
				else break;
			}
			if(sum == 3) return false;
		}
		if(s[0][0] == 'X' && s[1][1] == 'X' && s[2][2] == 'X') return false;
		if(s[2][0] == 'X' && s[1][1] == 'X' && s[0][2] == 'X') return false;
	} else {
		for(int i = 0; i < 3; i++) {
			int sum = 0;
			for(int j = 0; j < 3; j++) {
				if(s[i][j] == 'O') sum++;
				else break;
			}
			if(sum == 3) return false;
			sum = 0;
			for(int j = 0; j < 3; j++) {
				if(s[j][i] == 'O') sum++;
				else break;
			}
			if(sum == 3) return false;
		}
		if(s[0][0] == 'O' && s[1][1] == 'O' && s[2][2] == 'O') return false;
		if(s[2][0] == 'O' && s[1][1] == 'O' && s[0][2] == 'O') return false;
	}
	return true;
}

int main() {
	int t;
	scanf("%d", &t);
	while(t--) {
		for(int i = 0; i < 3; i++) {
			scanf("%s", s[i]);
		}
		if(judge()) printf("yes\n");
		else printf("no\n");
	}
	return 0;
}

D - Factorial! You Must be Kidding!!!

Description

Arif has bought a super computer from Bongobazar. Bongobazar is a place in Dhaka where second hand goods are found in plenty. So the super computer bought by him is also second hand and has some bugs. One of the bugs is that the range of unsigned long integer of this computer for C/C++ compiler has changed. Now its new lower limit is 10000 and upper limit is 6227020800. Arif writes a program in C/C++ which determines the factorial of an integer. Factorial of an integer is defined recursively as:
f a c t o r i a l ( 0 ) = 1 f a c t o r i a l ( n ) = n ∗ f a c t o r i a l ( n − 1 ) factorial(0) = 1 \\ factorial(n) = n * factorial(n - 1) factorial(0)=1factorial(n)=nfactorial(n1)
Of course one can manipulate these expressions. For example, it can be written as
f a c t o r i a l ( n ) = n ∗ f a c t o r i a l ( n − 1 ) ∗ f a c t o r i a l ( n − 2 ) factorial(n) = n * factorial(n - 1) * factorial(n - 2) factorial(n)=nfactorial(n1)factorial(n2)
This definition can also be converted to an iterative one. But Arif knows that his program will not behave rightly in the super computer. You are to write program which will simulate that changed behavior in a Normal Computer.

Input

The input file contains several lines of input. Each line contains a single integer n. No integer has more than six digits. Input is terminated by end of file.

Output

For each line of input you should output a single line. This line will contain a single integer n! if the value of n! fits within the unsigned long integer of Arif’s computer. Otherwise the line will contain one of the following two words Overflow! (When n ! > 6227020800 n! > 6227020800 n!>6227020800) Underflow! (When n ! < 10000 n! < 10000 n!<10000)

Sample Input
2
10
100
Sample Output
Underflow!
3628800
Overflow!
解题思路

打表可以发现满足条件直接输出结果的的只有当 8 ≤ n ≤ 13 8 \leq n \leq 13 8n13 时,当 0 ≤ n ≤ 7 0 \leq n \leq 7 0n7 直接输出下溢,当 n ≥ 14 n \geq 14 n14 时,直接输出上溢, 倒过来推一下可以发现当负数为奇数的时候是无穷大,偶数为无穷小,输出对应的上溢,下溢即可

AC代码
#include<cstdio>
#include<cstring>

using namespace std;
typedef long long ll;
ll a[15];

int main() {
	a[0] = 1;
	for(int i = 1; i <= 13; i++) {
		a[i] = i * a[i - 1];
	}
	int n;
	while(~scanf("%d", &n)) {
		if(n >= 0) {
			if(n <= 7) printf("Underflow!\n");
			else if(n <= 13) printf("%lld\n", a[n]);
			else printf("Overflow!\n");
		} else {
			n *= -1;
			if(n % 2) printf("Overflow!\n");
			else printf("Underflow!\n");
		}
	}
	return 0;
}

E - Function Run Fun

Description

We all love recursion! Don’t we?

Consider a three-parameter recursive function w(a, b, c):

if a ≤ 0     o r     b ≤ 0     o r     c ≤ 0 a \leq 0 \ \ \ or \ \ \ b \leq 0 \ \ \ or\ \ \ c \leq 0 a0   or   b0   or   c0, then w(a, b, c) returns: 1

if a > 20 o r b > 20 o r c > 20 a > 20 or b > 20 or c > 20 a>20orb>20orc>20, then w(a, b, c) returns: w(20, 20, 20)

if a < b a < b a<b and b < c b < c b<c, then w(a, b, c) returns:

w(a, b, c-1) + w(a, b-1, c-1) - w(a, b-1, c)

otherwise it returns:
w(a-1, b, c) + w(a-1, b-1, c) + w(a-1, b, c-1) - w(a-1, b-1, c-1)

This is an easy function to implement. The problem is, if implemented directly, for moderate values of a, b and c (for example, a = 15 , b = 15 , c = 15 a = 15, b = 15, c = 15 a=15,b=15,c=15), the program takes hours to run because of the massive recursion.

Input

The input for your program will be a series of integer triples, one per line, until the end-of-file flag of − 1 − 1 − 1 -1 -1 -1 111. Using the above technique, you are to calculate w(a, b, c) efficiently and print the result.

Output

Print the value for w(a,b,c) for each triple.

Sample Input
1 1 1
2 2 2
10 4 6
50 50 50
-1 7 18
-1 -1 -1
Sample Output
w(1, 1, 1) = 2
w(2, 2, 2) = 4
w(10, 4, 6) = 523
w(50, 50, 50) = 1048576
w(-1, 7, 18) = 1
解题思路

直接用一个三维的标记数组记录每一次w(a,b,c)第一次出现的值,如果再次需要用到,直接return这个值,降低递归的时间复杂度,然后对应的判断去递归即可,需要注意的是由于a,b,c可能小于0,因此

a ≤ 0 a \le 0 a0 || b ≤ 0 b \le 0 b0 || c ≤ 0 c \le 0 c0 要放在判断标记数组是否标记过前面,因为数组下标不能是负值

AC代码
#include<cstdio>
#include<cstring>
using namespace std;
const int N = 222;
int f[N][N][N];

int w(int a, int b, int c) {
	if(a <= 0 || b <= 0 || c <= 0) return 1;
	if(f[a][b][c]) return f[a][b][c];
	if(a > 20 || b > 20 || c > 20) return f[a][b][c] = w(20, 20, 20);
	if(a < b && b < c) {
		return f[a][b][c] = w(a, b, c - 1) + w(a, b - 1, c - 1) - w(a, b - 1, c);
	} else {
		return f[a][b][c] = w(a-1, b, c) + w(a-1, b-1, c) + w(a-1, b, c-1) - w(a-1, b-1, c-1);
	} 
} 

int main() {
	int a, b, c;
	while(~scanf("%d%d%d", &a, &b, &c)) {
		if(a == -1 && b == -1 && c == -1) break;
		printf("w(%d, %d, %d) = %d\n", a, b, c, w(a, b, c));
	}
	return 0;
}

F - Simple Addition

Description

Lets define a simple recursive function F ( n ) F(n) F(n), where
KaTeX parse error: Expected '}', got '&' at position 66: …%10 > 0 )} \\ 0&̲ \text{if n = 0…
Lets define another function S ( p , q ) S(p, q) S(p,q),
S ( p , q ) = ∑ i = p q F ( i ) S(p,q) = \sum_{i=p}^qF(i) S(p,q)=i=pqF(i)
In this problem you have to Calculate S ( p , q ) S(p, q) S(p,q) on given value of p p p and q q q.

Input

The input file contains several lines of inputs. Each line contains two non negative integers p and q ( p ≤ q ) (p ≤ q) (pq) separated by a single space. p and q will fit in 32 32 32 bit signed integer. In put is terminated by a line which contains two negative integers. This line should not be processed.

Output

For each set of input print a single line of the value of S ( p , q ) S(p, q) S(p,q)

Sample Input
1 10
10 20
30 40
-1 -1
Sample Output
46
48
52
解题思路

这题可以发现一个规律,如果是从 1 − n 1 - n 1n 求值,那么除了最后一位是 0 0 0 的,其他的答案就是

45 ∗ ( n / 10 ) + ( 1 + ( n % 10 ) ∗ ( n % 10 ) / 2 ) 45 * (n / 10) + (1 + (n \% 10) * (n \% 10) / 2) 45(n/10)+(1+(n%10)(n%10)/2) , 然后你会发现,如果让 n / = 10 n /= 10 n/=10 ,那么剩下的那个 n n n 就可以求出来之前没有求的那些最后一位带0的数,依次类推,每次都让 n / = 10 n /= 10 n/=10 直到为 0 0 0 为止,去计算答案即可

AC代码
#include<iostream>
#include<cstring>

using namespace std;
typedef long long ll;

ll sum(ll n) {
	ll ans = 0;
	while(n) {
		ll x = n % 10;
		n /= 10;
		ans += (1 + x) * x / 2 + n * 45;
	}
	return ans;
}

int main() {
	ll p, q;
	while(~scanf("%lld%lld", &p, &q)) {
		if(p == -1 && q == -1) break;
		printf("%lld\n", sum(q) - sum(p - 1));
	}
	return 0;
}

G - A Contesting Decision

Description

Judging a programming contest is hard work, with demanding contestants, tedious decisions,and monotonous work. Not to mention the nutritional problems of spending 12 hours with only donuts, pizza, and soda for food. Still, it can be a lot of fun.
Software that automates the judging process is a great help, but the notorious unreliability of some contest software makes people wish that something better were available. You are part of a group trying to develop better, open source, contest management software, based on the principle of modular design.
Your component is to be used for calculating the scores of programming contest teams and determining a winner. You will be given the results from several teams and must determine the winner.
Scoring
There are two components to a team’s score. The first is the number of problems solved. The second is penalty points, which reflects the amount of time and incorrect submissions made before the problem is solved. For each problem solved correctly, penalty points are charged equal to the time at which the problem was solved plus 20 minutes for each incorrect submission. No penalty points are added for problems that are never solved.
So if a team solved problem one on their second submission at twenty minutes, they are charged 40 penalty points. If they submit problem 2 three times, but do not solve it, they are charged no penalty points. If they submit problem 3 once and solve it at 120 minutes, they are charged 120 penalty points. Their total score is two problems solved with 160 penalty points.
The winner is the team that solves the most problems. If teams tie for solving the most problems,then the winner is the team with the fewest penalty points.

Input

For the programming contest your program is judging, there are four problems. You are guaranteed that the input will not result in a tie between teams after counting penalty points.
Line 1 < nTeams >
Line 2 - n+1 < Name > < p1Sub > < p1Time > < p2Sub > < p2Time > … < p4Time >

The first element on the line is the team name, which contains no whitespace.Following that, for each of the four problems, is the number of times the team submitted a run for that problem and the time at which it was solved correctly (both integers). If a team did not solve a problem, the time will be zero. The number of submissions will be at least one if the problem was solved.

Output

The output consists of a single line listing the name of the team that won, the number of problems they solved, and their penalty points.

Sample Input
4
Stars 2 20 5 0 4 190 3 220
Rockets 5 180 1 0 2 0 3 100
Penguins 1 15 3 120 1 300 4 0
Marsupials 9 0 3 100 2 220 3 80
Sample Output
Penguins 3 475
解题思路

这题直接输入时计算每个人解题的题数和罚时,然后和记录的最大值的情况进行判断,看看是否更新信息即可

AC代码
#include<iostream>
#include<cstring>
using namespace std;
const int N = 1e5 + 10;

struct list {
	string name;
	int a[4];
	int b[4];
}list;

string name;
int maxx, tot;

int main() {
	int n;
	cin >> n;
	while(n--) {
		cin >> list.name;
		int sum = 0;
		int tmp = 0;
		for(int i = 0; i < 4; i++) {
			cin >> list.a[i] >> list.b[i];
			if(list.b[i] == 0) continue;
			tmp++;
			sum += (list.a[i] - 1) * 20 + list.b[i];
		}
		if(maxx < tmp || (maxx == tmp && tot > sum)) {
			name = list.name;
			maxx = tmp;
			tot = sum;
		}
	}
	cout << name << " " << maxx << " " << tot << endl;
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值