Are We There Yet?    
(ZOJ Problem Set - 1745)

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!


Source: Southeast USA 2000
                                                           简单模拟题
  对于初学者几个需要注意的地方:
 一:绝对值使用abs,需要math函数或者判断大小后做差;
二:固定格式输出时,使用printf比较方便而且不容易出错。
三:根据题目要求,最后一组数据后不能加换行符,不然会PE,需要转化思路。在除第一组数据前加换行符。
四:题目中最后一些数据在代码中不必考虑,指的是5280 后面那个10.而如果后面还有数据,则可以用字符串读取一整行


#include<cstdio>

#include<cstdlib>

#include<iostream>

#include<math.h>

using namespace std;

int s;

void _in()

{

int fr=0,num;

while(cin>>num)

{

if(num==s) {

printf("Moving from %d to %d: found it!\n",fr,num);

return ;

}

else if(abs(fr-s)>abs(num-s))printf("Moving from %d to %d: warmer.\n",fr,num);

else if(abs(fr-s)<abs(num-s))printf("Moving from %d to %d: colder.\n",fr,num);

else if(abs(fr-s)==abs(num-s))printf("Moving from %d to %d: same.\n",fr,num);

fr=num;

}

}

int main()

{

int flag=0;

while(cin>>s&&s<5280){

if(flag++) printf("\n");

_in();

}

return 0;

}//注意格式









Are We There Yet? (zoj1745)的更多相关文章

  1. Angular2入门系列教程7-HTTP(一)-使用Angular2自带的http进行网络请求

    上一篇:Angular2入门系列教程6-路由(二)-使用多层级路由并在在路由中传递复杂参数 感觉这篇不是很好写,因为涉及到网络请求,如果采用真实的网络请求,这个例子大家拿到手估计还要自己写一个web ...

  2. Angular2学习笔记(1)

    Angular2学习笔记(1) 1. 写在前面 之前基于Electron写过一个Markdown编辑器.就其功能而言,主要功能已经实现,一些小的不影响使用的功能由于时间关系还没有完成:但就代码而言,之 ...

  3. ASP.NET Core 之 Identity 入门(一)

    前言 在 ASP.NET Core 中,仍然沿用了 ASP.NET里面的 Identity 组件库,负责对用户的身份进行认证,总体来说的话,没有MVC 5 里面那么复杂,因为在MVC 5里面引入了OW ...

  4. ABP入门系列(1)——学习Abp框架之实操演练

    作为.Net工地搬砖长工一名,一直致力于挖坑(Bug)填坑(Debug),但技术却不见长进.也曾热情于新技术的学习,憧憬过成为技术大拿.从前端到后端,从bootstrap到javascript,从py ...

  5. Online Judge(OJ)搭建(第一版)

    搭建 OJ 需要的知识(重要性排序): Java SE(Basic Knowledge, String, FileWriter, JavaCompiler, URLClassLoader, Secur ...

  6. 如何一步一步用DDD设计一个电商网站(九)—— 小心陷入值对象持久化的坑

    阅读目录 前言 场景1的思考 场景2的思考 避坑方式 实践 结语 一.前言 在上一篇中(如何一步一步用DDD设计一个电商网站(八)—— 会员价的集成),有一行注释的代码: public interfa ...

  7. 如何一步一步用DDD设计一个电商网站(八)—— 会员价的集成

    阅读目录 前言 建模 实现 结语 一.前言 前面几篇已经实现了一个基本的购买+售价计算的过程,这次再让售价丰满一些,增加一个会员价的概念.会员价在现在的主流电商中,是一个不大常见的模式,其带来的问题是 ...

  8. 【.net 深呼吸】细说CodeDom(5):类型成员

    前文中,老周已经厚着脸皮介绍了类型的声明,类型里面包含的自然就是类型成员了,故,顺着这个思路,今天咱们就了解一下如何向类型添加成员. 咱们都知道,常见的类型成员,比如字段.属性.方法.事件.表示代码成 ...

  9. 【.net 深呼吸】细说CodeDom(4):类型定义

    上一篇文章中说了命名空间,你猜猜接下来该说啥.是了,命名空间下面就是类型,知道了如何生成命名空间的定义代码,之后就该学会如何声明类型了. CLR的类型通常有这么几种:类.接口.结构.枚举.委托.是这么 ...

随机推荐

  1. 算法学习:并行化初体验_JAVA实现并行化归并算法

    这个系列包括算法导论学习过程的记录. 最初学习归并算法,对不会使其具体跑在不同的核上报有深深地怨念,刚好算倒重温了这个算法,闲来无事,利用java的thread来体验一下并行归并算法.理论上开的thr ...

  2. swing-窗体添加背景图片的2种方法

    在美化程序时,常常需要在窗体上添加背景图片.通过搜索和测试,发现了2种有效方式.下面分别介绍.1.利用JLabel加载图片利用JLabel自带的setIcon(Icon icon)加载icon,并设置 ...

  3. Java学习10——package和import

    package和import语句 为了便于管理大型软件系统中数目众多的类,解决类的命名冲突问题,Java引入包(package)机制,提供类的多重类命名空间,使用时,import引入相应package ...

  4. 201521123013 《Java程序设计》第6周学习总结

    1. 本章学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想进行一个总结. 2. 书面作业 Q1.clone方法 1.1 Object ...

  5. 201521123035《Java程序设计》第十四周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多数据库相关内容. 2. 书面作业 1. MySQL数据库基本操作 建立数据库,将自己的姓名.学号作为一条记录插入.(截图,需出现自 ...

  6. JAVA课程设计---学生基本信息管理系统(201521123039 王兴)

    1.团队课程设计博客链接 http://www.cnblogs.com/zyjjj/p/7061880.html 2.个人负责模块或任务说明 函数 功能说明 Search 查找学生信息,分为两种查找方 ...

  7. 201521123060 《Java程序设计》第10周学习总结

    1.本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常与多线程相关内容. 异常: 1.不要乱用异常: 2.异常发生时:确定异常类型,异常位置: 3.尽量使用已有的异常类. 多线程: 2 ...

  8. java课程设计---计算器(201521123020 邱伟达)

    1.团队课程设计博客链接 http://www.cnblogs.com/br0823/p/7064407.html 2.个人负责模板或任务说明 1.初始化按键 2.实现加减乘除开方乘方等运算 3.每个 ...

  9. thymeleaf模板引擎调用java类中的方法(附源码)

    前言 <Docker+SpringBoot+Mybatis+thymeleaf的Java博客系统开源啦> 由于开源了项目的缘故,很多使用了My Blog项目的朋友遇到问题也都会联系我去解决 ...

  10. response 常用详解(1)

    我们在创建Servlet时会覆盖service()方法,或doGet()/doPost(),这些方法都有两个参数,一个为代表请求的request和代表响应response. service方法中的re ...