Are We There Yet? (zoj1745)
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
#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)的更多相关文章
- Angular2入门系列教程7-HTTP(一)-使用Angular2自带的http进行网络请求
上一篇:Angular2入门系列教程6-路由(二)-使用多层级路由并在在路由中传递复杂参数 感觉这篇不是很好写,因为涉及到网络请求,如果采用真实的网络请求,这个例子大家拿到手估计还要自己写一个web ...
- Angular2学习笔记(1)
Angular2学习笔记(1) 1. 写在前面 之前基于Electron写过一个Markdown编辑器.就其功能而言,主要功能已经实现,一些小的不影响使用的功能由于时间关系还没有完成:但就代码而言,之 ...
- ASP.NET Core 之 Identity 入门(一)
前言 在 ASP.NET Core 中,仍然沿用了 ASP.NET里面的 Identity 组件库,负责对用户的身份进行认证,总体来说的话,没有MVC 5 里面那么复杂,因为在MVC 5里面引入了OW ...
- ABP入门系列(1)——学习Abp框架之实操演练
作为.Net工地搬砖长工一名,一直致力于挖坑(Bug)填坑(Debug),但技术却不见长进.也曾热情于新技术的学习,憧憬过成为技术大拿.从前端到后端,从bootstrap到javascript,从py ...
- Online Judge(OJ)搭建(第一版)
搭建 OJ 需要的知识(重要性排序): Java SE(Basic Knowledge, String, FileWriter, JavaCompiler, URLClassLoader, Secur ...
- 如何一步一步用DDD设计一个电商网站(九)—— 小心陷入值对象持久化的坑
阅读目录 前言 场景1的思考 场景2的思考 避坑方式 实践 结语 一.前言 在上一篇中(如何一步一步用DDD设计一个电商网站(八)—— 会员价的集成),有一行注释的代码: public interfa ...
- 如何一步一步用DDD设计一个电商网站(八)—— 会员价的集成
阅读目录 前言 建模 实现 结语 一.前言 前面几篇已经实现了一个基本的购买+售价计算的过程,这次再让售价丰满一些,增加一个会员价的概念.会员价在现在的主流电商中,是一个不大常见的模式,其带来的问题是 ...
- 【.net 深呼吸】细说CodeDom(5):类型成员
前文中,老周已经厚着脸皮介绍了类型的声明,类型里面包含的自然就是类型成员了,故,顺着这个思路,今天咱们就了解一下如何向类型添加成员. 咱们都知道,常见的类型成员,比如字段.属性.方法.事件.表示代码成 ...
- 【.net 深呼吸】细说CodeDom(4):类型定义
上一篇文章中说了命名空间,你猜猜接下来该说啥.是了,命名空间下面就是类型,知道了如何生成命名空间的定义代码,之后就该学会如何声明类型了. CLR的类型通常有这么几种:类.接口.结构.枚举.委托.是这么 ...
随机推荐
- Spring详解(五)------AspectJ 实现AOP
上一篇博客我们引出了 AOP 的概念,以及 AOP 的具体实现方式.但是为什么要这样实现?以及提出的切入点表达式到底该怎么理解? 这篇博客我们通过对 AspectJ 框架的介绍来详细了解. 1.什么是 ...
- [UWP]理解及扩展Expander
##1. 前言 最近在自定义Expander的样式,顺便看了看它的源码. Expander控件是一个ContentControl,它通过IsExpanded属性或者通过点击Header中的Toggle ...
- 【DDD】领域驱动设计实践 —— 业务建模小招数
本文结合团队在ECO(社区服务系统)业务建模过程中的实践经验,总结得到一些DDD业务建模的小招数,不一定是完美的,但是对我们团队来说很有效用,希望能帮到其他人.后面会陆续将项目中业务建模的一些经典例子 ...
- PHP初入--表单元素
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...
- 201521123045 《Java程序设计》第7周学习总结
Java 第七周总结 1. 本周学习总结 2. 书面作业 1.ArrayList代码分析 1.1 解释ArrayList的contains源代码 public boolean contains(Obj ...
- 201521123033《Java程序设计》第1周学习总结
1. 本周学习总结 (1)了解了JVM,JRE,JDK (2)配置java环境变量 (3)编译一些简单的java代码 2. 书面作业 为什么java程序可以跨平台运行?执行java程序的步骤是什么?( ...
- 201521123048 《Java程序设计》第12周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 书面作业 将Student对象(属性:int id, String name,int age,doubl ...
- Selenium+Python自动化测试实战(2)元素定位
1.Selenium2 的原理 第一篇分享简单介绍了基于Python开发的Selenium2的环境配置,这篇主要讲一下基本用法.首先讲一下Selenium2的基本原理.基本上知道了这个东西是怎么回事, ...
- [13] static 和 final
不论是类.属性,还是方法的声明中,都有一个可设置的"修饰符",它可以实现一些高级特性. 1.static static被称之为静态的,并不是指不可以修改的意思,而是说它的内存空间是 ...
- java控制台输入输出
一.比较传统的输入方法用输入流,得到字符串后要另行判断.转换 案例 import java.io.BufferedReader; import java.io.IOException; import ...