跳到正文

题解

题解:P11323 【MX-S7-T1】「SMOI-R2」Happy Card

用户 555262约 3 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 3 分钟
获赞
1
题目
P11323

版本

  1. v1当前

将所有的牌数拆成n * 3+1 例如5拆成1*3+1+n * 1,将炸弹看成3带一个一样的牌,则三带一定是出牌最快的,然后就可以贪心了 题解如下

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=300005;
int a[N],th[N],one[N],s,y;
signed main(){
	int t;
	scanf("%lld",&t);
	while(t--){
		int ans=0,n,s=0,y=0;
		scanf("%lld",&n);
		for(int i=1;i<=n;i++){
			scanf("%lld",&a[i]);
			th[i]=(a[i]/3);
			s+=th[i];//记录有几组3张牌
			one[i]=(a[i]%3);
			y+=one[i];//记录但张牌
		}
		if(s==y){//当3张牌的组数与单张牌的个数相同则全部出3带1
			cout<<s<<endl;
			continue;
		}
		else if(s>y){	//当3张牌的组数大于但张牌的个数
			ans+=y;
			s-=y;
			if(s%4==0){ //刚好把部分3组的拆开,与其他三个的凑成一对
				ans+=(s/4)*3;
				cout<<ans<<endl;
				continue;
			} if(s%4==1){//多出一组3张,拆成一对对子和一张单牌
				ans+=(s/4)*3;
				ans+=2;
				cout<<ans<<endl;
				continue;
			} if(s%4==2){// 多出2组3张,拆成一个三带一和一张单牌
				ans+=(s/4)*3;
				ans+=2;
				cout<<ans<<endl;
				continue;
			} if(s%4==3){// 多出3组3牌,拆成了两个三带一和一个单牌
				ans+=(s/4)*3;
				ans+=3;
				cout<<ans<<endl;
				continue;
			}
		} else {// 当有多的单排

			ans+=s;
			y-=s;
			for(int i=1;i<=n;i++){
				if(y==1){
					break;
				}
				if(y==0){
					break;
				}
				if(one[i]%2==0&&one[i]!=0){//能凑出对子的优先
					ans++;
					y-=2;
				}
			}
			ans+=y;//实在不行出单牌
			cout<<ans<<endl;
		}
	}

	return 0;
}

其实是我的话我出老千 皮

原文