上海市计算机学会2020年9月月赛(丙组)

第一道题:最大平方因子 AC

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int ct, ct1, sum = 0;
int main() {
	int num, ct = 1, mx = -1;
	cin >> num;
	for (int i = num/2; i >= 1; --i) {
		if (num%i == 0) {
			ct1 = i;
			ct = sqrt(i);
			if ( pow(ct, 2) == ct1) {
				sum = ct1;
				mx = max(mx, sum);
			}
		}
	}
	printf("%d", mx);
	return 0;
}

第二道题:中心对称数 AC

这道题我弄了他两年半了,终于给他搞成AC了!!!QAQ

我总结出了这样一句话:十进制和循环的综合题,首先输入,转变为十进制,判断对称,输出

#include <iostream>
#include <algorithm>
using namespace std;
string s;
char b[10];
int main() {
	cin >> s;
	b[1] = '1';
	b[8] = '8';
	b[0] = '0';
	b[6] = '9';
	b[9] = '6';
	int len = s.size();
	for (int i = 0; i < len; i++) {
		if (s[i]=='2' || s[i]=='3' || s[i]=='4' || s[i]=='5' || s[i]=='7') {
			printf("Not a strobogrammatic number");
			return 0;
		} else if (!(s[i]==b[s[len-i-1]-'0'])) {
			printf("Not a strobogrammatic number");
			return 0;
		}
	}
	printf("Strobogrammatic number");
	return 0;
}

第三道题:选修课程 AC

#include <bits/stdc++.h>
using namespace std;
const int N = 1007;
string s;
int clct, stct;
struct cour {
	string name;
	int capacity;
} cour[N];
int main() {
	int m, n;
	scanf("%d%d", &m, &n);
	for (int i = 1; i <= m; i++)
		cin >> cour[i].name >> cour[i].capacity;
	map<string, int> ct;
	for (int i = 1; i <= n; i++) {
		cin >> s;
		ct[s]++;
	}
	for (int i = 1; i <= m; i++) {
		if (ct[cour[i].name]*2 < cour[i].capacity) {
			clct++;
			stct += ct[cour[i].name];
		} else if (ct[cour[i].name] > cour[i].capacity)
			stct += ct[cour[i].name] - cour[i].capacity;
	}
	cout << clct << endl << stct;
	return 0;
}

第四道题:随机性验证 AC

#include <iostream>
#include <algorithm>
using namespace std;
string s;
int main() {
	cin >> s;
	int len = s.size();
	for (int i = 0; i < len-1; i++) {
		if (s[i]==s[i+1] || s[i]==s[i+2]) {
			cout << "Not a random string";
			return 0;
		}
	}
	cout << "Random string";
	return 0;
}

第五道题:异或方程 AC

#include <iostream>
#include <algorithm>
using namespace std;
const int mod = 1e9 + 9, N = 1e6 + 7;
int dp[N];
int main() {
	int n;
	scanf("%d", &n);
	dp[0] = 1;
	dp[1] = 2;
	for (int i = 2; i <= n; i++)
		dp[i] = (dp[i-1] + dp[i-2]) % mod;
	printf("%d\n", dp[n]);
	return 0;
}

若有更好的解,欢迎评论或私信与我~

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值