2020年天梯赛题目

L1-1 嫑废话上代码 (5分)

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

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

L1-2 猫是液体 (5分)

#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 洛希极限 (10分)

#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 调和平均 (10分)

#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 胎压监测 (15分)

#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 吃火锅 (15分)

#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 前世档案 (20分)

#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 刮刮彩票 (20分)

#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 简单计算器 (25分)

用栈来模拟一下即可

#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 网红点打卡攻略 (25分)

模拟即可

需要满足的条件:

1、看能否从0出发再回到0

2、把n个网红点都打卡一次,且不能超过一次

#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;
} 
  • 2
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值