forked from t3nsor/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cerc07p.cpp
96 lines (96 loc) · 1.6 KB
/
cerc07p.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// 2008-09-26
#include <iostream>
#include <algorithm>
#ifdef ONLINE_JUDGE
#define gc getchar_unlocked
#else
#define gc getchar
#endif
int in()
{
char c;
int res=0;
bool minus=false;
for(;;)
{
c=gc();
if (c=='-')
minus=true;
else if (c<=32)
return minus?-res:res;
else
res=(res<<1)+(res<<3)+c-'0';
}
}
using namespace std;
int main()
{
pair<pair<int,int>,int> A[1000];
pair<pair<int,int>,int> B[1000];
int px[1000];
int py[1000];
int nx[1000];
int ny[1000];
bool up[1000];
bool right[1000];
char res[1000];
int N,i;
for(;;)
{
N=in();
if (!N) return 0;
for (i=0; i<N; i++)
{
A[i].first.first=B[i].first.second=px[i]=in();
B[i].first.first=A[i].first.second=py[i]=in();
A[i].second=B[i].second=i;
}
gc();
sort(A,A+N);
sort(B,B+N);
for (i=0; i<(N>>1); i++)
{
ny[A[i<<1].second]=A[(i<<1)+1].second;
up[A[i<<1].second]=true;
ny[A[(i<<1)+1].second]=A[i<<1].second;
up[A[(i<<1)+1].second]=false;
nx[B[i<<1].second]=B[(i<<1)+1].second;
right[B[i<<1].second]=true;
nx[B[(i<<1)+1].second]=B[i<<1].second;
right[B[(i<<1)+1].second]=false;
}
int cnt=0;
int firstpoint;
bool v=true;
int point=A[0].second;
while (cnt<N)
{
if (!point)
firstpoint=cnt;
if (v)
{
if (up[point])
res[cnt++]='N';
else
res[cnt++]='S';
v=false;
point=ny[point];
}
else
{
if (right[point])
res[cnt++]='E';
else
res[cnt++]='W';
v=true;
point=nx[point];
}
}
for (i=firstpoint; i<N; i++)
putchar(res[i]);
for (i=0; i<firstpoint; i++)
putchar(res[i]);
putchar('\n');
}
return 0;
}