【2020第五届团体程序设计天梯赛】个人题解(C++)

L1-1 嫑废话上代码

解题思路:无

参考代码:

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

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

L1-2 猫是液体

解题思路:小学算术

参考代码:

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

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

L1-3 洛希极限

解题思路:小学算术

参考代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 5;
int main() {
	int a;
	float n, m, p;
	scanf("%f %d %f", &n, &a, &m);
	if (a == 0) p = n * 2.455;
	else p = n * 1.26;
	if (p > m) printf("%.2f T_T", p);
	else printf("%.2f ^_^", p);
	return 0;
}

L1-4 调和平均

解题思路:小学算术

参考代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 5;
int main() {
	int n;
	cin >> n;
	double x, sum = 0;
	for (int i = 1; i <= n; i++) {
		cin >> x;
		sum += 1.0 / x;
	}
	sum /= n;
	printf("%.2lf", 1.0 / sum);
	return 0;
}

L1-5 胎压监测

解题思路:分类讨论

参考代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 5;
int main() {
	int a[5];
	for (int i = 1; i <= 4; i++) cin >> a[i];
	int n, m;
	cin >> n >> m;
	int ma = 0;
	for (int i = 1; i <= 4; i++) ma = max(ma, a[i]);
	int ok = 1;
	int cnt1 = 0, cnt2 = 0;
	int index1, index2;
	for (int i = 1; i <= 4; i++) {
		if (abs(ma - a[i]) > m) {
			cnt1++;
			index1 = i;
		}
	}
	for (int i = 1; i <= 4; i++) {
		if (a[i] < n) {
			cnt2++;
			index2 = i;
			ok = 0;
		}
	}
	if (ok == 1 && cnt1 == 0) cout << "Normal";
	if (max(cnt1, cnt2) == 1) {
		if (cnt1 == 1) {
			printf("Warning: please check #%d!", index1);
			return 0;
		}
		if (cnt2 == 1) printf("Warning: please check #%d!", index2);
	}
	if (max(cnt1, cnt2) >= 2) cout << "Warning: please check all the tires!";
	return 0;
}

L1-6 吃火锅

解题思路:直接用stl查找

参考代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 5;
int main() {
	string s;
	int cnt = 1;
	vector<int>ans;
	while (getline(cin, s)) {
		if (s == ".") break;
		if (s.find("chi1 huo3 guo1") != -1) ans.push_back(cnt);
		cnt++;
	}
	cout << --cnt << endl;
	if (ans.size()) cout << ans.front() << ' ' << ans.size();
	else cout << "-_-#";
	return 0;
}

L1-7 前世档案

解题思路:找规律

参考代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 5;
int main() {
	string s;
	int n, m;
	cin >> n >> m;
	int cnt = pow(2, n) - 1;
	while (m--) {
		cin >> s;
		int now = 1;
		for (int i = 0; i < n; i++) {
			if (s[i] == 'y') now <<= 1;
			else now = now << 1 | 1;
		}
		cout << now - cnt << endl;
	}
	return 0;
}

L1-8 刮刮彩票

解题思路:模拟即可

参考代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 5;
bool is[10];
int a[5][5];
int main() {
	int c[19] = {10000, 36, 720, 360, 80, 252, 108, 72, 54, 180, 72, 180, 119, 36, 306, 1080, 144, 1800, 3600};
	for (int i = 1; i <= 3; i++) {
		for (int j = 1; j <= 3; j++) {
			cin >> a[i][j];
			is[a[i][j]] = 1;
		}
	}
	int x, y;
	for (int i = 0; i <= 9; i++) {
		if (is[i] == 0) x = i;
		is[i] = 0;
	}
	for (int i = 1; i <= 3; i++) {
		for (int j = 1; j <= 3; j++) {
			if (a[i][j] == 0) a[i][j] = x;
		}
	}
	for (int i = 1; i <= 3; i++) {
		cin >> x >> y;
		cout << a[x][y] << endl;
		is[a[x][y]] = 1;
	}
	cin >> x;
	int sum = 0;
	if (x <= 3) {
		for (int i = 1; i <= 3; i++) {
			sum += a[x][i];
		}
	} else if (x <= 6) {
		x -= 3;
		for (int i = 1; i <= 3; i++) {
			sum += a[i][x];
		}
	} else if (x == 7) {
		sum += a[1][1];
		sum += a[2][2];
		sum += a[3][3];
	} else if (x == 8) {
		sum += a[1][3];
		sum += a[2][2];
		sum += a[3][1];
	}
	cout << c[sum - 6];
	return 0;
}

L2-1 简单计算器

解题思路:模拟

参考代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 5;
stack<int>num;
stack<char>ch;
int n;
int main() {
	cin >> n;
	int x;
	char y;
	for (int i = 1; i <= n; i++) {
		cin >> x;
		num.push(x);
	}
	for (int i = 1; i < n; i++) {
		cin >> y;
		ch.push(y);
	}
	while (num.size() != 1) {
		int b = num.top();
		num.pop();
		int a = num.top();
		num.pop();
		char c = ch.top();
		ch.pop();
		if (c == '+') num.push(a + b);
		if (c == '-') num.push(a - b);
		if (c == '*') num.push(a * b);
		if (c == '/') {
			if (b == 0) {
				printf("ERROR: %d/0", a);
				return 0;
			} else num.push(a / b);
		}
	}
	cout << num.top();
	return 0;
}

L2-

解题思路:

参考代码:

L2-

解题思路:

参考代码:

L2-

解题思路:

参考代码:

L3-

解题思路:

参考代码:

L3-

解题思路:

参考代码:

L3-

解题思路:

参考代码:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值