UVA 10714 蚂蚁贪心
来源:互联网 发布:c语言中数学函数 编辑:程序博客网 时间:2024/04/30 01:46
#include <map>#include <set>#include <list>#include <cmath>#include<cctype>#include <ctime>#include <deque>#include <stack>#include <queue>#include <cstdio>#include <string>#include <vector>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>#define LL long long#define PI 3.1415926535897932626using namespace std;int gcd(int a, int b){return a % b == 0 ? b : gcd(b, a % b);}//这个题目一开始思路还是没有想通,最短时间很简单,直接都不相撞,各自往较近的边界走,那么最短时间就是离较近一段最长的距离//对于最长时间,应注意等效替代的思想,实际上碰撞的换向行走过程就相当于蚂蚁还是一个方向的向前走,只是这个蚂蚁不是之前的那个蚂蚁//进行了替换,所以最长时间就是离远端最远的那个距离。下面是代码inline int get_max(int a,int b){ return a>b?a:b;}inline int get_min(int a,int b){ return a<b?a:b;}int main(){ int T; scanf("%d",&T); while (T--) { int max=0;//最长时间 int min=0;//最短时间 int L,num; scanf("%d%d",&L,&num); for (int i=0;i<num;i++) { int a; scanf("%d",&a); int Short=get_min(a,L-a); int Long=get_max(a,L-a); if (Short>min) min=Short; if (Long>max) max=Long; } printf("%d %d\n",min,max); } return 0;}
0 0
- UVA 10714 蚂蚁贪心
- UVA 10714 Ants 蚂蚁 贪心+模拟 水题
- 小蚂蚁搬家<贪心>
- uva 10714(贪心)
- Uva 10881 蚂蚁
- Uva 10881蚂蚁
- uva 10881 蚂蚁
- uva 10881 蚂蚁
- 例题1.5 蚂蚁 UVA
- uva - 10714 - Ants(数学推导、蚂蚁问题)
- UVA 10714 Ants (贪心)
- uva 10714 Ants(贪心)
- UVA - 10714 Ants(贪心)
- uva 10714 Ants(贪心)
- UVa 10881 蚂蚁(等效变换)
- NYOJ747 - 蚂蚁的难题(三)(贪心+DP)
- NYOJ747 蚂蚁的难题(三)(贪心+DP)
- UVA 10161 棋盘上的蚂蚁
- android界面 设计模式
- Android 中自定义 Adapter
- Linux 安装 FW150UM/RALINK 无线网卡
- 学习笔记----命名空间
- Opencv将图片转化成视频
- UVA 10714 蚂蚁贪心
- JUnit使用报java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing错误解决
- 超实用的三个ubuntu快捷键
- win7下虚拟WIFI
- 关于使用免费的myeclipse
- [转载]vector与迭代器和数组与指针
- SQL关联时发现的问题
- 考研之路-数学很重要(高数,线性代数和概率论)
- 股票F10脱机文件过滤:蓝宝石概念股票一览