forked from mohitsh/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjasiek.cpp
96 lines (96 loc) · 1.54 KB
/
jasiek.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-06-13
#include <cstdio>
#ifdef _MSC_VER
#define GC getchar
#else
#define GC getchar_unlocked
#endif
int X[30000];
int Y[30000];
int x,y;
int V;
void process(char lastc,char c)
{
if (lastc=='N')
if (c=='E')
X[V]=x,Y[V]=y,V++;
else if (c=='S')
{
X[V]=x+1,Y[V]=y+2,V++;
X[V]=x,Y[V]=y+2,V++;
}
else //c=='W'
X[V]=x+2,Y[V]=y+1,V++;
else if (lastc=='E')
if (c=='N')
X[V]=x+1,Y[V]=y-1,V++;
else if (c=='S')
X[V]=x,Y[V]=y+1,V++;
else //c=='W'
{
X[V]=x+2,Y[V]=y,V++;
X[V]=x+2,Y[V]=y+1,V++;
}
else if (lastc=='S')
if (c=='N')
{
X[V]=x,Y[V]=y-1,V++;
X[V]=x+1,Y[V]=y-1,V++;
}
else if (c=='E')
X[V]=x-1,Y[V]=y,V++;
else //c=='W'
X[V]=x+1,Y[V]=y+1,V++;
else //lastc=='W'
if (c=='N')
X[V]=x+1,Y[V]=y,V++;
else if (c=='E')
{
X[V]=x-1,Y[V]=y+1,V++;
X[V]=x-1,Y[V]=y,V++;
}
else //c=='S'
X[V]=x,Y[V]=y+2,V++;
}
int main()
{
int i,j,area;
char c,char1,lastc;
for (i=0; i<10; i++)
{
x=0; y=0; V=0;
GC();GC();
char1=GC(); GC();
if (char1=='K')
{
printf("1\n");
continue;
}
c=char1;
for(;;)
{
lastc=c;
c=GC(); GC();
if (c=='K') break;
if (c=='N')
y++;
else if (c=='E')
x++;
else if (c=='S')
y--;
else if (c=='W')
x--;
if (c!=lastc)
process(lastc,c);
}
if (char1=='N') y++; else if (char1=='E') x++; else if (char1=='S') y--; else x--;
if (lastc!=char1)
process(lastc,char1);
area=0;
for (j=0; j<V-1; j++)
area+=X[j]*Y[j+1]-X[j+1]*Y[j];
area+=X[V-1]*Y[0]-X[0]*Y[V-1];
printf("%d\n",area/2);
}
return 0;
}