URAL 1784 K - Rounders 找规律

时间:2021-11-07 16:04:07

K - Rounders
Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87643#problem/K

Description

After the shameful loss in the match against Jesus Quintana, The Dude, Donny and Walter decided to turn to poker and become rounders. First of all, they decided to learn to deal with cards.
Walter gave Donny a simple task—he should split a deck of 52 cards into four piles in such a way that cards in each pile would be sorted in the order of ascending value. Two should be the topmost card, three should be the next card and so on. Ace should lie in the bottom. Walter wanted all decks to be comprised of the cards of the same suit but he forgot to mention it. As a result, the suits in piles were shuffled.
The Dude decided to save the day. But after five White Russians he poured into himself yesterday he isn't in a good condition for thinking. In fact, he is able to perform only the following actions:
  • 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.

The Dude doesn't change the order of cards while moving them.

Help The Dude to complete Walter's task before Walter get insane and shoot both his best friends with Uzi.
 

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=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//**************************************************************************************
int s[][];
int main()
{
//freopen("test.txt","r",stdin);
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
string ss;
cin>>ss;
if(ss[]=='C')
s[i][j]=;
else if(ss[]=='S')
s[i][j]=;
else if(ss[]=='D')
s[i][j]=;
else
s[i][j]=;
}
}
int ans=;
for(int i=;i<;i++)
{
int tot=;
for(int j=;j<;j++)
{
if(s[j][i]!=s[j][i+])
tot++;
}
if(tot==)
{
int flag=;
for(int j=;j<;j++)
{
for(int jj=;jj<;jj++)
{
if(s[j][i]==s[jj][i+]&&s[jj][i]==s[j][i+])
flag=;
}
}
if(flag)
ans++;
}
if(tot>)
ans+=tot+;
}
cout<<ans<<endl;
}