Ural SU Championship 2010 K题.Rounders
2015-08-14 00:28
337 查看
K - Rounders
Time Limit:500MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
URAL 1784
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
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
output
3
http://acm.timus.ru/problem.aspx?space=1&num=1784
分析:
题目意思
一副牌分成4堆,每堆13张牌,
每堆值从前至后为2-KA,牌色可能不一样。
现在可以有两种操作:
1.从一堆中顶开始拿同一花色的k张,组成新的一堆。
2、从一堆中顶开始那同一花色的k张,放到当前堆的上面,
要求是当前堆的第一张牌的值比要放堆的底的值大一。
问最少需要多少步操作,使得每一堆牌的花色一样。
解题思路:
模拟题+贪心思想。对于每一列,牌的值肯定相同,花色各不一样。
以最后一列为标准,从倒数第二列开始往前,
当当前列有两个不后面一列的花色不一样时,要移动3次,
当有三个不一样时要移动4次,注意当有四个不一样时分两种情况,
如果是恰好两对相互不一样,要移动6次,
如果四个混合的不一样则要移动5次。
Time Limit:500MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
URAL 1784
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
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
output
3
http://acm.timus.ru/problem.aspx?space=1&num=1784
分析:
题目意思
一副牌分成4堆,每堆13张牌,
每堆值从前至后为2-KA,牌色可能不一样。
现在可以有两种操作:
1.从一堆中顶开始拿同一花色的k张,组成新的一堆。
2、从一堆中顶开始那同一花色的k张,放到当前堆的上面,
要求是当前堆的第一张牌的值比要放堆的底的值大一。
问最少需要多少步操作,使得每一堆牌的花色一样。
解题思路:
模拟题+贪心思想。对于每一列,牌的值肯定相同,花色各不一样。
以最后一列为标准,从倒数第二列开始往前,
当当前列有两个不后面一列的花色不一样时,要移动3次,
当有三个不一样时要移动4次,注意当有四个不一样时分两种情况,
如果是恰好两对相互不一样,要移动6次,
如果四个混合的不一样则要移动5次。
#include <iostream> #include <sstream> #include <iomanip> #include <vector> #include <deque> #include <list> #include <set> #include <map> #include <stack> #include <queue> #include <bitset> #include <string> #include <numeric> #include <algorithm> #include <functional> #include <iterator> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <cctype> #include <complex> #include <ctime> #define INF 0x3f3f3f3f #define eps 1e-6 #define p(x) printf("%d\n", x) #define k(x) printf("Case %d: ", ++x) #define mes(x, d) memset(x, d, sizeof(x)) #define s(x) scanf("%d", &x) typedef long long LL; const double pi = acos(-1.0); const long long mod = 1e9 + 7; using namespace std; char s[4][100]; int main() { for(int i = 0;i < 4;i++) cin.getline(s[i],100); int ans = 0; for(int i = 34;i >= 1;i -= 3) { int t = 0; for(int j = 0;j < 4;j++) if(s[j][i] != s[j][i + 3]) t++; if(t == 0) continue; if(t < 4) ans += (t + 1); if(t == 4) { int ok = 1; for(int j = 1;j < 4;j++) { if(s[j][i] == s[0][i + 3]) { if(s[j][i + 3] == s[0][i]) ok = 1; else ok = 0; } } if(ok) ans += 6; else ans += 5; } } printf("%d\n",ans); return 0; }
相关文章推荐
- 如何让两个不同的app共享数据
- 2349 poj &&uva 10369 Arctic Network【最小生成树】
- Partition List
- hdu 2072 Java 单词数(超级坑) HDU 2072
- 类型转换
- Domino9 自动化运维
- NOJ1013 三角形判断(模拟)
- iOS 8 Xcode6 设置Launch Image 启动图片<转>
- Java并发编程实战笔记(二):对象的共享
- 网络协议层--<TCP/IP详解1>
- mysql-5.5.36怎么打开批处理功能? 2步搞定。
- 黑马程序员---关于取出一个字符串中字母个数的题目分析
- protuse8安装破解手记
- java GUI(实例项目--记事本)
- LINUX修改path环境变量
- JAVA环境变量配置
- 从一道面试题谈linux下fork的运行机制
- java GUI (菜单设计)
- 客户端如何访问访问oracle 12c 64位的数据库
- JAVA基础——常见数据结构简要