URAL 1784 K - Rounders 找规律
K - Rounders
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87643#problem/K
Description
- take a few cards of one suit from the top of a deck and create a new deck of them;
- take a few cards of one suit from the top of a deck and put them onto a card which value is greater by one than the value of the bottommost of the taken cards.
Input
The input consists of four lines describing the piles of cards. Each line contains the description of 13 cards in a pile in order from top to bottom (that is, in the order of ascending values). Each card is denoted by its value and its suit. The value is one of the following: 2, 3, …, 9, T (ten), J (jack), Q (queen), K (king), A (ace), the suit can be: S (spades), C (clubs), D (diamonds) or H (hearts). All cards in the input are different.
Output
Output the minimal number of operations The Dude should perform in order to obtain four piles consisting of cards with the same suit.
Sample Input
2C 3C 4C 5C 6C 7C 8C 9C TC JC QC KC AC
2S 3S 4S 5S 6S 7S 8D 9D TD JD QD KD AD
2D 3D 4D 5D 6D 7D 8S 9S TS JS QS KS AS
2H 3H 4H 5H 6H 7H 8H 9H TH JH QH KH AH
Sample Output
3
HINT
题意
其实就是蜘蛛纸牌啦
一开始给你4个正确序列的纸牌
然后每次你就只能从上面拿下来一堆
然后问你最少几次操作可以得到上面的序列
题解:
我们对于每一行判断就好了,如果这一行有两个区别的话,那就加3啦,如果有3个区别,就加4,如果有4个区别,那就有两种,特判一下就好了
代码:
//qscqesze #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define maxn 5000 #define mod 10007 #define eps 1e-9 int Num; //const int inf=0x7fffffff; //нчоч╢С const int inf=0x3f3f3f3f; inline ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } //************************************************************************************** int s[4][40]; int main() { //freopen("test.txt","r",stdin); for(int i=0;i<4;i++) { for(int j=0;j<13;j++) { string ss; cin>>ss; if(ss[1]=='C') s[i][j]=1; else if(ss[1]=='S') s[i][j]=2; else if(ss[1]=='D') s[i][j]=3; else s[i][j]=4; } } int ans=0; for(int i=0;i<12;i++) { int tot=0; for(int j=0;j<4;j++) { if(s[j][i]!=s[j][i+1]) tot++; } if(tot==4) { int flag=0; for(int j=0;j<4;j++) { for(int jj=1;jj<4;jj++) { if(s[j][i]==s[jj][i+1]&&s[jj][i]==s[j][i+1]) flag=1; } } if(flag) ans++; } if(tot>0) ans+=tot+1; } cout<<ans<<endl; }