社区讨论
萌新求助qwq
P2668[NOIP 2015 提高组] 斗地主参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mi8620cb
- 此快照首次捕获于
- 2025/11/21 09:13 4 个月前
- 此快照最后确认于
- 2025/11/21 09:13 4 个月前
45分qwq
CPP#include <bits/stdc++.h>
using namespace std;
int const N=25;
int t,n,card[N],res,ct1;
inline int playelse(){
int cnt[N],ans=0;
memset(cnt,0,sizeof(cnt));
bool rok=false;
if(card[14]==2)rok=true;
cnt[1]+=card[14];
for(int i=1;i<=13;i++)cnt[card[i]]++;
while(!cnt[3]&&cnt[1]==1&&cnt[2]==1&&cnt[4]>1)cnt[4]-=2,cnt[1]--,cnt[2]--,ans+=2;
while(!cnt[2]&&cnt[1]==1&&cnt[2]==1&&cnt[3]>1)cnt[3]-=2,cnt[1]--,cnt[4]--,ans+=2;
if(cnt[3]+cnt[4]>cnt[1]+cnt[2])
while(cnt[4]&&cnt[3]&&cnt[2])cnt[4]--,cnt[3]--,cnt[2]--,cnt[1]++,ans++;
if(cnt[3]+cnt[4]>cnt[1]+cnt[2])
while(cnt[4]&&cnt[3]&&cnt[1])cnt[1]--,cnt[3]--,cnt[4]--,cnt[2]++,ans++;
while(cnt[4]&&cnt[1]>1)cnt[4]--,cnt[1]-=2,ans++;
while(cnt[4]&&cnt[2]>1)cnt[4]--,cnt[2]-=2,ans++;
while(cnt[4]&&cnt[2])cnt[4]--,cnt[2]--,ans++;
if(cnt[3]%3==0&&cnt[1]+cnt[2]<=1)
while(cnt[3]>2)cnt[3]-=3,ans+=2;
while(cnt[3]&&cnt[1])cnt[3]--,cnt[1]--,ans++;
while(cnt[3]&&cnt[2])cnt[3]--,cnt[2]--,ans++;
while(cnt[4]>1&&cnt[3])cnt[3]--,cnt[4]-=2,ans+=2;
while(cnt[3]>1&&cnt[4])cnt[3]-=2,cnt[4]--,ans+=2;
while(cnt[3]>2)cnt[3]-=3,ans+=2;
while(cnt[4]>1)cnt[4]-=2,ans++;
if(rok && cnt[1]>=2)return ans+cnt[2]+cnt[3]+cnt[4]+cnt[1]-1;
else return ans+cnt[1]+cnt[2]+cnt[3]+cnt[4];
}
void play(int step);
void F_straight(int step){
int l,last;
for(int st=3;st<=10;st++){
l=0;
while(card[st+l]>=1)l++;
for(int j=l;j>=5;j--){
last=st+j-1;
for(int k=st;k<=last;k++)card[k]-=1;
play(step+1);
for(int k=st;k<=last;k++)card[k]+=1;
}
}
}
void D_straight(int step){
int l,last;
for(int st=3;st<=12;st++){
l=0;
while(card[st+l]>=2)l++;
for(int j=l;j>=3;j--){
last=st+j-1;
for(int k=st;k<=last;k++)card[k]-=2;
play(step+1);
for(int k=st;k<=last;k++)card[k]+=2;
}
}
}
void T_straight(int step){
int l,last;
for(int st=3;st<=13;st++){
l=0;
while(card[st+l]>=3)l++;
for(int j=l;j>=2;j--){
last=st+j-1;
for(int k=st;k<=last;k++)card[k]-=3;
play(step+1);
for(int k=st;k<=last;k++)card[k]+=3;
}
}
}
void play(int step){
if(step>=res)return;
int temp=playelse();
res=min(step+temp,res);
T_straight(step);
D_straight(step);
F_straight(step);
}
int main(int argc, const char * argv[]){
scanf("%d%d",&t,&n);
while(t--){
memset(card,0,sizeof(card));
res=0x3f3f3f3f;
for(int i=1;i<=n;i++){
int x,x1;
scanf("%d%d",&x,&x1);
if(x>=2&&x<=13)card[x]++;
if(x==1)card[14]++;
if(x==0)card[1]++;
}
play(0);
printf("%d\n",res);
}
return 0;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...