Are We There Yet? (zoj1745)

时间:2022-10-26 23:57:33

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&period;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. 【&period;net 深呼吸】细说CodeDom(5):类型成员

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

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

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

随机推荐

  1. 文件操作 fopen&lpar;&rpar; fclose&lpar;&rpar;

    #define _CRT_SECURE_NO_DEPRECATE /*取消scanf,printf不安全之类的错误提示*/ /* fopen example */ #include <stdio ...

  2. 1&period;BOM学习

    1.bom.html <html> <head> <title>bom演示</title> <script type="text/jav ...

  3. MongoDB 逻辑与操作

    看下面两个例子 rs1:PRIMARY> db.display.find({$and: [{$where: '(1386813645 - this.last_active_time > 3 ...

  4. LeetCode&lowbar;Convert Sorted List to Binary Search Tree

    Given a singly linked list where elements are sorted in ascending order, convert it to a height bala ...

  5. Java编程入门(词汇表)

    抽象类(abstract class):抽象类不能创建对象,主要用来创建子类.Java中的抽象类使用 abstract 修饰符定义. 抽象数据类型(abstract data type ADT):抽象 ...

  6. 免费V P N获取方式。

    给需要加速器链接国外网站的朋友, 打开网址:http://miaoaff.com/reg.php?id=204250: 用一个邮箱注册,就会得到一个免费的vpn软件账号(包含300M流量时间永久): ...

  7. &lbrack;No0000F4&rsqb;C&num; 枚举(Enum)

    枚举是一组命名整型常量.枚举类型是使用 enum 关键字声明的. C# 枚举是值数据类型.换句话说,枚举包含自己的值,且不能继承或传递继承. 声明 enum 变量 声明枚举的一般语法: enum &l ...

  8. vsphere和vmware快照的不足之处

    当快照创建时虚拟机执行一个读操作,hypervisor会检查快照VMDK,查看是否有被读取的区块存在.如果有,则从快照中为虚拟机提供这个区块,如果没有,虚拟机还需要去读取基础VMDK.如果只有一个快照 ...

  9. 各版本 MySQL 并行复制的实现及优缺点

    MySQL并行复制已经是老生常谈,笔者从2010年开始就着手处理线上这个问题,刚开始两三年也乐此不疲分享,现在再提这个话题本来是难免“炒冷饭”嫌疑. 最近触发再谈这个话题,是因为有些同学觉得“5.7的 ...

  10. 从高版本JDK换成低版本JDK报错Unsupported major&period;minor version 52&period;0的解决方案

    从高版本JDK换成低版本JDK报错Unsupported major.minor version 52.0 java.lang.UnsupportedClassVersionError: PR/Sor ...