模拟 Codeforces Round #203 (Div. 2) C. Bombs

题目地址:http://codeforces.com/problemset/problem/350/C

 1 /*
 2     题意:机器人上下左右走路,把其他的机器人都干掉要几步,好吧我其实没读懂题目,
 3             看着样例猜出来的,这题也蛮水的
 4     模拟+贪心:sort一下,从最近的开始走
 5     注意:坐标有一个为0的比普通的少一半的步骤,每次干掉一个要返回原来的位置
 6 */
 7 #include <cstdio>
 8 #include <iostream>
 9 #include <algorithm>
10 #include <string>
11 #include <cmath>
12 #include <cstring>
13 #include <map>
14 #include <set>
15 using namespace std;
16 
17 const int MAXN = 1e5 + 10;
18 const int INF = 0x3f3f3f3f;
19 struct NODE
20 {
21     int x, y;
22     int ok;
23     int sum;
24 }node[MAXN];
25 
26 bool cmp(NODE a, NODE b)
27 {
28     return a.sum < b.sum;
29 }
30 
31 int main(void)        //Codeforces Round #203 (Div. 2) C. Bombs
32 {
33     //freopen ("F.in", "r", stdin);
34 
35     int n;
36     while (~scanf ("%d", &n))
37     {
38         int cnt = 0;
39         for (int i=1; i<=n; ++i)
40         {
41             scanf ("%d%d", &node[i].x, &node[i].y);
42             node[i].sum = abs (node[i].x) + abs (node[i].y);
43             //if (node[i].x < 0)    node[i].x = -node[i].x;
44             //if (node[i].y < 0)    node[i].y = -node[i].y;
45             if (node[i].x == 0 || node[i].y == 0)    node[i].ok = 1, cnt++;
46             else    node[i].ok = 0;
47         }
48         sort (node+1, node+1+n, cmp);
49 
50         printf ("%d
", (n - cnt) * 6 + 4 * cnt);
51         for (int i=1; i<=n; ++i)
52         {
53             if (node[i].ok == 0)
54             {
55                 printf ("%d %d %c
", 1, abs (node[i].x), (node[i]. x < 0) ? 'L' : 'R');
56                 printf ("%d %d %c
", 1, abs (node[i].y), (node[i]. y < 0) ? 'D' : 'U');
57                 puts ("2");
58                 printf ("%d %d %c
", 1, abs (node[i].x), (node[i]. x < 0) ? 'R' : 'L');
59                 printf ("%d %d %c
", 1, abs (node[i].y), (node[i]. y < 0) ? 'U' : 'D');
60                 puts ("3");
61             }
62             else
63             {
64                 if (node[i].x == 0)
65                 {
66                     printf ("%d %d %c
", 1, abs (node[i].y), (node[i]. y < 0) ? 'D' : 'U');
67                     puts ("2");
68                     printf ("%d %d %c
", 1, abs (node[i].y), (node[i]. y < 0) ? 'U' : 'D');
69                     puts ("3");
70                 }
71                 else
72                 {
73                     printf ("%d %d %c
", 1, abs (node[i].x), (node[i]. x < 0) ? 'L' : 'R');
74                     puts ("2");
75                     printf ("%d %d %c
", 1, abs (node[i].x), (node[i]. x < 0) ? 'R' : 'L');
76                     puts ("3");
77                 }
78             }
79         }
80     }
81 
82     return 0;
83 }
编译人生,运行世界!
原文地址:https://www.cnblogs.com/Running-Time/p/4385178.html