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. C# WinForm 跨线程访问控件

    问题出现: 在WinForm 处理多线程访问主线程的控件时候,就会出现如图所示的错误对话框:    解决方案:  方案一:去掉线程访问主线程UI控件的安全检查,使用: Control.CheckFor ...

  2. 交换机的Ethernet Channel

    端口聚合也叫做以太通道(ethernet channel),主要用于交换机之间连接.由于两个交换机之间有多条冗余链路的时候,STP会将其中的几条链路关闭,只保留一条,这样可以避免二层的环 路产生.但是 ...

  3. Sublime Text编辑器如何隐藏顶部的菜单栏

    隐藏前: 解决办法: 1.按住Ctrl+Shifp+p,出现一个框,在框里输入“view:”,出现了如下界面 2.选择:“View:Toggle Menu”即可.结果为: 大功告成!!!!

  4. We Talk -- 团队博客

    WeTalk --在线群聊程序 团队博客 服务器一直在运行,使用客户端可直接登入使用.(做得很粗糙...) 客户端下载(java环境下直接运行) 0.项目介绍 现在我们网上交流离不开微信和QQ,当然在 ...

  5. page分页类

    <?php /** file: Page.class.php 完美分页类 Page */ class Page { private $total; //数据表中总记录数 private $lis ...

  6. Java:类类型变量

    在java中有一种被称为类类型的变量,它不同于基本类型变量存储值的方式.不管是基本变量还是类类型变量,都实现为一个内存位置.但是,由于基本变量所需的内存数量是相同的,所以系统可以给它设置一个固定的空间 ...

  7. hadoop运行wordcount实例,hdfs简单操作

    1.查看hadoop版本 [hadoop@ltt1 sbin]$ hadoop version Hadoop -cdh5.12.0 Subversion http://github.com/cloud ...

  8. Jquery基础添加删除内容

    直入主题,工作中比较常用的功能在input框内添加内容,不白话了,上代码! 布局: <div id="content"> <input type="te ...

  9. php使用ZipArchive压缩文件的心得

    $zip=new ZipArchive; if($zip->open('test.zip',ZipArchive::CREATE)===TRUE){ $zip->addFile('imag ...

  10. [5] 微信公众号开发 - 微信支付功能开发(网页JSAPI调用)

    1.微信支付的流程 如下三张手机截图,我们在微信网页端看到的支付,表面上看到的是 "点击支付按钮 - 弹出支付框 - 支付成功后出现提示页面",实际上的核心处理过程是: 点击支付按 ...