【NOIP考前题目回顾】Luogu P1005
2017-10-29 20:42
232 查看
思路
很考思维的一道题,但是模拟一下的话就没什么难度了。首先两个人相遇并立即掉头走,那么将这两个人互换一下的话就会发现他们掉头走并没有什么卵用,人还是那几个人。所以直接放代码。代码
#include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <queue> #include <utility> int nextInt() { int num = 0; char c; bool flag = false; while ((c = std::getchar()) == ' ' || c == '\r' || c == '\t' || c == '\n'); if (c == '-') flag = true; else num = c - 48; while (std::isdigit(c = std::getchar())) num = num * 10 + c - 48; return (flag ? -1 : 1) * num; } int main() { int n, l, p, maxv = 0, minv = 0; l = nextInt(); n = nextInt(); for (int i = 1; i <= n; i++) { p = nextInt(); maxv = max(maxv, max(l - p + 1, p)); minv = max(minv, min(l - p + 1, p)); } std::cout << minv << ' ' << maxv << std::endl; #ifdef __EDWARD_EDIT std::cin.get(); std::cin.get(); #endif return 0; }
相关文章推荐
- 【NOIP考前题目回顾】Luogu P1005
- 【NOIP考前题目回顾】Luogu P1001
- 【NOIP考前题目回顾】Luogu P1040
- 【NOIP考前题目回顾】Luogu P1003
- 【NOIP考前题目回顾】Luogu P1046
- 【NOIP考前题目回顾】Luogu P1047
- 【NOIP考前题目回顾】Luogu P1006
- 【NOIP考前题目回顾】Luogu P1012
- 【NOIP考前题目回顾】Luogu P1000
- 2016.08.17【初中部 NOIP提高组 】模拟赛C题目
- 【noip题目代码】买铅笔;ceil向上取整,隐式浮点数,pause
- 2016.08.19上午【初中部 NOIP普及组 】模拟赛题目
- 基于上次腾讯远程面试的题目总结与回答(精心总结回顾) 上
- NOIP 考前日记
- 有关逻辑判断 请问pascal一道NOIP题目
- [NOIP 2014复习]第三章:动态规划——NOIP历届真题回顾
- ◆竞赛题目◆◇NOIP2016普及组◇ 魔法阵
- [转]NOIP考前知识大总结
- 不高兴的津津 C语言题目详解 noip2004普及组第1题
- {福利}NOIP考纲总结+NOIP考前经验谈