上海市计算机学会月赛2020年3月丙组

本次竞赛涵盖了从打渔还是晒网的策略问题,到数字加密的安全性讨论,再到双质数的数学探讨,以及连乘问题和救援争先的算法设计。参赛者在c++编程语言中展现了他们的算法解决能力。
打渔还是晒网
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n;
	cin >> n;
	
	if (n % 5 == 0 || n % 5 == 4) {	//后两天晒网 
		cout << "Lying" << endl;
	}
	else {
		cout << "Fishing" << endl;	//前三天打渔 
	}
	
	return 0;
}
数字加密
#include <bits/stdc++.h>
using namespace std;

int main() {
	char c[4];
	cin >> c;
	
	for (int i = 3; i >= 0; i --) {		//倒过来枚举 
		//'9' - c[i]得到对调后的数字 
		//'9' - c[i]得到对调后的数字的ASCII码 
		cout << char('9' - c[i] + '0');
	}
	
	return 0;
}
双质数
#include <bits/stdc++.h>
using namespace std;

bool isPrime(int x) {
	if (x < 2) return false;		//特判 
	
	for (int i = 2; i <= x / i; i ++) {
		if (x % i == 0) {
			return false;
		}
	}
	return true;
}

int main() {
	int a, b;
	cin >> a >> b;
	
	bool flag = false;	
	for (int i = a; i <= b; i++) {
		if (isPrime(i) && isPrime(i / 10)) {
			cout << i << endl;
			flag = true;
		}
	}
	
	if (!flag) {		//说明没有找到双质数 
		cout << "None" << endl;
	}
	
	return 0;
}
连乘问题
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 9, MOD = 1e4;
int n, a[N], b[N], c[N];

int main() {
	scanf("%d", &n);	
	for (int i = 1; i <= n; i ++) {
		scanf("%d", &a[i]);
	}
	
	b[0] = 1;
	for (int i = 1; i <= n; i ++) {			//前缀积 
		b[i] = b[i - 1] * a[i] % MOD;
	}
	
	c[n + 1] = 1;
	for (int i = n; i >= 1; i --) { 		//后缀积 
		c[i] = c[i + 1] * a[i] % MOD;
	}	
	
	for (int i = 1; i <= n; i ++) {
		printf("%d\n", b[i - 1] * c[i + 1] % MOD);
	}
	
	return 0;
}
救援争先
#include <bits/stdc++.h>
using namespace std;

int n;
struct team{
	int depart, arrive, id;
}t[1005];

bool cmp(team a, team b) {
	if (a.arrive < b.arrive) return true;
	if (a.arrive == b.arrive) {
		if (a.depart < b.depart) return true;
		if (a.depart == b.depart) {
			if (a.id < b.id) return true;			
		}
	}
	return false;
}

int main() {
	cin >> n;	
	for (int i = 1; i <= n; i ++) {
		int x, y;
		char ch;
		
		cin >> x >> ch >> y;
		t[i].depart = x * 60 + y;				//第i只队伍的出发时间 
		
		cin >> x >> ch >> y;
		t[i].arrive = t[i].depart + x * 60 + y;	//第i只队伍的到达时间
		
		t[i].id = i;							//第i只队伍的编号 
	}

	sort(t + 1, t + 1 + n, cmp);				//根据题目中的规则进行排序 

	for (int i = 1; i <= n; i ++) cout << t[i].id << endl;

	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值