C. Tourist's Notes
题意:n天内登山,相邻两次登山的高度差的绝对值小于等于1,也就是说每次高度变化只能是:0,1,-1.我们已经知道n天中部分天数人所在的山的高度,求最大的登山高度。
输入:
n m n 是天数,m是已经知道的登山天数
di dhi di天,所在的高度是dhi,共有m行
输出:
最大的登山高度。
Java程序:
import java.util.Scanner; public class C538 { public static void run(){
Scanner in = new Scanner(System.in);
int n=in.nextInt();
int m=in.nextInt();
int ans = 0;
int res = 0;
int prea =in.nextInt();
int preb =in.nextInt();
m--;
ans=preb+prea-1;// 第一次之前,可能的最大高度
int a=0;int b=0;
boolean flag=true;
while(m!=0){
a=in.nextInt();
b=in.nextInt();
if(Math.abs(b-preb) >a-prea)// 为真,说明中间有走的步长 大于 1 或小于 -1
flag = false;
if(flag){
int disd= a-prea;
int dish=b-preb;
if(dish>=0){ // prea 到 a 高度上升 ,dish是两次的高度差
res=preb+dish;// 走了dish 高度,要dish天
disd-=dish; // 减去后的值,是走完disd天,高度没有变化
res+=disd/2;// 步长-1 1 最大的高度是先走disd/2 再下降 disd/2 (共disd天)
ans=Math.max(ans, res); //最大值是最大的高度
}else{// prea 到 a 高度下降了
disd+=dish; // dish有效的下降天数,等式的结果是在disd天内高度没有变化
res =preb+disd/2; // 最大的高度是在disd/2 天内高度上升disd/2
ans = Math.max(ans,res); }
}
prea =a;
preb =b;
m--;
}
if(flag){
preb+=n-prea;
ans = Math.max(ans, preb);
System.out.println(ans);
}else
System.out.println("IMPOSSIBLE");
}
public static void main(String[] args){
run();
}
}
C. Tourist's Notes的更多相关文章
- Codeforces Round #300 C. Tourist's Notes 水题
C. Tourist's Notes Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/538/pr ...
- Codeforces 538 C. Tourist's Notes
C. Tourist's Notes time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- C. Tourist's Notes
C. Tourist's Notes time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Tourist's Notes CodeForces - 538C (贪心)
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist no ...
- Codeforces Round #300(A.【字符串,多方法】,B.【思维题】,C.【贪心,数学】)
A. Cutting Banner time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- Codeforces Round #300 解题报告
呜呜周日的时候手感一直很好 代码一般都是一遍过编译一遍过样例 做CF的时候前三题也都是一遍过Pretest没想着去检查... 期间姐姐提醒说有Announcement也自信不去看 呜呜然后就FST了 ...
- C. Tourist Problem
http://codeforces.com/problemset/problem/340/C 赛时没想出赛后却能较快想出深深的教育自己做题一定要静下心来,不要轻易放弃,认真思考,不要浮躁着急,不要太容 ...
- codeforces 340C Tourist Problem(公式题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Tourist Problem Iahub is a big fan of tou ...
- Codeforces Round #198 (Div. 2) C. Tourist Problem
C. Tourist Problem time limit per test 1 second memory limit per test 256 megabytes input standard i ...
随机推荐
- IOS开发的国际化
一 app中内容的国际化 1 添加简体中文支持(默认只有英文) 在xcode的PROJECT->Info->Localizations下添加简体中文的支持. 2新建St ...
- FTP上传文件夹
文件上传类 using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; usi ...
- Filter介绍
Filter可人为是Servlet的一种“加强版”,它重要用于对用户请求进行预处理,也可以对HttpServletResponse进行后处理,是个典型的处理链.使用Filter的完整的流程是:Filt ...
- Centering HTML elements larger than their parents
Centering HTML elements larger than their parents It's not a common problem, but I've run into it a ...
- Struts2入门教程
最近闲来无事,学习s2sh框架,这里先写一点struts2的入门 我的环境 eclipse 4.3.2 tomcat 7.0.52 jdk 1.7.0_45 struts2 2.3.16.3 在ecl ...
- PLSQL读取XML的数据
最近公司做的几个项目,都是通过EBS与外部系统的Web Service进行数据的交互,而调用Web Service的时候,我们所传送的数据,都是按照约定的XML格式来传递,所以EBS接收到数据之后,需 ...
- Leetcode-Construct Binary Tree from inorder and preorder travesal
Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that ...
- 基于BaseAdapter的GridView设置ImageView大小
基于BaseAdapter的GridView设置ImageView大小 网上找了好多,都是基于SimpleAdapter的,本身在Item.xml中就对ImageView设置了id,而基于BaseAd ...
- 【Maximum Depth of Binary Tree 】cpp
题目: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the ...
- selenium使用IE 浏览器问题
代码如下: #coding=utf-8 from selenium import webdriver driver=webdriver.Ie() driver.get('https://www.bai ...