Posted on 2007-05-03 10:32
oyjpart 阅读(965)
评论(2) 编辑 收藏 引用 所属分类:
ACM/ICPC或其他比赛
今天集训队出了一些题目做
看到一个2900 想了想 什么线段相交之类的做法 觉得还是挺复杂的
闲来无聊 翻翻status 突然看到alpc12!
顿觉十分惊讶 一看 是很久以前做过的题目了 仔细查查 竟然是我在PKU上做的第五道题 。。。 一看 那时候还不知道多test case怎么处理 居然把所有的答案保存一下 一次输出 而且程序里面 还有一堆goto语句。。faint
贴出来纪念一下那个纯真的年代
Source
Problem Id:2900 User Id:alpc12
Memory:7904K Time:265MS
Language:C++ Result:Accepted
- Source
1
#include <iostream>
2
#include <string>
3
using namespace std;
4
int d[1001][1001]; //0空白 1一次 2两次
5
enum dr{EM, UL, UR, DL, DR};//empty & not available
6
dr dir[1001][1001];
7
int main()
8
{
9
int t,a,b,x,y;
10
string indrt;
11
int i,j,k;
12
scanf("%d",&t);
13
int *count = new int[t];
14
for (i=0; i<t; i++)
15
count[i] = 0;
16
for (i=0; i<t; i++) //input
17
{
18
for(j=1; j<=a; j++) //initiate
19
{
20
for(k=1; k<=b; k++)
21
{
22
d[j][k] = 0;
23
dir[j][k] = EM;
24
}
25
}
26
scanf("%d%d%d%d",&a,&b,&x,&y);
27
d[x][y] = 1;
28
cin >> indrt;
29
if(indrt=="UL") dir[x][y] =UL;
30
if(indrt=="UR") dir[x][y] =UR;
31
if(indrt=="DL") dir[x][y] =DL;
32
if(indrt=="DR") dir[x][y] =DR;
33
int u,l;
34
dr father = dir[x][y];
35
for(j=0; ;j++)
36
{
37
father = dir[x][y];
38
switch(father)
39
{
40
case UL: u=-1; l=-1; break;
41
case UR: u=-1; l=1; break;
42
case DL: u=1; l=-1; break;
43
case DR: u=1; l=1; break;//忘了break
44
}
45
x+=u;
46
y+=l;
47
if (d[x][y]==2) goto print;
48
if (d[x][y]==1)
49
{
50
dr temp = dir[x][y];
51
d[x][y] = 2;
52
count[i]++;
53
dir[x][y] = father;
54
if(x==1)
55
{
56
if (father == UL)
57
dir[x][y] = DL;
58
else
59
dir[x][y] = DR;
60
}
61
if(x==a)
62
{
63
if (father == DL)
64
dir[x][y] = UL;
65
else
66
dir[x][y] = UR;
67
}
68
if(y==1)
69
{
70
if (father == UL)
71
dir[x][y] = UR;
72
else
73
dir[x][y] = DR;
74
}
75
if(y==b)
76
{
77
if (father == UR)
78
dir[x][y] = UL;
79
else
80
dir[x][y] = DL;
81
}
82
if((x==1||x==a) && (y==1)||(y==b))
83
goto print;
84
if(temp == dir[x][y])
85
{
86
goto print;
87
}
88
}//if
89
if(d[x][y]==0)
90
{
91
d[x][y] = 1;
92
dir[x][y] = father;
93
if(x==1)
94
{
95
if (father == UL)
96
dir[x][y] = DL;
97
else
98
dir[x][y] = DR;
99
}
100
if(x==a)
101
{
102
if (father == DL)
103
dir[x][y] = UL;
104
else
105
dir[x][y] = UR;
106
}
107
if(y==1)
108
{
109
if (father == UL)
110
dir[x][y] = UR;
111
else
112
dir[x][y] = DR;
113
}
114
if(y==b)
115
{
116
if (father == UR)
117
dir[x][y] = UL;
118
else
119
dir[x][y] = DL;
120
}
121
if(((x==1)||(x==a)) && ((y==1)||(y==b)))
122
{
123
goto print;
124
}
125
}//if
126
}//if
127
print: ;
128
}
129
for (i=0; i<t; i++)
130
printf("%d\n",count[i]);
131
return 0;
132
}
133