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. Linux Centos 6.9中SSH默认端口修改的坑

    关于Linux Centos6.5的SSH默认端口修改的博客有一大堆,我在这里就不啰嗦了,但是面对Centos 6.9,就会发现有一个巨坑: 修改iptables之后执行下面的命令后: # servi ...

  2. 关于SCSI/SATA/IDE硬盘的比较

    看linux的书时,发现许多地方提到SCSI/SATA/IDE这几种硬盘接口,对这些硬盘的概念和区别感到很模糊.所以特意查了一些资料,基本上算是弄懂了他们的区别. 目前硬盘最要分为3种.也即:IDE. ...

  3. 团队作业4——第一次项目冲刺(Alpha版本) Day3

    1.由于大家课程都比较多,时间紧迫,今天最后一节课下课完在教室召开了简短的站立式会议,会议照片如下: 2.Leangoo任务分解图: 3.每个人的工作: 队员 今天已完成的工作 明天计划完成的工作 林 ...

  4. 201521123060 《Java程序设计》第5周学习总结

    1.本周学习总结 2.书面作业 Q1.代码阅读:Child压缩包内源代码 1.1 com.parent包中Child.java文件能否编译通过?哪句会出现错误?试改正该错误.并分析输出结果. 答:不能 ...

  5. 201521123093 java 第十周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常与多线程相关内容. Runnable不是线程,Thread才是,必须将实现Runnable接口的类的对象放入Thread中才能在 ...

  6. 201521123036 《Java程序设计》第14周学习总结

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

  7. 201521123002《Java程序设计》第12周学习总结

    本次作业参考文件 正则表达式参考资料 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. FileinputStream,FileoutputStream //字 ...

  8. php memcache 扩展 php -m 与 phpinfo() 不同

    事情起因,因要升级 openssl(openssl升级这里不表) ,所以在升级后对 php 也进行了从新编译,编译成功. 发现没有安装,memcache 扩展,从新编译安装了一下,显示的安装成功,但是 ...

  9. JS严格模式

    如何开启严格模式? 在js中,只需要在顶部添加"use strict",即可进入严格模式 在函数中加上"use strict"编辑指示,也可以指定函数在严格模式 ...

  10. mysql数据库-初始化sql建库建表-关联查询投影问题

    下面是一个简易商城的几张表的创建方式 drop database if exists shop ; create database shop CHARACTER SET 'utf8' COLLATE ...