UVALive 6662 TheLastAnt

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 using namespace std;
 6 struct xxx
 7 {
 8     int p,d;
 9 }a[22];
10 int n,l;
11 bool f[22];
12 int main()
13 {
14     while (~scanf("%d%d",&n,&l))
15     {
16         if (n==0&&l==0) break;
17         for (int i=1;i<=n;i++)
18         {
19             char s[5];
20             scanf("%s",s);
21             scanf("%d",&a[i].p);
22             if (s[0]==‘R‘) a[i].d=1;
23             else a[i].d=0;
24         }
25         int ti=0,tot=n;
26         memset(f,0,sizeof(f));
27         int ans;
28         while (tot)
29         {
30             ti++;
31             for (int i=1;i<=n;i++)
32                 if (!f[i])
33                 {
34                     if (a[i].d==1) a[i].p++;
35                     else a[i].p--;
36                 }
37             for (int i=1;i<=n;i++)
38                 if (!f[i])
39                 {
40                     if (a[i].p>=l)
41                     {
42                         ans=i;
43                         f[i]=1;
44                         tot--;
45                     }
46                 }
47             for (int i=1;i<=n;i++)
48                 if (!f[i])
49                 {
50                     if (a[i].p<1)
51                     {
52                         ans=i;
53                         f[i]=1;
54                         tot--;
55                     }
56                 }
57             for (int i=1;i<=n;i++)
58                 for (int j=i+1;j<=n;j++)
59                     if (a[i].p==a[j].p)
60                     {
61                         a[i].d^=1;
62                         a[j].d^=1;
63                     }
64         }
65         printf("%d %d\n",ti,ans);
66     }
67     return 0;
68 }

UVALive 6662 TheLastAnt

时间: 2024-08-06 18:10:10

UVALive 6662 TheLastAnt的相关文章

UvaLive 6662 The Last Ant 模拟

链接:http://vjudge.net/problem/viewProblem.action?id=49407 题意:有若干只蚂蚁,给出它们在管子内的坐标和它们的移动方向,如果两只蚂蚁在坐标为整数的位置相遇,那么它们分别调头,否则,两只蚂蚁穿过对方,继续前进.现在问什么时候蚂蚁能全部离开这个管子,并且求出最后一只离开管子的蚂蚁的编号. 是一道纯模拟题,以前觉得这种模拟题的代码量太大,不愿意做,这次A掉以后,感觉神清气爽. 思路:直接模拟即可. 代码: #include<iostream> #

UESTC 2014 Summer Training #18 Div.2

A.UVALive 6661 题意从1~N中选k个数,和为s的方案数 第一眼搜索,估计错状态量,又去yydp...浪费大量时间 数据很小的,状态数都不会超过2^N...直接dfs就过了 //state二进制表示选取的数 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> using namespace std; const int maxn = 200; in

UVALive 4848 Tour Belt

F - Tour Belt Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVALive 4848 Description Korea has many tourist attractions. One of them is an archipelago (Dadohae in Korean), a cluster of small islands sca

UVALive 6467 Strahler Order 拓扑排序

这题是今天下午BNU SUMMER TRAINING的C题 是队友给的解题思路,用拓扑排序然后就可以了 最后是3A 其中两次RE竟然是因为: scanf("%d",mm); ORZ 以后能用CIN还是CIN吧 QAQ 贴代码了: 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <math.h> 5 #include <iostre

UVALive 7077 Little Zu Chongzhi&#39;s Triangles (有序序列和三角形的关系)

这个题……我上来就给读错了,我以为最后是一个三角形,一条边可以由多个小棒组成,所以想到了状态压缩各种各样的东西,最后成功了……结果发现样例过不了,三条黑线就在我的脑袋上挂着,改正了以后我发现N非常小,想到了回溯每个棍的分组,最多分5组,结果发现超时了……最大是5^12 =  244,140,625,厉害呢…… 后来想贪心,首先想暴力出所有可能的组合,结果发现替换问题是一个难题……最后T T ,我就断片了.. 等看了别人的办法以后,我才发现我忽视了三角形的特性,和把数据排序以后的特点. 如果数据从

Gym 100299C &amp;&amp; UVaLive 6582 Magical GCD (暴力+数论)

题意:给出一个长度在 100 000 以内的正整数序列,大小不超过 10^ 12.求一个连续子序列,使得在所有的连续子序列中, 它们的GCD值乘以它们的长度最大. 析:暴力枚举右端点,然后在枚举左端点时,我们对gcd相同的只保留一个,那就是左端点最小的那个,只有这样才能保证是最大,然后删掉没用的. UVaLive上的数据有问题,比赛时怎么也交不过,后来去别的oj交就过了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000&qu

UVALive 6511 Term Project

Term Project Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Original ID: 651164-bit integer IO format: %lld      Java class name: Main 解题:强连通分量 1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 1

UVALive 6508 Permutation Graphs

Permutation Graphs Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Original ID: 650864-bit integer IO format: %lld      Java class name: Main 解题:逆序数 1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long l

UVALive 2659+HUST 1017+ZOJ 3209 (DLX

UVALive 2659 题目:16*16的数独.试了一发大白模板. /* * @author: Cwind */ //#pragma comment(linker, "/STACK:102400000,102400000") #include <iostream> #include <map> #include <algorithm> #include <cstdio> #include <cstring> #include