水题/poj 1852 Ants

 1 /*
 2     PROBLEM:poj1852
 3     AUTHER:Nicole
 4     MEMO:水题
 5 */
 6 #include<cstdio>
 7 using namespace std;
 8 int cmax(int a,int b){return a>b?a:b;}
 9 int cmin(int a,int b){return a<b?a:b;}
10 int main()
11 {
12     int cases;
13     scanf("%d",&cases);
14     for (int c=1;c<=cases;c++)
15     {
16         int l,n;
17         int mmax=0,mmin=0;
18         scanf("%d%d",&l,&n);
19         for (int i=1;i<=n;i++)
20         {
21             int x;
22             scanf("%d",&x);
23             mmax=cmax(mmax,cmax(x,l-x));
24             mmin=cmax(mmin,cmin(x,l-x));
25         }
26         printf("%d %d\n",mmin,mmax);
27     }
28     return 0;
29 }
时间: 2024-10-09 07:53:43

水题/poj 1852 Ants的相关文章

POJ 1852 Ants 思维题 简单题

Ants Description An army of ants walk on a horizontal pole of length l cm, each with a constant speed of 1 cm/s. When a walking ant reaches an end of the pole, it immediatelly falls off it. When two ants meet they turn back and start walking in oppos

poj -1852 ants (思维题)

n只蚂蚁以每秒1cm的速度在长为Lcm的杆子上爬行,当蚂蚁爬到杆子的端点时就会掉落,由于杆子太细,两只蚂蚁相遇时,他们不能交错通过,只能各自反向爬回去,对于每只蚂蚁,我们知道它距离杆子左端的距离为x,但不知道它当前的朝向,请计算所有蚂蚁落下杆子所需的最短时间很最长时间. #include <iostream> #include <cstdio> #include <cmath> #include <vector> #include <cstring&g

简单水题 POJ 2291 Rotten Ropes

题目传送门 1 /* 2 我校oj的源题,看懂题意就很水,贴出来省的再敲:) 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 using namespace std; 8 9 const int MAXN = 1e3 + 10; 10 const int INF = 0x3f3f3f3f; 11 int a[MAXN]; 12 13 int main(void) //POJ 2

POJ 1852 Ants

Ants Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 15617   Accepted: 6753 Description An army of ants walk on a horizontal pole of length l cm, each with a constant speed of 1 cm/s. When a walking ant reaches an end of the pole, it imm

POJ 1852 Ants 分析

1.暴搜 每只蚂蚁朝向有两种,可以枚举n只蚂蚁的朝向,然后模拟蚂蚁相遇的情景,总共2^n中情况. 2.分析ants相碰的情况: (a->)  (<-b) 变成 (<-a)(b->) 由于每只蚂蚁是相同的,所以等价与(<-b)(a->),这和两只蚂蚁原来的走向是一样的,即把碰撞当作没发生过 所以可以对每一只蚂蚁检查一次就可以了 3.空间优化 存蚂蚁的初始位置O(n),但是我们每次只要比较 a[i] 和 len-a[i] 就可以了,后面不需要这两个值了,所以完全可以用一个x

POJ 1852 Ants (思维技巧 + 贪心)

Ants Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 10639   Accepted: 4718 Description An army of ants walk on a horizontal pole of length l cm, each with a constant speed of 1 cm/s. When a walking ant reaches an end of the pole, it imm

poj 1852 Ants(贪心)

Ants Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 14061   Accepted: 6134 Description An army of ants walk on a horizontal pole of length l cm, each with a constant speed of 1 cm/s. When a walking ant reaches an end of the pole, it imm

并查集水题 POJ 1611

题意:有n(n<=30000)个学生,每个学生属于一个团体(可以属于多个团体),共有m(<=500)个团体,如果一个学生是嫌疑人,则他所在的团体的所有人都是嫌疑人,初始时0号学生是嫌疑人.问总共有多少个嫌疑人. 很明显同一个团体的学生可以连一条边,即求0号点所在的连通块有多少个点,用并查集可以很方便的办到,如果两个点属于同一个连通块则把他们的代表元连接起来即可,始终把较小的那个节点作为父节点,所以最后p[0]的节点数就是答案. 代码:

poj 2369 Permutations 置换水题

找循环节求lcm就够了,若答案是12345应该输出1,被坑了下. #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<cmath> using namespace std; #define INF 0x3FFFFFF #define MAXN 2222 #define eps 1e-6 i