nyoj 204-Coin Test (python count)
204-Coin Test
内存限制:64MB
时间限制:3000ms
特判: No
通过数:2
提交数:2
难度:1
题目描述:
As is known to all,if you throw a coin up and let it droped on the desk there are usually three results. Yes,just believe what I say ~it can be the right side or the other side or standing on the desk, If you don't believe this,just try In the past there were some famous mathematicians working on this .They repeat the throwing job once again. But jacmy is a lazy boy.He is busy with dating or playing games.He have no time to throw a single coin for 100000 times. Here comes his idea,He just go bank and exchange thousands of dollars into coins and then throw then on the desk only once. The only job left for him is to count the number of coins with three conditions.
He will show you the coins on the desk to you one by one. Please tell him the possiblility of the coin on the right side as a fractional number if the possiblity between the result and 0.5 is no larger than 0.003. BE CAREFUL that even 1/2,50/100,33/66 are equal only 1/2 is accepted ! if the difference between the result and 0.5 is larger than 0.003,Please tell him "Fail".Or if you see one coin standing on the desk,just say "Bingo" any way.
输入描述:
Three will be two line as input.
The first line is a number N(1<N<65536)
telling you the number of coins on the desk.
The second line is the result with N litters.The letter are "U","D",or "S","U" means the coin is on the right side. "D" means the coin is on the other side ."S" means standing on the desk.
输出描述:
If test successeded,just output the possibility of the coin on the right side.If the test failed please output "Fail",If there is one or more"S",please output "Bingo"
样例输入:
6
UUUDDD
样例输出:
1/2
python AC:
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b) n = int(input())
my_str = input()
u = my_str.count("U")
d = my_str.count("D")
s = my_str.count("S") if s >= 1:
print("Bingo")
else:
total = u + d
ans = float(u) / float(total)
if 0.497 <= ans <= 0.503:
temp = gcd(u, total)
print("%d/%d" % (u / temp, total / temp))
else:
print("Fail")
nyoj 204-Coin Test (python count)的更多相关文章
- nyoj 241-字母统计 (python count)
241-字母统计 内存限制:64MB 时间限制:3000ms 特判: No 通过数:12 提交数:14 难度:1 题目描述: 现在给你一个由小写字母组成字符串,要你找出字符串中出现次数最多的字母,如果 ...
- python count函数
描述 Python count() 方法用于统计字符串里某个字符出现的次数.可选参数为在字符串搜索的开始与结束位置. 语法 count()方法语法: str.count(sub, start= 0,e ...
- python count()
count() 描述 Python count() 方法用于统计字符串里某个字符出现的次数.可选参数为在字符串搜索的开始与结束位置. 语法 count()方法语法: str.count(sub, st ...
- Python Count函数的应用
Python Count函数的应用 通过LeetCode Origin:https://leetcode-cn.com/problems/robot-return-to-origin/ 学会了Pyth ...
- nyoj 268-荷兰国旗问题 (count)
268-荷兰国旗问题 内存限制:64MB 时间限制:3000ms 特判: No 通过数:15 提交数:20 难度:1 题目描述: 荷兰国旗有三横条块构成,自上到下的三条块颜色依次为红.白.蓝.现有若干 ...
- python count()函数
Python 元组 count() 方法用于统计某个元素在元祖,列表,字符串中出现的次数.可选参数为在字符串搜索的开始与结束位置. 参数 sub -- 搜索的子字符串 start -- 字符串开始搜索 ...
- python Count类(转)
1.collections模块 collections模块自Python 2.4版本开始被引入,包含了dict.set.list.tuple以外的一些特殊的容器类型,分别是: OrderedDict类 ...
- Python count() 方法
描述 count() 方法用于统计字符串中某个子字符串出现的次数,可选参数为开始搜索与结束搜索的位置索引. 语法 count() 方法语法: S.count(sub[,start=0[,end=len ...
- nyoj 517-最小公倍数 (python range(start, end) range(length))
517-最小公倍数 内存限制:64MB 时间限制:1000ms 特判: No 通过数:2 提交数:11 难度:3 题目描述: 为什么1小时有60分钟,而不是100分钟呢?这是历史上的习惯导致. 但也并 ...
随机推荐
- [Luogu2967] 视频游戏的麻烦Video Game Troubles
农夫约翰的奶牛们游戏成瘾!本来约翰是想要按照调教兽的做法拿她们去电击戒瘾的,可是 后来他发现奶牛们玩游戏之后比原先产更多的奶.很明显,这是因为满足的牛会产更多的奶. 但是,奶牛们在哪个才是最好的游 ...
- [JZOJ5818] 【NOIP提高A组模拟2018.8.15】 做运动
Description 一天,Y 君在测量体重的时候惊讶的发现,由于常年坐在电脑前认真学习,她的体重有了突 飞猛进的增长. 幸好 Y 君现在退役了,她有大量的时间来做运动,她决定每天从教学楼跑到食堂来 ...
- ES6入门之变量的解构赋值(二)
前言 在上一章 ES6入门之let和const命令中我们对ES6的相关语法已经有了初步了解,上一章中我们主要学习了三大部分的内容,let命令的使用,块级作用域,const命令的使用,那么从本篇博客将进 ...
- Go语言系列开发之延迟调用和作用域
Hello,各位小伙伴大家好,我是小栈君,最近一段时间我们将继续分享关于go语言基础系列,当然后期小栈君已经在筹划关于java.Python,数据分析.人工智能和大数据等相关系列文章.希望能和大家一起 ...
- Chrome 浏览器垃圾回收机制与内存泄漏分析
Chorme 浏览器中的垃圾回收和内存泄漏 垃圾回收 通常情况下,垃圾数据回收分为手动回收和自动回收两种策略. 手动回收策略,何时分配内存.何时销毁内存都是由代码控制的. 自动回收策略,产生的垃圾数据 ...
- 第三方软件 radmin提权
一款远控工具 端口扫描 4899 端口 上传 radmin.asp 木马读取 radmin的加密密文 下载radmin工具连接
- java-反编译工具(luyten)
下载地址:https://github.com/deathmarine/Luyten
- 1.在ubuntu中软件安装在哪里?
ubuntu下安装软件有四种方式: 1.通过deb格式的离线软件包安装 sudo dpkg -i xxx.deb # 安装包,安装程序 -i: install sudo dpkg -r packa ...
- 1,下载和部署开发环境--AutoCAD二次开发
环境需求为: AutoCAD 2020版 ObjectARX SDK 下载地址:https://www.autodesk.com/developer-network/platform-technolo ...
- 百万年薪python之路 -- 装饰器
装饰器 1.1 开放封闭原则 开放封闭原则具体定义是这样: 1.对扩展是开放的 我们说,任何一个程序,不可能在设计之初就已经想好了所有的功能并且未来不做任何更新和修改.所以我们必须允许代码扩展.添加新 ...