http://codeforces.com/contest/350/problem/C
对n个点按曼哈顿距离排序。
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 100010
using namespace std; struct node
{
int x,y;
int dir;
bool operator <(const node &a)const
{
return (abs(x)+abs(y))<(abs(a.x)+abs(a.y));
}
}p[maxn]; int n; int main()
{
while(scanf("%d",&n)!=EOF)
{
int cnt=;
for(int i=; i<n; i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
if(p[i].x!=&&p[i].y!=) cnt+=;
else cnt+=;
}
sort(p,p+n);
printf("%d\n",cnt);
for(int i=; i<n; i++)
{
if(p[i].x>)
{
printf("1 %d R\n",abs(p[i].x));
if(p[i].y>)
{
printf("1 %d U\n",abs(p[i].y));
}
else if(p[i].y<)
{
printf("1 %d D\n",abs(p[i].y));
}
printf("2\n");
printf("1 %d L\n",abs(p[i].x));
if(p[i].y>)
{
printf("1 %d D\n",abs(p[i].y));
}
else if(p[i].y<)
{
printf("1 %d U\n",abs(p[i].y));
}
printf("3\n");
}
else if(p[i].x<)
{
printf("1 %d L\n",abs(p[i].x));
if(p[i].y>)
{
printf("1 %d U\n",abs(p[i].y));
}
else if(p[i].y<)
{
printf("1 %d D\n",abs(p[i].y));
}
printf("2\n");
printf("1 %d R\n",abs(p[i].x));
if(p[i].y>)
{
printf("1 %d D\n",abs(p[i].y));
}
else if(p[i].y<)
{
printf("1 %d U\n",abs(p[i].y));
}
printf("3\n");
}
else if(p[i].x==)
{
if(p[i].y>) printf("1 %d U\n",abs(p[i].y));
else if(p[i].y<) printf("1 %d D\n",abs(p[i].y));
printf("2\n");
if(p[i].y>) printf("1 %d D\n",abs(p[i].y));
else if(p[i].y<) printf("1 %d U\n",abs(p[i].y));
printf("3\n");
}
}
}
return ;
}