cf C. Bombs

http://codeforces.com/contest/350/problem/C

对n个点按曼哈顿距离排序。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define maxn 100010
 5 using namespace std;
 6 
 7 struct node
 8 {
 9     int x,y;
10     int dir;
11     bool operator <(const node &a)const
12     {
13        return (abs(x)+abs(y))<(abs(a.x)+abs(a.y));
14     }
15 }p[maxn];
16 
17 int n;
18 
19 int main()
20 {
21     while(scanf("%d",&n)!=EOF)
22     {
23         int cnt=0;
24         for(int i=0; i<n; i++)
25         {
26             scanf("%d%d",&p[i].x,&p[i].y);
27             if(p[i].x!=0&&p[i].y!=0) cnt+=6;
28             else cnt+=4;
29         }
30         sort(p,p+n);
31         printf("%d\n",cnt);
32         for(int i=0; i<n; i++)
33         {
34             if(p[i].x>0)
35             {
36                 printf("1 %d R\n",abs(p[i].x));
37                 if(p[i].y>0)
38                 {
39                     printf("1 %d U\n",abs(p[i].y));
40                 }
41                 else if(p[i].y<0)
42                 {
43                     printf("1 %d D\n",abs(p[i].y));
44                 }
45                 printf("2\n");
46                 printf("1 %d L\n",abs(p[i].x));
47                 if(p[i].y>0)
48                 {
49                     printf("1 %d D\n",abs(p[i].y));
50                 }
51                 else if(p[i].y<0)
52                 {
53                     printf("1 %d U\n",abs(p[i].y));
54                 }
55                 printf("3\n");
56             }
57             else if(p[i].x<0)
58             {
59                 printf("1 %d L\n",abs(p[i].x));
60                 if(p[i].y>0)
61                 {
62                     printf("1 %d U\n",abs(p[i].y));
63                 }
64                 else if(p[i].y<0)
65                 {
66                     printf("1 %d D\n",abs(p[i].y));
67                 }
68                 printf("2\n");
69                 printf("1 %d R\n",abs(p[i].x));
70                 if(p[i].y>0)
71                 {
72                     printf("1 %d D\n",abs(p[i].y));
73                 }
74                 else if(p[i].y<0)
75                 {
76                     printf("1 %d U\n",abs(p[i].y));
77                 }
78                 printf("3\n");
79             }
80             else if(p[i].x==0)
81             {
82                 if(p[i].y>0) printf("1 %d U\n",abs(p[i].y));
83                 else if(p[i].y<0) printf("1 %d D\n",abs(p[i].y));
84                 printf("2\n");
85                 if(p[i].y>0) printf("1 %d D\n",abs(p[i].y));
86                 else if(p[i].y<0) printf("1 %d U\n",abs(p[i].y));
87                 printf("3\n");
88             }
89         }
90     }
91     return 0;
92 }
View Code

 

posted @ 2014-08-21 21:44  null1019  阅读(143)  评论(0编辑  收藏  举报