【NOIP考前题目回顾】Luogu P1005
来源:互联网 发布:php什么是搭建环境 编辑:程序博客网 时间:2024/06/06 00:16
思路
很考思维的一道题,但是模拟一下的话就没什么难度了。首先两个人相遇并立即掉头走,那么将这两个人互换一下的话就会发现他们掉头走并没有什么卵用,人还是那几个人。所以直接放代码。
代码
#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;}
阅读全文
0 0
- 【NOIP考前题目回顾】Luogu P1005
- 【NOIP考前题目回顾】Luogu P1005
- 【NOIP考前题目回顾】Luogu P1000
- 【NOIP考前题目回顾】Luogu P1001
- 【NOIP考前题目回顾】Luogu P1003
- 【NOIP考前题目回顾】Luogu P1006
- 【NOIP考前题目回顾】Luogu P1012
- 【NOIP考前题目回顾】Luogu P1040
- 【NOIP考前题目回顾】Luogu P1046
- 【NOIP考前题目回顾】Luogu P1047
- Luogu考前模拟Round2总结
- NOIP 考前模板整理
- NOIP 考前注意
- NOIP考前的心得体会
- NOIP 考前错误总结
- NOIP考前总结
- noip考前大总结
- NOIP 考前提醒
- AWT&Swing 各种组件关系
- Linux中利用NFS实现飞鸽传书
- SAP Creating Packages
- 消息总线能否实现消息必达?
- Linux信号机制
- 【NOIP考前题目回顾】Luogu P1005
- KMP算法
- CSS 命名规则
- 识别方法区
- 笔试面试---不经意的strcpy
- SDNU OJ 1182奖学金
- Makefile学习笔记3
- Java基础
- Gym 101572E Emptying Baltic【优先队列+BFS】