UVA 573 The Snail
2016-07-14 22:27
429 查看
UVA-573
题意:蜗牛白天往上爬,晚上往下滑,并且每天往上爬的距离会按第一天的一定比例递减,求蜗牛能不能爬出去,能爬出去是在第几天,不能的话在第几天触底。解题思路:暴力模拟,白天爬完判断出没出去,晚上下滑判断触没触底,爬出去的条件是爬的高度 > h。触底条件是爬的高度 < 0。白天爬高的距离最小是0,不会负的。
/************************************************************************* > File Name: UVA-573.cpp > Author: Narsh > > Created Time: 2016年07月14日 星期四 15时12分33秒 ************************************************************************/ #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; int h,u,d,f; int main () { while (scanf("%d%d%d%d",&h,&u,&d,&f) && h+u+d+f) { double l = u, now = u; int day=0; while (l >= 0) { day++; if ( l > h ) break; l -= d; now = now - (double) f/100.0 * (u*1.00); if (now < 0) now = 0; if (l < 0) break; l += now; } if (l > h) printf("success on day %d\n",day); else printf("failure on day %d\n",day); } }
相关文章推荐
- MainWindows
- Numpy ConfigParser.MissingSectionHeaderError: File contains no section headers.
- Raid技术白皮书(强烈推荐)
- Email邮件头揭密
- codeforces 360 D - Remainders Game
- RAID 概述
- Flex桌面AIR软件日志添加
- a:focus,input:focus{ -webkit-tap-highlight-color:rgba(0,0,0,0); -webkit-user-modify:read-write-plaintext-only;} a选中高亮显示
- Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other.
- The working copy"XXX" failed to commit files
- 人工智能的革命:道德可以被编程么?
- Aizu 2677 Breadth-First Search by Foxpower LCA+bfs
- SetupDiGetDeviceInterfaceDetail
- Winform线程间操作无效从不是创建控件的线程访问它的几个解决方案async和await?
- hdu 1789 Doing Homework again
- AIS原始数据
- Climbing Stairs
- 正则表达式用户名密码电话身份证Email使用
- OpenJ_Bailian 4081 树的转换 数据结构
- No grammar constraints (DTD or XML schema).....解决方法