社区讨论

找不同~(玄关)

P14361[CSP-S 2025] 社团招新参与者 5已保存回复 12

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
12 条
当前快照
1 份
快照标识符
@mhpi12xd
此快照首次捕获于
2025/11/08 07:40
4 个月前
此快照最后确认于
2025/11/08 07:52
4 个月前
查看原帖
该倒霉蛋复现代码喜提AC,考场代码喜提爆炸65(大哭)
有无好心人帮我找不同~跪谢了
现在整个人都不好了·-·
考场代码(65)
CPP
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll T,n,sum,t[4],mt=0,cmt=0;
struct node{
	ll c[4];
}a[N];
bool cmp(node a,node b){
	if (a.c[0]==a.c[1] and b.c[0]==b.c[1])return max(a.c[2],a.c[3])-a.c[0]>max(b.c[2],b.c[3])-b.c[0];
	if (a.c[0]==a.c[1] and b.c[0]==b.c[2])return max(a.c[2],a.c[3])-a.c[0]>max(b.c[1],b.c[3])-b.c[0];
	if (a.c[0]==a.c[1] and b.c[0]==b.c[3])return max(a.c[2],a.c[3])-a.c[0]>max(b.c[1],b.c[2])-b.c[0];
	if (a.c[0]==a.c[2] and b.c[0]==b.c[1])return max(a.c[1],a.c[3])-a.c[0]>max(b.c[2],b.c[3])-b.c[0];
	if (a.c[0]==a.c[2] and b.c[0]==b.c[2])return max(a.c[1],a.c[3])-a.c[0]>max(b.c[1],b.c[3])-b.c[0];
	if (a.c[0]==a.c[2] and b.c[0]==b.c[3])return max(a.c[1],a.c[3])-a.c[0]>max(b.c[1],b.c[2])-b.c[0];
	if (a.c[0]==a.c[3] and b.c[0]==b.c[1])return max(a.c[2],a.c[1])-a.c[0]>max(b.c[2],b.c[3])-b.c[0];
	if (a.c[0]==a.c[3] and b.c[0]==b.c[2])return max(a.c[2],a.c[1])-a.c[0]>max(b.c[1],b.c[3])-b.c[0];
	if (a.c[0]==a.c[3] and b.c[0]==b.c[3])return max(a.c[2],a.c[1])-a.c[0]>max(b.c[1],b.c[2])-b.c[0];	
}
int main(){
	freopen("club.in","r",stdin);
	freopen("club.out","w",stdout);
	scanf("%lld",&T);
	while (T--){
		sum=t[1]=t[2]=t[3]=mt=0;
		scanf("%lld",&n);
		for (ll i=1;i<=n;i++){
			scanf("%lld%lld%lld",&a[i].c[1],&a[i].c[2],&a[i].c[3]);
			ll tt=max(max(a[i].c[1],a[i].c[2]),a[i].c[3]);
			if (tt==a[i].c[1]){
				t[1]++;a[i].c[0]=a[i].c[1];
			}else if (tt==a[i].c[2]){
				t[2]++;a[i].c[0]=a[i].c[2];
			}else if (tt==a[i].c[3]){
				t[3]++;a[i].c[0]=a[i].c[3];
			}
		}mt=max(max(t[1],t[2]),t[3]);
		if (mt<=n/2){
			for (int i=1;i<=n;i++)sum+=a[i].c[0];
			printf("%lld\n",sum);continue;
		}
		
		for (int i=1;i<=3;i++){
			if (t[i]==mt)cmt=i;
		}
		sort(a+1,a+1+n,cmp);
		for (int i=1;i<=n and t[cmt]>n/2;i++){
			if (a[i].c[0]==a[i].c[cmt]){
				t[cmt]--;
				if (cmt==1)a[i].c[0]=max(a[i].c[2],a[i].c[3]);
				if (cmt==2)a[i].c[0]=max(a[i].c[1],a[i].c[3]);
				if (cmt==3)a[i].c[0]=max(a[i].c[1],a[i].c[2]);
			}
		}
		for (int i=1;i<=n;i++)sum+=a[i].c[0];
		printf("%lld\n",sum);continue;
	}
	return 0;
}
/*
思路:先不考虑人数限制
	  再分组微调 
*/
复现的AC代码(AC)
CPP
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
ll T,n,res=0;
ll t1,t2,t3,mt,cmt;
struct node{
	ll c[4];
}a[N];
bool cmp(node a,node b){
	if (a.c[0]==a.c[1] and b.c[0]==b.c[1])return (a.c[0]-max(a.c[3],a.c[2]))<(b.c[0]-max(b.c[3],b.c[2]));
	if (a.c[0]==a.c[1] and b.c[0]==b.c[2])return (a.c[0]-max(a.c[3],a.c[2]))<(b.c[0]-max(b.c[3],b.c[1]));
	if (a.c[0]==a.c[1] and b.c[0]==b.c[3])return (a.c[0]-max(a.c[3],a.c[2]))<(b.c[0]-max(b.c[1],b.c[2]));
	if (a.c[0]==a.c[2] and b.c[0]==b.c[1])return (a.c[0]-max(a.c[3],a.c[1]))<(b.c[0]-max(b.c[3],b.c[2]));
	if (a.c[0]==a.c[2] and b.c[0]==b.c[2])return (a.c[0]-max(a.c[3],a.c[1]))<(b.c[0]-max(b.c[3],b.c[1]));
	if (a.c[0]==a.c[2] and b.c[0]==b.c[3])return (a.c[0]-max(a.c[3],a.c[1]))<(b.c[0]-max(b.c[1],b.c[2]));
	if (a.c[0]==a.c[3] and b.c[0]==b.c[1])return (a.c[0]-max(a.c[1],a.c[2]))<(b.c[0]-max(b.c[3],b.c[2]));
	if (a.c[0]==a.c[3] and b.c[0]==b.c[2])return (a.c[0]-max(a.c[1],a.c[2]))<(b.c[0]-max(b.c[3],b.c[1]));
	if (a.c[0]==a.c[3] and b.c[0]==b.c[3])return (a.c[0]-max(a.c[1],a.c[2]))<(b.c[0]-max(b.c[1],b.c[2]));
}
int main(){
//	freopen("club5.in","r",stdin);
//	freopen("club.out","w",stdout);
	scanf("%lld",&T);
	while (T--){
		res=mt=t1=t2=t3=0;
		scanf("%lld",&n);
		for (int i=1;i<=n;i++){
			scanf("%lld%lld%lld",&a[i].c[1],&a[i].c[2],&a[i].c[3]);
			a[i].c[0]=max(max(a[i].c[1],a[i].c[2]),a[i].c[3]);
			if (a[i].c[0]==a[i].c[1])t1++;
			if (a[i].c[0]==a[i].c[2])t2++;
			if (a[i].c[0]==a[i].c[3])t3++;
		}
		mt=max(max(t1,t2),t3);
		if (mt<=n/2){
			for (int i=1;i<=n;i++)res+=a[i].c[0];
			printf("%lld\n",res);
			continue;
		}
		if (mt==t1)cmt=1;
		if (mt==t2)cmt=2;
		if (mt==t3)cmt=3;
		sort(a+1,a+1+n,cmp);
		for (int i=1;i<=n and mt>n/2;i++){
			if(a[i].c[0]==a[i].c[cmt]){
				mt--;
				if (cmt==1)a[i].c[0]=max(a[i].c[2],a[i].c[3]);
				if (cmt==2)a[i].c[0]=max(a[i].c[1],a[i].c[3]);
				if (cmt==3)a[i].c[0]=max(a[i].c[2],a[i].c[1]);
			}
		}
		for (int i=1;i<=n;i++)res+=a[i].c[0];
		printf("%lld\n",res);		
	}
	return 0;
}

回复

12 条回复,欢迎继续交流。

正在加载回复...