http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=582

  QAQ许久没打过比赛,来一发BC,结果还是只能做前两题……too young too naive了……

  不过这场比赛前两题被hack&FST的人挺多的?蒟蒻手太慢,造数据也慢,玩不来hack……抢不到QAQ

A

  给5张牌,问最少换多少张可得到同花顺。

  其实是枚举花色,以及最小的是哪张(其实就是枚举换完以后,得到的是哪五张)看手里有多少张是已经得到的= =

  开个have[i][j]表示手里有花色为 i 数字为 j 的牌(其中,如果手里有A,那么1和14都置为true)

  hack点?没啥吧……可能有的同学是看手里连续拥有最大段是多长,比如手里最长的连续牌是123,那ans=2,但是135也是只需要换两张……

 1 //BestCoder #41 A
 2 #include<vector>
 3 #include<cstdio>
 4 #include<cstring>
 5 #include<cstdlib>
 6 #include<iostream>
 7 #include<algorithm>
 8 #define rep(i,n) for(int i=0;i<n;++i)
 9 #define F(i,j,n) for(int i=j;i<=n;++i)
10 #define D(i,j,n) for(int i=j;i>=n;--i)
11 #define pb push_back
12 using namespace std;
13 inline int getint(){
14     int v=0,sign=1; char ch=getchar();
15     while(ch<'0'||ch>'9'){ if (ch=='-') sign=-1; ch=getchar();}
16     while(ch>='0'&&ch<='9'){ v=v*10+ch-'0'; ch=getchar();}
17     return v*sign;
18 }
19 const int N=1e5+10,INF=~0u>>2;
20 typedef long long LL;
21 /******************tamplate*********************/
22 
23 int a[6],b[6];
24 char s[6][10];
25 bool have[6][16];
26 int main(){
27 #ifndef ONLINE_JUDGE
28     freopen("A.in","r",stdin);
29     freopen("A.out","w",stdout);
30 #endif
31     int T=getint();
32     while(T--){
33         memset(have,0,sizeof have);
34         memset(a,0,sizeof a);
35         memset(b,0,sizeof b);
36         memset(s,0,sizeof s);
37         F(i,1,5) scanf("%s",s[i]);
38         F(i,1,5) a[i]=s[i][0]-'A';
39         F(i,1,5){
40             b[i]=s[i][1]-'0';
41             if (s[i][2]>0) b[i]=b[i]*10+s[i][2]-'0';
42             have[a[i]][b[i]]=1;
43             if (b[i]==1) have[a[i]][14]=1;
44         }
45 #ifdef debug
46         F(i,1,5) printf("%d %d\n",a[i],b[i]);
47 #endif
48         int ans=0;
49         rep(i,4){
50             int mx=0,now=0;
51             F(j,1,15){
52                 now=now+have[i][j]-have[i][max(j-5,0)];
53                 mx=max(mx,now);
54             }
55             ans=max(ans,mx);
56         }
57         printf("%d\n",5-ans);
58     }
59     return 0;
60 }
View Code

相关文章: