python实现ZOJ1745(简单模拟)
来源:互联网 发布:北京语言大学网络继续 编辑:程序博客网 时间:2024/06/06 02:19
我就直接贴代码了,代码上有具体的思路。
# -*- coding:utf-8 -*-'''每一行输入最少两个数最多21个数,且最后一步一定要到达饼干。每一行输入的第一个数是饼干所在的位置,且饼干的位置不能为0.输出有三种状态,输出什么状态,取决于这一次和上一次距离饼干的距离是否近了还是远了还是相同近了返回warmer远了返回colder如果相同则返回same如果输入的数字与饼干所在位置相同则输出found it!最后如果输入5280则代表程序结束'''import sysdef SearchCookie(): while True: num = sys.stdin.readline().split() CookiePos = int(num[0]) nowPos = int(num[1]) PastPos = 0 if CookiePos == 5280: return 0 i = 2 while True: NowGap = abs(nowPos-CookiePos) PastGap = abs(PastPos-CookiePos) if NowGap > PastGap: print 'Moving from %d to %d: colder.'%(PastPos,nowPos) elif NowGap < PastGap: print 'Moving from %d to %d: warmer.'%(PastPos,nowPos) else: print 'Moving from %d to %d: same.'%(PastPos,nowPos) PastPos = nowPos nowPos = int(num[i]) i = i + 1 if nowPos == CookiePos: print 'Moving from %d to %d: found it!'%(PastPos,nowPos) break if __name__ == '__main__': SearchCookie()
0 0
- python实现ZOJ1745(简单模拟)
- python实现简单爬虫模拟登录淘宝(cookie简介)
- 简单模拟实现hibernate
- 模拟实现简单Mystring
- Vector 简单模拟实现
- list简单模拟实现
- python实现模拟登录
- python实现模拟登录
- python实现模拟登录
- python实现模拟登录
- python实现模拟登录
- python实现模拟登录
- python实现模拟登录
- python实现模拟登录
- python简单模拟数据库程序
- Python 模拟简单的queue
- python简单模拟登陆详解
- python简单用户管理模拟
- 前端框架对页面的损害+如何判断一个dom是否存在某个属性
- 二叉树的链式结构实现
- new和malloc的区别
- POJ 3126--BFS
- 各银行网上支付接口 开通流程及所需材料 中、农、建、工
- python实现ZOJ1745(简单模拟)
- Java线程池使用说明
- 黑马程序员---Objective-C 三大特性---继承
- Node.js入门系列——Express.js安装
- MIT算法导论——第六讲.Order statistics and Median
- UVALive 4015 - Caves(树形DP)
- [授权发表]基于 VNCServer + noVNC 构建 Docker 桌面系统
- uCOS 中优先级判定表OSUnMapTbl原理
- 设计模式之装饰者(包装模式)模式