2020 Ranked Topics

L1-1 Code on nonsense (5 points)

#include <bits/stdc++.h>
using namespace std;

int main(void)
{
    
    
	puts("Talk is cheap. Show me the code.");
	
	return 0;
} 

L1-2 cat is liquid (5 points)

#include <bits/stdc++.h>
using namespace std;

int main(void)
{
    
    
	int a, b, c;
	cin >> a >> b >> c;
	cout << a * b * c << endl;
	
	return 0;
} 

L1-3 Roche limit (10 points)

#include <bits/stdc++.h>
using namespace std;

int main(void)
{
    
    
	double a, c, res;
	int b;
	cin >> a >> b >> c;
	if (b == 0) {
    
    
		res = a * 2.455;
	} else {
    
    
		res = a * 1.26;
	}
	printf("%.2f ", res);
	if (res > c) {
    
    
		puts("T_T");
	} else {
    
    
		puts("^_^");
	}
	
	return 0;
} 

L1-4 Harmonized Average (10 points)

#include <bits/stdc++.h>
using namespace std;

int main(void)
{
    
    
	int n;
	double t, res = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
    
    
		cin >> t;
		res += 1 / t;
	}
	res /= n;
	res = 1 / res;
	printf("%.2f\n", res);
	
	return 0;
} 

L1-5 Tire pressure monitoring (15 points)

#include <bits/stdc++.h>
using namespace std;

int main(void)
{
    
    
	int a[5];
	int low, diff, maxv = -1;
	int cnt = 0, pos;
	for (int i = 1; i <= 4; i++) {
    
    
		cin >> a[i];
		maxv = max(maxv, a[i]);
	}
	cin >> low >> diff;
	for (int i = 1; i <= 4; i++) {
    
    
		if (maxv - a[i] > diff || a[i] < low) {
    
    
			pos = i;
			cnt++;
		}
	}
	if (cnt == 0) {
    
    
		puts("Normal");
	} else if (cnt == 1) {
    
    
		printf("Warning: please check #%d!\n", pos);
	} else {
    
    
		puts("Warning: please check all the tires!");
	}
	
	return 0;
} 

L1-6 Eat hot pot (15 points)

#include <bits/stdc++.h>
using namespace std;

int main(void)
{
    
    
	string s;
	int cnt = 0, res = 0, st = 0;
	while (true) {
    
    
		getline(cin, s);
		if (s == ".")
			break;
		cnt++;
		if (s.find("chi1 huo3 guo1") != -1) {
    
    
			res++;
			if (st == 0)
				st = cnt;
		}
	}
	cout << cnt << endl;
	if (res != 0)
		cout << st << " " << res << endl;
	else
		cout << "-_-#" << endl;
	
	return 0;
} 

L1-7 Past Life Archives (20 points)

#include <bits/stdc++.h>
using namespace std;

int main(void)
{
    
    
	int n, m, res, base;
	string s;
	cin >> n >> m;
	
	while (m--) {
    
    
		res = 1; base = 1;
		for (int i = 0; i < n-1; i++) {
    
    
			base *= 2;
		}
		cin >> s;
		for (int i = 0; i < n; i++) {
    
    
			if (s[i] == 'n')
				res += base;
			base /= 2;
		}
		cout << res << endl;
	}
	
	return 0;
} 

L1-8 Scratch the lottery ticket (20 points)

#include <bits/stdc++.h>
using namespace std;

int arr[5][5]; 
bool vis[10];
int a[] = {
    
    10000, 36, 720, 360, 80, 252, 108, 72, 54, 180, 
			72, 180, 119, 36, 306, 1080, 144, 1800, 3600};

int main(void)
{
    
    
	int x, y;
	for (int i = 1; i <= 3; i++) {
    
    
		for (int j = 1; j <= 3; j++) {
    
    
			cin >> arr[i][j];
			vis[arr[i][j]] = 1;
			if (arr[i][j] == 0) {
    
    
				x = i, y = j;
			}
		}
	}
	for (int i = 1; i <= 9; i++) {
    
    
		if (vis[i] == 0) {
    
    
			arr[x][y] = i;
		}
	}
	for (int i = 0; i < 3; i++) {
    
    
		cin >> x >> y;
		cout << arr[x][y] << endl;
	}
	int op, cnt = 0;
	cin >> op;
	if (op <= 3) {
    
    
		for (int i = 1; i <= 3; i++) {
    
    
			cnt += arr[op][i];
		}
	} else if (op <= 6) {
    
    
		for (int i = 1; i <= 3; i++) {
    
    
			cnt += arr[i][op - 3];
		}
	} else if (op == 7) {
    
    
		for (int i = 1; i <= 3; i++) {
    
    
			cnt += arr[i][i];
		}
	} else {
    
    
		cnt += arr[1][3] + arr[2][2] + arr[3][1];
	}
	cout << a[cnt - 6] << endl;
	
	return 0;
} 

L2-1 Simple Calculator (25 points)

Use the stack to simulate it

#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;

stack<int> stk;
char op[N];

int main(void)
{
    
    
	bool flag = 1;
	int n, a, b;
	cin >> n;
	for (int i = 0; i < n; i++) {
    
    
		cin >> a;
		stk.push(a);
	}
	for (int i = 0; i < n - 1; i++) {
    
    
		cin >> op[i];
	}
	int idx = n - 2;
	while (stk.size() >= 2) {
    
    
		a = stk.top(); stk.pop();
		b = stk.top(); stk.pop();
		if (op[idx] == '+') {
    
    
			stk.push(b + a);
		} else if (op[idx] == '-') {
    
    
			stk.push(b - a);
		} else if (op[idx] == '*') {
    
    
			stk.push(b * a);
		} else {
    
    
			if (a == 0) {
    
    
				flag = 0;
				break;
			} else {
    
    
				stk.push(b / a);
			}
		}
		idx--;
	}
	if (flag == 1) {
    
    
		cout << stk.top() << endl;
	} else {
    
    
		printf("ERROR: %d/%d\n", b, a);
	}
	
	return 0;
} 

L2-4 Online celebrity point clocking strategy (25 points)

Simulate

Conditions that need to be met:

1. See if you can start from 0 and then return to 0

2. Check in all n internet celebrity points once, and not more than once

#include <bits/stdc++.h>
using namespace std;
const int N = 205, INF = 0x3f3f3f3f;

int arr[N][N];
int way[N];
bool vis[N];

int main(void)
{
    
    
	int n, m, k;
	cin >> n >> m;
	for (int i = 0; i <= n; i++) {
    
    
		for (int j = 0; j <= n; j++) {
    
    
			arr[i][j] = (i == j ? 0 : INF);
		}
	}
	int a, b, c;
	for (int i = 0; i < m; i++) {
    
    
		cin >> a >> b >> c;
		arr[a][b] = arr[b][a] = c;
	}
	cin >> k;
	int u, v;
	int res = INF, idx, cnt;
	int num = 0;
	bool flag;
	for (int j = 1; j <= k; j++) {
    
    
		memset(vis, 0, sizeof vis);
		flag = 1; cnt = 0;
		cin >> u;
		for (int i = 1; i <= u; i++) {
    
    
			cin >> way[i];
		}
		way[0] = way[u + 1] = 0;
		for (int i = 0; i <= u; i++) {
    
    
			if (arr[way[i]][way[i + 1]] != INF && vis[way[i + 1]] == 0) {
    
    
				cnt += arr[way[i]][way[i + 1]];
				vis[way[i + 1]] = 1;
			} else {
    
    
				flag = 0;
				break;
			}
		}
		for (int i = 1; i <= n; i++) {
    
    
			if (vis[i] == 0) 
				flag = 0;
		}
		if (flag == 1) {
    
    
			num++;
			if (res > cnt) {
    
    
				res = cnt;
				idx = j;
			}
		}
	}
	cout << num << endl;
	cout << idx << " " << res << endl;
	
	return 0;
} 

Guess you like

Origin blog.csdn.net/weixin_43772166/article/details/112443812