东华大学2020年程序设计竞赛(同步赛)A-D F G

东华大学2020年程序设计竞赛
A

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IO ios::sync_with_stdio(false)
#define pb push_back
#define mk make_pair
const int N = 100+10;
const int mod = 1e9+7;

int n;
struct node{
	int index;
	ll w;
	bool operator < (const node e) const{
		if(w == e.w) return index < e.index;
		else return w > e.w;
	}
}e[N];

int main(){
	IO;
	cin >> n;
	int index;
	ll a, b, c;
	for(int i = 0; i < n; i++){
		cin >> index >> a >> b >> c;
		e[i].index = index;
		e[i].w = a + 2*b + c*3;
	}
	sort(e, e+n);
	cout << e[0].index << " " << e[0].w << "\n";
	return 0;
}

B

exgcd求 a x = 1 ( m o d ) p ax=1(mod)p ax=1(mod)p,当 a a a p p p的倍数时无解

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IO ios::sync_with_stdio(false)
#define pb push_back
#define mk make_pair
const int N = 1e5+10;
const int mod = 1e9+7;

int t;
ll a, p;

ll exgcd(ll a, ll b, ll &x, ll &y){
	if(b == 0){
		x = 1; y = 0;
		return b;
	}
	ll res = exgcd(b, a%b, x, y);
	ll tmp = x;
	x = y;
	y = tmp - a/b*y;
	return res;
}

int main(){
	IO;
	cin >> t;
	while(t--){
		cin >> a >> p;
		if(a%p == 0){
			cout << "-1\n";
		}
		else{
			ll x, y;
			exgcd(a, p, x, y);
			while(x < 0){
				x += p;
				y -= a;
			}
			cout << x%p << "\n";
		}
	}
	return 0;
}

C 最短路

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IO ios::sync_with_stdio(false)
#define pb push_back
#define mk make_pair
const int N = 1e6+10;
const int mod = 1e9+7;

int n, m;
struct Edge{
	int to, next;
}e[4*N];
int head[N], tot = 0;
void addEdge(int u, int v){
	e[tot] = (Edge){v, head[u]};
	head[u] = tot++;
}
int d[N], vis[N];
priority_queue< pair<int, int> > q;
void Dij(){
	for(int i = 0; i <= n; i++){
		d[i] = 1e9; vis[i] = 0;
	}
	d[1] = 0;
	q.push(mk(0, 1));
	while(!q.empty()){
		int u = q.top().second;
		q.pop();
		if(vis[u]) continue;
		vis[u] = 1;
		for(int i = head[u]; i != -1; i = e[i].next){
			int v = e[i].to;
			if(d[v] > d[u] + 1){
				d[v] = d[u] + 1;
				q.push(mk(-d[v], v));
			}
		}
	}
}

ll qpow(ll a, int x){
	ll res = 1;
	while(x){
		if(x&1) res = res * a % mod;
		a = a * a % mod;
		x >>= 1;
	}
	return res;
}

int main(){
	IO;
	cin >> n >> m;
	memset(head, -1, sizeof(int)*(n+1));
	int u, v;
	for(int i = 0; i < m; i++){
		cin >> u >> v;
		addEdge(u, v);
		addEdge(v, u);
	}
	Dij();
	ll ans = 0;
	for(int i = 2; i <= n; i++){
		ans = (ans + qpow(2, d[i])) % mod;
	}
	cout << ans << "\n";
	return 0;
}

D

暴力模拟,每次选最小堆加

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IO ios::sync_with_stdio(false)
#define pb push_back
#define mk make_pair
const int N = 100+10;
const int mod = 1e9+7;

int t, n, a[N];

int main(){
	IO;
	cin >> t;
	while(t--){
		cin >> n;
		int sum = 0;
		for(int i = 0; i < n; i++){
			cin >> a[i];
			sum += a[i];
		}
		if(sum%n != 0){
			cout << "No\n";
			continue;
		}
		sort(a, a+n);
		int flag = 1;
		for(int i = 1; i < n; i++){
			if((a[i]-a[0]) % n != 0){
				flag = 0;
			}
		}
		int x = sum/n;
		while(flag){
			int cnt1 = 0, cnt2 = 0;
			for(int i = 0; i < n; i++){
				if(a[i] == x) cnt1++;
				if(a[i] == 0) cnt2++;
			}
			if(cnt1 == n) {
				flag = 1; break;
			}
			if(cnt2 > 1){
				flag = 0; break;
			}
			sort(a, a+n);
			a[0] += n-1;
			for(int i = 1; i < n; i++){
				a[i]--;
			}
		}
		if(flag == 0) {
			cout << "No\n";
		}
		else cout << "Yes\n";
	}
	return 0;
}

F

连续的0变为1,然后1又可以变为0,所以连续的0贡献2步,对结果没有影响。对每个字符串我们只需要统计1的个数就好。
当所有串含1的个数都是偶数时,无论你选择对哪些串进行操作,对方只要也选这些串进行操作,就能继续保证所有串含1的个数都是偶数。由于是Alice先动,所以只有当所有串含1的个数都是偶数时,Alice才会输,其他情况则是Bob落败。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IO ios::sync_with_stdio(false)
#define pb push_back
#define mk make_pair
const int N = 1e5+10;
const int mod = 1e9+7;

int t, n;
string s;

int main(){
	IO;
	cin >> t;
	while(t--){
		cin >> n;
		int ans = 0;
		for(int i = 0; i < n; i++){
			cin >> s;
			int num = 0;
			for(int j = 0; j < s.size(); j++){
				if(s[j] =='1') num++;
			}
			if(num % 2) ans++;
		}
		if(ans) cout << "sdzNB\n";
		else cout << "kgNB\n";
	}
	return 0;
}

G

最多只有五个数连乘, − 1 ∗ 1 ∗ 1 ∗ 1 ∗ − 1 -1*1*1*1*-1 11111,然后dp

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IO ios::sync_with_stdio(false)
#define pb push_back
#define mk make_pair
const int N = 1e5+10;
const int mod = 1e9+7;

int t, n, a[N], dp[N];

int main(){
	IO;
	cin >> t;
	while(t--){
		cin >> n;
		for(int i = 0; i <= n; i++){
			dp[i] = -1e9;
		}
		for(int i = 1; i <= n; i++){
			cin >> a[i];
		}
		dp[0] = 0;
		for(int i = 1; i <= n; i++){
			int x = 1;
			for(int  j = 1; j <= 5; j++){
				if(i - j < 0) continue;
				x *= a[i-j+1];
				dp[i] = max(dp[i], dp[i-j] + x);
			}
		}
		cout << dp[n] << "\n";
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 内容概要 《计算机试卷1》是一份综合性的计算机基础和应用测试卷,涵盖了计算机硬件、软件、操作系统、网络、多媒体技术等多个领域的知识点。试卷包括单选题和操作应用两大类,单选题部分测试学生对计算机基础知识的掌握,操作应用部分则评估学生对计算机应用软件的实际操作能力。 ### 适用人群 本试卷适用于: - 计算机专业或信息技术相关专业的学生,用于课程学习或考试复习。 - 准备计算机等级考试或职业资格认证的人士,作为实战演练材料。 - 对计算机操作有兴趣的自学者,用于提升个人计算机应用技能。 - 计算机基础教育工作者,作为教学资源或出题参考。 ### 使用场景及目标 1. **学习评估**:作为学校或教育机构对学生计算机基础知识和应用技能的评估工具。 2. **自学测试**:供个人自学者检验自己对计算机知识的掌握程度和操作熟练度。 3. **职业发展**:帮助职场人士通过实际操作练习,提升计算机应用能力,增强工作竞争力。 4. **教学资源**:教师可以用于课堂教学,作为教学内容的补充或学生的课后练习。 5. **竞赛准备**:适合准备计算机相关竞赛的学生,作为强化训练和技能检测的材料。 试卷的目标是通过系统性的题目设计,帮助学生全面复习和巩固计算机基础知识,同时通过实际操作题目,提高学生解决实际问题的能力。通过本试卷的学习与练习,学生将能够更加深入地理解计算机的工作原理,掌握常用软件的使用方法,为未来的学术或职业生涯打下坚实的基础。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值