跳到正文

剪贴板

剪贴板 53ry6cvt

原文
剪贴板信息

剪贴板信息

收录
更新

CSP-S\text{CSP-S} 第一题 决斗

C++
/*
	CSP-S 2024 RP++!
	This Code By Zhang Yimin.
	I will Get Second Prize?
	I Want to Get Second Prize!!!
	I Hope This Code Will Be AC.
	(My English is not well QwQ)

	 CCF <--- OIer's God--CCF!
	_____
	|  |___Orz_Orz_Orz___

	面对现实,成为现实。
*/
#include<bits/stdc++.h>
using namespace std;
struct solve{
	int d,id;
}r[100100];
struct solve2{
	int val,l,num;
}cnt[100100];
int total=1;
bool cmp(solve a,solve b) {
	return a.d<b.d;
}
bool test5_10=false;
int main() {
	freopen("duel.in","r",stdin);
	freopen("duel.out","w",stdout);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) {
		cin>>r[i].d;
		r[i].id=i;
		if(r[i].d>2) {
			test5_10=false;
		}
	}
	if(test5_10) {
		int one,two;
		one=two=0;
		for(int i=1;i<=n;i++) {
			if(r[i].d==1) one++;
			else two++;
		}
		cout<<two;
		exit(0);
	}
	stable_sort(r+1,r+1+n,cmp);
	for(int i=1;i<=n;i++) {
		if(cnt[total-1].val!=r[i].d) {
			cnt[total].val=r[i].d;
			cnt[total].l=i;
			cnt[total-1].num=(i-1)-cnt[total-1].l+1;
			total++;
		}
	}
	cnt[total-1].num=n-cnt[total-1].l+1;
	total--;
	int ans=0;
	//for(int i=1;i<=total;i++) {
	//	cout<<cnt[i].l<<" "<<cnt[i].num<<" "<<cnt[i].val<<"\n";
	//}
	int l=0;
	for(int i=2;i<=total;i++) {
		if(cnt[i].num+l<cnt[i].l) l=cnt[i].num+l;
		else {
			l=cnt[i].l-1;
		}
		//cout<<l<<"\n";
	}
	ans=n-l;
	cout<<ans;
	return 0;
}

CSP-S\text{CSP-S} 第三题 染色

C++
/*
	CSP-S 2024 RP++!
	This Code By Zhang Yimin.
	I will Get Second Prize?
	I Want to Get Second Prize!!!
	I Hope This Code Will Get 20 pts.
	(My English is not well QwQ)

	 CCF <--- OIer's God--CCF!
	_____
	|  |___Orz_Orz_Orz___
*/
#include<bits/stdc++.h>
using namespace std;
int a[110];
bool cr[110];
int maxans=0,n;
void dfs(int n,int step) {
	if(step==n) {
//		for(int i=1;i<=n;i++) cout<<color[i]<<" ";
//		cout<<"\n";
//		return ;
		int pts=0;
		for(int i=1;i<=n;i++) {
			for(int j=i-1;j>=1;j--) {
				if(cr[j]==cr[i]&&a[i]==a[j]) {//有同色的数并且值相同
					pts+=a[i];
					break;
				}
			}
		}//大样例n=15不对呃呃呃
		//for(int i=1;i<=n;i++) cout<<c[i]<<" ";
		//cout<<"\n";
		maxans=max(maxans,pts);
		return ;
	}
	else {
		for(int c=0;c<=1;c++) {
			cr[step]=c;//染色
			dfs(n,step+1);
		}
	}
}
int main() {
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
//	ios::sync_with_stdio(0);
//	cin.tie(0),cout.tie(0);
	int T;
	cin>>T;
	while(T--) {
		maxans=0;
		memset(a,0,sizeof a);
		cin>>n;
		for(int i=1;i<=n;i++) {
			cin>>a[i];
		}
		dfs(n,0);
		cout<<maxans<<"\n";
	}
	return 0;
}
/*
2
15
5 3 7 2 4 13 11 6 5 5 3 5 12 8 13
15
1 12 11 11 7 11 15 6 4 6 3 15 7 5 2
*/