ACM学习历程—Hihocoder 1177 顺子(模拟 && 排序 && gcd)(hihoCoder挑战赛12)
时间限制:6000ms
单点时限:1000ms
内存限制:256MB
描述
你在赌场里玩梭哈,已经被发了4张牌,现在你想要知道发下一张牌后你得到顺子的概率是多少?
假定赌场使用的是一副牌,四种花色的A、2、3、...、J、Q、K共52张,这副牌只发给你了4张,你的剩下一张牌从剩下48张中任意取出一张。
顺子指的是点数连续的五张牌,包括10、J、Q、K、A这种牌型(不包含同花顺,即构成顺子的五张牌花色不能相同)。参见:https://zh.wikipedia.org/wiki/%E6%92%B2%E5%85%8B%E7%89%8C%E5%9E%8B#.E7.89.8C.E5.9E.8B
输入
一行四个被空格隔开的长度为2或3的字符串,XY,表示你手里的牌。
X为2~10、J、Q、K、A中一个,表示点数,Y为S、H、C、D分别表示黑桃、红心、梅花和方块。
输出
一行一个分数表示概率,注意你的分数需为最简分数,若答案为0输出0/1。
样例输入
10S JS QS KD
样例输出
1/6
题目是个模拟,只用暴力枚举每一张牌即可。
最后答案gcd处理公约数以后输出。
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#define LL long long using namespace std; struct Card
{
int num;
char kind;
}; bool cmp(Card a, Card b)
{
return a.num < b.num;
} struct node
{
Card card[];
}my; int ans; //GCD
//求最大公约数
//O(logn)
int gcd(int a, int b)
{
if (b == )
return a;
else
return gcd(b, a%b);
} bool input()
{
char str[];
for (int i = ; i < ; ++i)
{
if (scanf("%s", str) == EOF)
return false;
if (strlen(str) == )
{
if ('' <= str[] && str[] <= '')
my.card[i].num = str[] - '';
else if (str[] == 'A')
my.card[i].num = ;
else if (str[] == 'J')
my.card[i].num = ;
else if (str[] == 'Q')
my.card[i].num = ;
else if (str[] == 'K')
my.card[i].num = ;
my.card[i].kind = str[];
}
else
{
my.card[i].num = ;
my.card[i].kind = str[];
}
}
return true;
} bool judge(node t)
{
if (t.card[].kind == t.card[].kind &&
t.card[].kind == t.card[].kind &&
t.card[].kind == t.card[].kind &&
t.card[].kind == t.card[].kind)
return false;
sort(t.card, t.card+, cmp);
if (t.card[].num+ == t.card[].num &&
t.card[].num+ == t.card[].num &&
t.card[].num+ == t.card[].num &&
t.card[].num+ == t.card[].num)
return true;
if (t.card[].num == &&
t.card[].num+ == t.card[].num &&
t.card[].num+ == t.card[].num &&
t.card[].num+ == t.card[].num &&
t.card[].num == )
return true;
return false;
} void work()
{
ans = ;
for (int i = ; i <= ; ++i)
{
my.card[].num = i;
my.card[].kind = 'S';
ans += judge(my);
my.card[].kind = 'H';
ans += judge(my);
my.card[].kind = 'C';
ans += judge(my);
my.card[].kind = 'D';
ans += judge(my);
}
int d = gcd(ans, );
if (ans == )
printf("0/1\n");
else
printf("%d/%d\n", ans/d, /d);
} int main()
{
//freopen("test.in", "r", stdin);
while (input())
{
work();
}
return ;
}
ACM学习历程—Hihocoder 1177 顺子(模拟 && 排序 && gcd)(hihoCoder挑战赛12)的更多相关文章
- hihocoder #1177 : 顺子 模拟
#1177 : 顺子 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/problemset/problem/1177 ...
- ACM学习历程——HDU4472 Count(数学递推) (12年长春区域赛)
Description Prof. Tigris is the head of an archaeological team who is currently in charge of an exca ...
- 模拟 hihoCoder 1177 顺子
题目传送门 /* 模拟:简单的照着规则做就可以了,把各种情况考虑到,虽然比赛写的丑了点,但能1Y还是很开心的:) */ #include <cstdio> #include <cst ...
- ACM学习历程—Hihocoder 1233 Boxes(bfs)(2015北京网赛)
hihoCoder挑战赛12 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There is a strange storehouse in PKU. In this ...
- hihocoder 1177 : 顺子
#1177 : 顺子 时间限制:6000ms 单点时限:1000ms 内存限制:256MB 描述 你在赌场里玩梭哈,已经被发了4张牌,现在你想要知道发下一张牌后你得到顺子的概率是多少? 假定赌场使用的 ...
- ACM学习历程—Hihocoder 1289 403 Forbidden(字典树 || (离线 && 排序 && 染色))
http://hihocoder.com/problemset/problem/1289 这题是这次微软笔试的第二题,过的人比第三题少一点,这题一眼看过去就是字符串匹配问题,应该可以使用字典树解决.不 ...
- ACM学习历程—HihoCoder1309任务分配(排序 && 贪心)
http://hihocoder.com/problemset/problem/1309 题目大意是给定n个任务的起始时间,求问最少需要多少台机器. 有一个贪心的策略就是,如果说对于一个任务结束,必然 ...
- ACM学习历程—HDU5700 区间交(树状数组 && 前缀和 && 排序)
http://acm.hdu.edu.cn/showproblem.php?pid=5700 这是这次百度之星初赛2B的第五题.省赛回来看了一下,有这样一个思路:对于所有的区间排序,按左值排序. 然后 ...
- ACM学习历程—Hihocoder [Offer收割]编程练习赛1
比赛链接:http://hihocoder.com/contest/hihointerview3/problem/1 大概有一个月没怎么打算法了.这一场的前一场BC,也打的不是很好.本来Div1的A和 ...
随机推荐
- Python模拟登录12306
#!/usr/bin/python # -*- coding: utf-8 -*- import re; import sys; import cookielib; import urllib; im ...
- spring4 maven3 mybatis
1 新建maven工程 http://www.cnblogs.com/quanyongan/archive/2013/04/21/3033838.html 如果在第三步中出现错误,比如类似: Coul ...
- python爬虫入门篇
优质爬虫入门源码:https://github.com/lining0806/PythonSpiderNotes Python Spider:https://www.cnblogs.com/wangy ...
- PageHelper
https://pagehelper.github.io/ Mybatis分页插件PageHelper简单使用 SpringBoot之分页PageHelper
- [转] 盘点8种CSS实现垂直居中水平居中的绝对定位居中技术
转自:http://blog.csdn.net/freshlover/article/details/11579669 Ⅰ.绝对定位居中(Absolute Centering)技术 我们经常用marg ...
- HttpModule与HttpHandler详解(转)
ASP.NET对请求处理的过程:当请求一个*.aspx文件的时候,这个请求会被inetinfo.exe进程截获,它判断文件的后缀(aspx)之后,将这个请求转交给 ASPNET_ISAPI.dll,A ...
- iOS10.3 UILable中划线失效问题
iOS10.3系统的一个Bug,在UILable中含有中文时,中划线会失效 NSString *priceStr = [NSString stringWithFormat:@"%.2f元&q ...
- 【题解】Codeforces 961G Partitions
[题解]Codeforces 961G Partitions cf961G 好题啊哭了,但是如果没有不小心看了一下pdf后面一页的提示根本想不到 题意 已知\(U=\{w_i\}\),求: \[ \s ...
- Pentaho BIServer Community Edtion 6.1 使用教程 第三篇 发布和调度Kettle(Data Integration) 脚本 Job & Trans
Pentaho BIServer Community Edtion 6.1 集成了 Kettle 组件,可以运行Kettle 程序脚本.但由于Kettle没有直接发布到 BIServer-ce 服务的 ...
- 应用程序无法启动(0*c000007b)
2个插件就解决 一个是DX缺失工具检查那个 一个是运行库缺失检查