博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
zoj 1745 Are We There Yet?
阅读量:2441 次
发布时间:2019-05-10

本文共 3315 字,大约阅读时间需要 11 分钟。

Are We There Yet?

Time Limit: 2 Seconds      
Memory Limit: 65536 KB

Laurie's little brother Joey has been playing Find the Cookie with her. However, after the 32,767th time, Laurie is tired of it. She wants to write a program to keep the boy occupied. Write a program to simulate a game of Find the Cookie. The game takes place in a long narrow hall, so Joey can only move forward and backward, not right or left. At the beginning of each game, a cookie is placed in the hall (not at the center of the hall) and Joey starts at the center of the hall. Joey attempts to find the cookie. He does this by moving to another point in the hall, whereupon the computer tells him whether he is "warmer" (he has moved closer to the cookie than his last position), "colder" (he has moved farther away from the cookie than his last position), "same" (he has not moved closer or farther away from the cookie), or he has reached the cookie. Joey continues until he exactly reaches the location of the cookie, which always happens within 20 moves. 



Input


Each input line represents a new game. Each input line contains at least two and at most 21 integers separated by whitespace. The integers represent locations along the hall, expressed in units of feet. Joey begins each game at location 0 feet. The first integer on an input line is the location of the cookie. This integer is guaranteed to be different from 0. The remaining integers represent locations Joey moves to, in order. Joey will never move more than 5280 feet from his original location. Joey will always reach the cookie in each game, and this will be the last move on the input line. Your program should stop processing input lines when the cookie is located at 5280 feet (a mile from the center of the hall is way too far for Joey to go for only one cookie).



Output


For each location that Joey moves to, determine whether he is warmer, colder, the same, or has reached the cookie. Have a blank line between the output for different input lines. Follow the format in the Sample Output.



Sample Input


5 10 11 12 3 4 5

3 10 10 7 3

12 5 -3 1 4 6 7 8 9 12

5280 10



Sample Output

Moving from 0 to 10: same.

Moving from 10 to 11: colder.

Moving from 11 to 12: colder.

Moving from 12 to 3: warmer.

Moving from 3 to 4: warmer.

Moving from 4 to 5: found it!


Moving from 0 to 10: colder.

Moving from 10 to 10: same.

Moving from 10 to 7: warmer.

Moving from 7 to 3: found it!


Moving from 0 to 5: warmer.

Moving from 5 to -3: colder.

Moving from -3 to 1: warmer.

Moving from 1 to 4: warmer.

Moving from 4 to 6: warmer.

Moving from 6 to 7: warmer.

Moving from 7 to 8: warmer.

Moving from 8 to 9: warmer.

Moving from 9 to 12: found it!

注意看输出格式

参考代码:

#include 
#include
using namespace std;int abs(int a){ if (a>0) return a; return -a;}int main(){ int first,second,flag=0,last,location; while (~scanf("%d",&location)){ if (location==5280){ while (~scanf("%d",&second)); break; } if (flag++) printf("\n"); first=0; while (~scanf("%d",&second)){ if (second==location){ printf("Moving from %d to %d: found it!\n",first,second); break; } else{ int l=abs(second-location),r=abs(first-location); if (l>r) printf("Moving from %d to %d: colder.\n",first,second); if (l==r) printf("Moving from %d to %d: same.\n",first,second); if (l

转载地址:http://gfbqb.baihongyu.com/

你可能感兴趣的文章
linux中crontab命令(转)
查看>>
牛人请进 小弟跪求(转)
查看>>
Linux版本凌乱痛失市场(转)
查看>>
大家好,新学生。 请问怎么升级Redhat9.0 kernel 2.4.X-->2.6.18 的详细过程(转)
查看>>
FreeBSD6.1+无线+永中......桌面安装【附笔记】(转)
查看>>
adsl设置(转)
查看>>
Wii将有一个可升级的Linux操作系统(转)
查看>>
Linux机为先锋智能机和PDA06销量大(转)
查看>>
Oracle与SQL Server在企业应用中的比较(转)
查看>>
Unix类操作系统入门(转)
查看>>
让FreeBSD使用ntpd同步时间(转)
查看>>
用cat命令查看文件内的特殊字符(转)
查看>>
debian sid下vmware不能运行一则(转)
查看>>
Linux操作系统套接字编程的5个隐患(转)
查看>>
Ubuntu Linux:定制Ubuntu安装CD(转)
查看>>
调查显示:企业级Linux用户不断攀升(转)
查看>>
Ubuntu/Linux入门介绍-dpkg(转)
查看>>
SCO UNIX学习宝典 高级进阶(转)
查看>>
Oracle9i RAC for RedFlag Linux DC4.1 32bit 安装流程(转)
查看>>
Sybase和Oracle安装过程中常遇到的问题(转)
查看>>