Regionals 2011 :: North America - Southeast USA

题目链接:UVALive

VJ比赛链接:VJ

A题。 水题。
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/* ***************

Author :kuangbin

Created Time :2014/7/15 19:13:25

File Name :E:\2014ACM\区域赛练习\2011\2011Southeast_USA\A.cpp

************************************************ */

#include <stdio.h>

#include <string.h>

#include <iostream>

#include <algorithm>

#include <vector>

#include <queue>

#include <set>

#include <map>

#include <string>

#include <math.h>

#include <stdlib.h>

#include <time.h>

using namespace std;

const double pi = acos(-1.0);

double dp[1010][12];

int main()

{

//freopen("drive-000.inp","r",stdin);

//freopen("out.txt","w",stdout);

int n,m;

while(scanf("%d%d",&n,&m) == 2)

{

if(n == 0 && m == 0)break;

double k;

char op[10];

for(int i = 1;i <= n;i++)

{

scanf("%s%lf",op,&k);

if(i == 1)

{

if(op[0] == 'S')

{

for(int j = 0;j < m;j++)

dp[i][j] = k;

}

else if(op[0] == 'L')

{

for(int j = 0;j < m;j++)

dp[i][j] = pi/2(k+5+j10);

}

else

{

for(int j = 0;j < m;j++)

dp[i][j] = pi/2(k+5+(m-1-j)10);

}

}

else

{

if(op[0] == 'S')

{

for(int j = 0;j < m;j++)

dp[i][j] = dp[i-1][j]+k;

for(int j = 0;j < m;j++)

for(int x = 0;x < m;x++)

{

double tmp = abs(j-x)*100;

if(tmp > k+0.01)continue;

dp[i][j] = min(dp[i][j],dp[i-1][x]+sqrt(k*k + 10.0*10.0*abs(j-x)*abs(j-x)));

}

}

else if(op[0] == 'L')

{

for(int j = 0;j < m;j++)

dp[i][j] = dp[i-1][j] + pi/2(k+5+j10);

}

else

{

for(int j = 0;j < m;j++)

dp[i][j] = dp[i-1][j] + pi/2(k+5+(m-1-j)10);

}

}

}

double ans = dp[n][0];

for(int i = 1;i < m;i++)

ans = min(ans,dp[n][i]);

printf("%.2lf\n",ans);

}

return 0;

}

B: 暴力搞一下就OK了。

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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/* ***************

Author :kuangbin

Created Time :2014/7/15 21:22:19

File Name :E:\2014ACM\区域赛练习\2011\2011Southeast_USA\B.cpp

************************************************ */

#include <stdio.h>

#include <string.h>

#include <iostream>

#include <algorithm>

#include <vector>

#include <queue>

#include <set>

#include <map>

#include <string>

#include <math.h>

#include <stdlib.h>

#include <time.h>

using namespace std;

int a[12];

struct Node

{

int x,y,z;

Node(int _x=0,int _y = 0,int _z = 0)

{

x = _x;

y = _y;

z = _z;

}

};

vector<Node>V;

bool used[12];

bool used2[12];

int A[3],B[3],C[5];

int sum;

bool check1()

{

return a[C[0]]+a[A[0]]+a[B[0]]+a[C[1]] == sum &&

a[C[0]]+a[A[1]]+a[C[2]]+a[C[4]] == sum &&

a[C[1]]+a[B[1]]+a[C[3]]+a[C[4]] == sum &&

a[A[2]]+a[C[2]]+a[C[3]]+a[B[2]] == sum;

}

bool check2()

{

return a[A[0]]+a[B[1]]+a[C[1]]+a[C[4]] == sum &&

a[A[2]]+a[C[0]]+a[C[2]]+a[C[4]] == sum &&

a[B[0]]+a[A[1]]+a[C[0]]+a[C[3]] == sum &&

a[B[2]]+a[C[1]]+a[C[2]]+a[C[3]] == sum;

}

int main()

{

//freopen("in.txt","r",stdin);

//freopen("out.txt","w",stdout);

while(1)

{

sum = 0;

for(int i = 0;i < 12;i++)

{

scanf("%d",&a[i]);

sum += a[i];

}

if(sum == 0)break;

if(sum % 3 != 0)

{

printf("0\n");

continue;

}

sum /= 3;

V.clear();

for(int i = 1;i < 12;i++)

for(int j = 1;j < i;j++)

for(int k = 1;k < j;k++)

if(a[i]+a[j]+a[k]+a[0] == sum)

V.push_back(Node(k,j,i));

int sz = V.size();

int ans = 0;

for(int i = 0;i < sz;i++)

{

memset(used,false,sizeof(used));

A[0] = V[i].x;

A[1] = V[i].y;

A[2] = V[i].z;

used[A[0]] = used[A[1]] = used[A[2]] = true;

for(int j = 0;j < i;j++)

if(!used[V[j].x] && !used[V[j].y] && !used[V[j].z])

{

B[0] = V[j].x;

B[1] = V[j].y;

B[2] = V[j].z;

memset(used2,false,sizeof(used2));

used2[A[0]] = used2[A[1]] = used2[A[2]] = true;

used2[B[0]] = used2[B[1]] = used2[B[2]] = true;

int cnt = 0;

for(int k = 1;k < 12;k++)

if(!used2[k])

C[cnt++] = k;

do

{

do

{

do

{

if(check1())ans++;

if(check2())ans++;

}

while(next_permutation(C,C+5));

}

while(next_permutation(B,B+3));

}

while(next_permutation(A,A+3));

}

}

printf("%d\n",ans);

}

return 0;

}

C:

Flooring Tiles

分两种情况,如果是平方数,约数个数就是2*n-1 如果是非平方数,约数个数就是2*n. 然后暴力去搜就可以了。

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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <stdio.h>

#include <algorithm>

#include <iostream>

#include <queue>

#include <set>

#include <string.h>

#include <map>

#include <vector>

#include <string>

#include <math.h>

using namespace std;

vector<int>yueshu[200];

int prime[] = {2,3,5,7,11,13,17,19};

unsigned long long ans;

bool squ;

void solve(unsigned long long now,int pos,int n,int last,bool flag)

{

if(now >= ans)return;

if(n == 1)

{

if(now < ans && flag == squ)ans = now;

return;

}

int sz = yueshu[n].size();

for(int i = 0;i < sz;i++)

{

if(yueshu[n][i] > last)break;

int v = yueshu[n][i];

if(squ && v%2 != 1)continue;

unsigned long long nxt = now;

for(int j = 0;j < v-1;j++)

{

if((double)nxt > (double)ans/prime[pos] + 10)return;

nxt *= prime[pos];

if(nxt > ans)

{

return;

}

}

solve(nxt,pos+1,n/v,v,flag && v%2 == 1);

}

}

int main()

{

//freopen("in.txt","r",stdin);

//freopen("out.txt","w",stdout);

int n;

for(int i = 2;i < 200;i++)

{

for(int j = 2;j <= i;j++)

if(i%j == 0)

yueshu[i].push_back(j);

}

while(scanf("%d",&n) ==1 && n)

{

ans = 1000000000000000000LL + 10;

squ = true;

solve(1,0,2*n-1,200,1);

squ = false;

solve(1,0,2*n,200,1);

cout<<ans<<endl;

}

return 0;

}

D:

Vive la Difference!

水题了。

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
#include <stdio.h>

#include <algorithm>

#include <iostream>

#include <queue>

#include <set>

#include <string.h>

#include <map>

#include <vector>

#include <string>

#include <math.h>

using namespace std;

int main()

{

//freopen("in.txt","r",stdin);

//freopen("out.txt","w",stdout);

int a,b,c,d;

while(scanf("%d%d%d%d",&a,&b,&c,&d) == 4)

{

if(a == 0 && b == 0 && c == 0 && d == 0)

break;

int ans = 0;

while(1)

{

if(a == b && c == b && d == c)break;

ans++;

int na = abs(a-b);

int nb = abs(b-c);

int nc = abs(c-d);

int nd = abs(d-a);

a = na;

b = nb;

c = nc;

d = nd;

}

printf("%d\n",ans);

}
return 0;

}

E:

Robot Navigation

就是BFS的水题。

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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/* ***************

Author :kuangbin

Created Time :2014/7/15 23:22:33

File Name :E:\2014ACM\区域赛练习\2011\2011Southeast_USA\E.cpp

************************************************ */

#include <stdio.h>

#include <string.h>

#include <iostream>

#include <algorithm>

#include <vector>

#include <queue>

#include <set>

#include <map>

#include <string>

#include <math.h>

#include <stdlib.h>

#include <time.h>

using namespace std;

const int INF = 0x3f3f3f3f;

const int MOD = 1000000;

int Move[][2] = { {-1,0},{0,1},{1,0},{0,-1}};

char g[110][110];

int n,m;

int sx,sy,sd;

int ex,ey;

int dp1[110][110][4];

int dp2[110][110][4];

struct Node

{

int x,y;

int d;

Node(int _x = 0,int _y = 0,int _d = 0)

{

x = _x;

y = _y;

d = _d;

}

};

bool check(int x,int y)

{

return x >= 0 && x < n && y >= 0 && y < m && g[x][y] != '*';

}

void bfs()

{

queue<Node>q;

for(int i = 0;i < n;i++)

for(int j = 0;j < m;j++)

for(int k = 0;k < 4;k++)

{

dp1[i][j][k] = INF;

dp2[i][j][k] = 0;

}

q.push(Node(sx,sy,sd));

dp1[sx][sy][sd] = 0;

dp2[sx][sy][sd] = 1;

while(!q.empty())

{

Node tmp = q.front();

q.pop();

int x = tmp.x;

int y = tmp.y;

x += Move[tmp.d][0];

y += Move[tmp.d][1];

while(check(x,y))

{

if(dp1[x][y][tmp.d] > dp1[tmp.x][tmp.y][tmp.d]+1)

{

dp1[x][y][tmp.d] = dp1[tmp.x][tmp.y][tmp.d]+1;

dp2[x][y][tmp.d] = dp2[tmp.x][tmp.y][tmp.d];

q.push(Node(x,y,tmp.d));

}

else if(dp1[x][y][tmp.d] == dp1[tmp.x][tmp.y][tmp.d]+1)

{

dp2[x][y][tmp.d] += dp2[tmp.x][tmp.y][tmp.d];

if(dp2[x][y][tmp.d] >= MOD)

dp2[x][y][tmp.d] -= MOD;

}

x += Move[tmp.d][0];

y += Move[tmp.d][1];

}

if(dp1[tmp.x][tmp.y][(tmp.d+1)%4] > dp1[tmp.x][tmp.y][tmp.d]+1)

{

dp1[tmp.x][tmp.y][(tmp.d+1)%4] = dp1[tmp.x][tmp.y][tmp.d]+1;

dp2[tmp.x][tmp.y][(tmp.d+1)%4] = dp2[tmp.x][tmp.y][tmp.d];

q.push(Node(tmp.x,tmp.y,(tmp.d+1)%4));

}

else if(dp1[tmp.x][tmp.y][(tmp.d+1)%4] == dp1[tmp.x][tmp.y][tmp.d]+1)

{

dp2[tmp.x][tmp.y][(tmp.d+1)%4] += dp2[tmp.x][tmp.y][tmp.d];

if(dp2[tmp.x][tmp.y][(tmp.d+1)%4] >= MOD)

dp2[tmp.x][tmp.y][(tmp.d+1)%4] -= MOD;

}

if(dp1[tmp.x][tmp.y][(tmp.d+3)%4] > dp1[tmp.x][tmp.y][tmp.d]+1)

{

dp1[tmp.x][tmp.y][(tmp.d+3)%4] = dp1[tmp.x][tmp.y][tmp.d]+1;

dp2[tmp.x][tmp.y][(tmp.d+3)%4] = dp2[tmp.x][tmp.y][tmp.d];

q.push(Node(tmp.x,tmp.y,(tmp.d+3)%4));

}

else if(dp1[tmp.x][tmp.y][(tmp.d+3)%4] == dp1[tmp.x][tmp.y][tmp.d]+1)

{

dp2[tmp.x][tmp.y][(tmp.d+3)%4] += dp2[tmp.x][tmp.y][tmp.d];

if(dp2[tmp.x][tmp.y][(tmp.d+3)%4] >= MOD)

dp2[tmp.x][tmp.y][(tmp.d+3)%4] -= MOD;

}

}

}

int main()

{

//freopen("in.txt","r",stdin);

//freopen("out.txt","w",stdout);

while(scanf("%d%d",&n,&m) == 2)

{

if(n == 0 && m == 0)break;

for(int i = 0;i < n;i++)

{

scanf("%s",g[i]);

for(int j = 0;j < m;j++)

{

if(g[i][j] == 'X')

{

ex = i; ey = j;

}

else if(g[i][j] == 'N' || g[i][j] == 'E' || g[i][j] == 'S' || g[i][j] == 'W')

{

sx = i;

sy = j;

if(g[i][j] == 'N')sd = 0;

else if(g[i][j] == 'E')sd = 1;

else if(g[i][j] == 'S')sd = 2;

else sd = 3;

}

}

}

bfs();

int ans1 = INF;

int ans2 = 0;

for(int i = 0;i < 4;i++)

{

if(dp1[ex][ey][i] < ans1)

{

ans1 = dp1[ex][ey][i];

ans2 = dp2[ex][ey][i];

}

else if(dp1[ex][ey][i] == ans1)

{

ans2 += dp2[ex][ey][i];

if(ans2 >= MOD)

ans2 -= MOD;

}

}

if(ans1 == INF)ans1 = 0;

printf("%d %d\n",ans1,ans2);

}

return 0;

}

F:

Folding Game

一个折纸问题。 直接写个dfs就解决了,注意细节。

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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* ***************

Author :kuangbin

Created Time :2014/7/16 18:33:53

File Name :E:\2014ACM\区域赛练习\2011\2011Southeast_USA\F.cpp

************************************************ */

#include <stdio.h>

#include <string.h>

#include <iostream>

#include <algorithm>

#include <vector>

#include <queue>

#include <set>

#include <map>

#include <string>

#include <math.h>

#include <stdlib.h>

#include <time.h>

using namespace std;

int W[30],H[30];

char op[30][10];

int K[30];

int dfs(int n,int x,int y)

{

if(n == 0)return 1;

int ans = 0;

if(op[n][0] == 'T')

{

int tmp = H[n] - y;

if(K[n] > tmp)ans += dfs(n-1,x,H[n-1]-(K[n]-tmp));

if(H[n-1]-K[n] > tmp)ans += dfs(n-1,x,H[n-1]-K[n]-tmp);

}

else if(op[n][0] == 'B')

{

if(K[n] > y)ans += dfs(n-1,x,K[n]-y);

if(H[n-1]-K[n] > y)ans += dfs(n-1,x,y+K[n]);

}

else if(op[n][0] == 'L')

{

if(K[n] > x)ans += dfs(n-1,K[n]-x,y);

if(W[n-1]-K[n] > x)ans += dfs(n-1,K[n]+x,y);

}

else

{

int tmp = W[n]-x;

if(K[n] > tmp)ans += dfs(n-1,W[n-1]-(K[n]-tmp),y);

if(W[n-1]-K[n] > tmp)ans += dfs(n-1,W[n-1]-K[n]-tmp,y);

}

return ans;

}

int main()

{

//freopen("in.txt","r",stdin);

//freopen("out.txt","w",stdout);

int n;

while(scanf("%d%d%d",&W[0],&H[0],&n) == 3)

{

if(W[0] == 0 && H[0] == 0 && n == 0)break;

for(int i = 1;i <= n;i++)

{

scanf("%s%d",op[i],&K[i]);

if(op[i][0] == 'T' || op[i][0] == 'B')

{

W[i] = W[i-1];

H[i] = max(K[i],H[i-1]-K[i]);

}

else

{

H[i] = H[i-1];

W[i] = max(K[i],W[i-1]-K[i]);

}

}

int x,y;

scanf("%d%d",&x,&y);

printf("%d\n",dfs(n,x,y));

}

return 0;

}
H:

Family Fortune

一颗树上,要选择k个节点,这k个节点没有祖先和后代关系。 要求k个点的值的和最大。 可以发现当一个点选择一个,它子树下面,和它上面的点都不能选了。 所以按照dfs的顺序进行DP,要么选子树,要么选当前点。

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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* ***************

Author :kuangbin

Created Time :2014/7/16 19:47:08

File Name :E:\2014ACM\区域赛练习\2011\2011Southeast_USA\H.cpp

************************************************ */

#include <stdio.h>

#include <string.h>

#include <iostream>

#include <algorithm>

#include <vector>

#include <queue>

#include <set>

#include <map>

#include <string>

#include <math.h>

#include <stdlib.h>

#include <time.h>

using namespace std;

const int MAXN = 100010;

struct Edge

{

int to,next;

}edge[MAXN];

int head[MAXN],tot;

void init()

{

tot = 0;

memset(head,-1,sizeof(head));

}

void addedge(int u,int v)

{

edge[tot].to = v;

edge[tot].next = head[u];

head[u] = tot++;

}

int W[MAXN];

int n,k;

int dp[1010][1010];

void dfs(int u,int dep)

{

for(int i = 0;i <= k;i++)

dp[dep+1][i] = dp[dep][i];

for(int i = head[u];i != -1;i = edge[i].next)

dfs(edge[i].to,dep+1);

for(int i = k-1;i >= 0;i--)

if(dp[dep][i] > -1 && dp[dep][i]+W[u] > dp[dep][i+1])

dp[dep][i+1] = dp[dep][i]+W[u];

for(int i = 0;i <= k;i++)

if(dp[dep+1][i] > dp[dep][i])

dp[dep][i] = dp[dep+1][i];

}

int main()

{

//freopen("in.txt","r",stdin);

//freopen("out.txt","w",stdout);

while(scanf("%d%d",&n,&k) == 2)

{

if(n == 0 && k == 0)break;

int root;

int u;

init();

for(int i = 1;i <= n;i++)

{

scanf("%d%d",&u,&W[i]);

if(u == 0)root = i;

else addedge(u,i);

}

memset(dp[0],-1,sizeof(dp[0]));

dp[0][0] = 0;

dfs(root,0);

if(dp[0][k] == -1)printf("0\n");

else printf("%d\n",dp[0][k]);

}

return 0;

}

I:

Moving Points

状态压缩DP。 直接状压,以及当前在哪个点。 然后直接相对速度去求就可以了。

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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include <stdio.h>

#include <algorithm>

#include <iostream>

#include <queue>

#include <set>

#include <string.h>

#include <map>

#include <vector>

#include <string>

#include <math.h>

using namespace std;

const int MAXN = 16;

double X[MAXN],Y[MAXN],D[MAXN],S[MAXN];

const double PI = acos(-1.0);

struct Point

{

double x,y;

Point(double _x = 0,double _y = 0)

{

x = _x;

y = _y;

}

double operator ^(const Point &b)const

{

return x*b.y-y*b.x;

}

double operator *(const Point &b)const

{

return x*b.x + y*b.y;

}

};

double calc(double x0,double y0,double x1,double y1,double dx,double dy,double C,double S)

{

Point p1 = Point(x1-x0,y1-y0);

Point p2 = Point(-dx,-dy);

double jiao = atan2(fabs(p1^p2),p1*p2);

double a = 1;

double b = -2*S*cos(jiao);

double c = S*S - C*C;

double deta = b*b - 4*a*c;

double tmp = (-b+sqrt(deta))/(2.0*a);

double s = sqrt((x0-x1)(x0-x1) + (y0-y1)(y0-y1));

return s/tmp;

}

double dp[MAXN][1<<MAXN];

const double INF = 1e20;

int main()

{

//freopen("in.txt","r",stdin);

//freopen("out.txt","w",stdout);

int n;

double C;

while(scanf("%d%lf",&n,&C) == 2)

{

if(n == 0 && C == 0)break;

for(int i = 0;i < n;i++)

scanf("%lf%lf%lf%lf",&X[i],&Y[i],&D[i],&S[i]);

for(int i = 0;i < n;i++)

for(int j = 0;j < (1<<n);j++)

dp[i][j] = INF;

for(int i = 0;i < n;i++)

{

dp[i][1<<i] = calc(0.0,0.0,X[i],Y[i],cos(D[i]/180.0*PI),sin(D[i]/180.0*PI),C,S[i]);

}

int tot = (1<<n);

for(int j = 0;j < tot;j++)

for(int i = 0;i < n;i++)

if(j&(1<<i))

{

double nx = S[i]*cos(D[i]/180.0*PI)*dp[i][j] + X[i];

double ny = S[i]*sin(D[i]/180.0*PI)*dp[i][j] + Y[i];

for(int k = 0;k < n;k++)

if((j&(1<<k)) == 0)

{

double tx = S[k]*cos(D[k]/180.0*PI)*dp[i][j] + X[k];

double ty = S[k]*sin(D[k]/180.0*PI)*dp[i][j] + Y[k];

dp[k][j^(1<<k)] = min(dp[k][j^(1<<k)],dp[i][j] + calc(nx,ny,tx,ty,cos(D[k]/180.0*PI),sin(D[k]/180.0*PI),C,S[k]));

}

}

double ans = INF;

for(int i = 0;i < n;i++)

ans = min(ans,dp[i][tot-1]);

printf("%.2lf\n",ans);

}

return 0;

}

J:

Vampire Numbers

暴力搞就可以了。 姿势写不好就容易T。

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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* ***************

Author :kuangbin

Created Time :2014/7/16 21:06:34

File Name :E:\2014ACM\区域赛练习\2011\2011Southeast_USA\J.cpp

************************************************ */

#include <stdio.h>

#include <string.h>

#include <iostream>

#include <algorithm>

#include <vector>

#include <queue>

#include <set>

#include <map>

#include <string>

#include <math.h>

#include <stdlib.h>

#include <time.h>

using namespace std;

int num1[10],num2[10];

bool check(int u,int a,int b)

{

memset(num1,0,sizeof(num1));

memset(num2,0,sizeof(num2));

while(u)

{

num1[u%10]++;

u /= 10;

}

while(a)

{

num2[a%10]++;

a /= 10;

}

while(b)

{

num2[b%10]++;

b /= 10;

}

for(int i = 0;i < 10;i++)

if(num1[i] != num2[i])

return false;

return true;

}

bool check(int n)

{

for(int i = 1;i*i <= n;i++)

if(n%i == 0)

if(check(n,i,n/i))

return true;

return false;

}

int main()

{

//freopen("in.txt","r",stdin);

//freopen("out.txt","w",stdout);

int n;

while(scanf("%d",&n) == 1 && n)

{

while(1)

{

if(check(n))

{

printf("%d\n",n);

break;

}

n++;

}

}

return 0;

}
当然,这题也可以打表。
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/* ***************

Author :kuangbin

Created Time :2014/7/16 21:06:34

File Name :E:\2014ACM\区域赛练习\2011\2011Southeast_USA\J.cpp

************************************************ */

#include <stdio.h>

#include <string.h>

#include <iostream>

#include <algorithm>

#include <vector>

#include <queue>

#include <set>

#include <map>

#include <string>

#include <math.h>

#include <stdlib.h>

#include <time.h>

using namespace std;

int num1[10],num2[10];

bool check(int u,int a,int b)

{

memset(num1,0,sizeof(num1));

memset(num2,0,sizeof(num2));

while(u)

{

num1[u%10]++;

u /= 10;

}

while(a)

{

num2[a%10]++;

a /= 10;

}

while(b)

{

num2[b%10]++;

b /= 10;

}

for(int i = 0;i < 10;i++)

if(num1[i] != num2[i])

return false;

return true;

}

bool check(int n)

{

for(int i = 1;i*i <= n;i++)

if(n%i == 0)

if(check(n,i,n/i))

return true;

return false;

}

int a[]=

{

126,153,688,1206,1255,1260,1395,1435,1503,1530,1827,2187,3159,3784,6880,10251,10255,10426,10521,10525,10575,11259,11844,11848,12006,12060,12384,12505,12546,12550,12595,12600,12762,12843,12955,12964,13243,13545,13950,14035,14350,15003,15030,15246,15300,15435,15624,15795,16272,17325,17428,17437,17482,18225,18265,18270,19026,19215,21375,21586,21753,21870,25105,25375,25474,25510,28476,29632,31509,31590,33655,33696,36855,37840,37845,39784,41665,42898,44676,45684,45760,45864,47538,48672,49855,51759,52168,53865,56295,56875,62968,63895,67149,67392,67950,68800,71199,78975,100255,100525,101299,102051,102505,102510,102541,102550,102595,102942,102955,103968,104026,104260,104368,105021,105025,105075,105210,105250,105264,105295,105723,105750,107163,107329,108126,108135,108216,108612,108864,109525,110758,112468,112509,112590,114268,115672,115699,116478,116496,116725,116928,117067,118408,118440,118480,118575,118926,119848,120006,120060,120384,120600,120762,120843,121086,121576,121815,122746,122764,123084,123354,123538,123840,123894,124483,124488,124542,124978,125005,125050,125095,125248,125433,125460,125500,125950,125995,126000,126027,126108,126846,127417,127620,128403,128430,128943,129438,129505,129514,129550,129564,129595,129640,129775,129955,131242,132430,132565,132615,132655,133245,134275,134725,135045,135450,135828,135837,136525,136854,136948,138784,139500,139824,140035,140350,141345,142978,143500,143739,143793,145273,145314,145345,145683,146137,146520,146952,149364,149782,150003,150030,150246,150300,150435,150624,150826,152271,152406,152460,152608,152685,152946,153000,153436,154350,155277,156024,156240,156289,156325,156915,157950,158193,162072,162526,162720,162976,163255,163795,163854,163944,164583,165208,168520,171598,172246,172386,172822,173250,173925,174028,174082,174208,174280,174298,174370,174793,174802,174820,174982,175329,176215,178294,178942,179325,179428,179482,180225,180297,180621,182065,182250,182650,182700,182974,184126,186624,187029,189702,189742,190260,190827,191205,192150,192375,192685,192717,193257,193945,194229,197428,197482,197725,201852,205785,207391,208624,210375,210681,210753,211896,212868,213075,213466,213750,213759,214506,215086,215424,215455,215860,216733,217503,217530,217638,217854,218488,218700,223524,226498,226872,226876,227448,229648,231579,231673,233896,236754,236758,236925,238968,241506,241564,243175,245182,245448,246150,246928,250105,250510,251005,251050,251095,251896,253750,254740,255010,255100,256315,256410,256414,258795,259510,260338,261378,261783,262984,263074,263155,263736,267034,268398,279328,281736,283198,283648,284598,284760,285376,286416,286974,287356,289674,291375,291753,293625,295105,295510,296320,297463,297832,304717,307183,312475,312565,312655,312975,314199,314743,315009,315090,315490,315594,315625,315900,316255,319059,319536,325615,326155,326452,328419,328864,329346,329656,336195,336550,336960,338296,341284,341653,342688,346288,346725,346968,347913,352966,355995,361989,362992,365638,368104,368550,368784,369189,371893,373864,375156,375615,376992,378400,378418,378450,381429,384912,384925,386415,390847,392566,393246,393417,394875,397840,399784,404932,404968,414895,415575,416065,416259,416650,416988,419287,428980,429664,435784,439582,442975,446760,446976,447916,449676,449955,450688,451768,456840,457168,457600,458640,462672,465088,465984,468535,475380,475893,476892,486720,488592,489159,489955,490176,491688,493857,495328,497682,498550,515907,516879,517509,517590,519745,520168,520816,521608,521680,526792,529672,530379,531297,535968,536539,538650,549765,559188,562950,564912,567648,568750,571648,573768,588676,611793,611878,612598,614965,617728,618759,623758,629680,632875,638950,649638,661288,665919,667876,671409,671490,671944,673920,678892,679500,687919,688000,692712,697248,702189,702918,710496,711099,711909,711990,715959,719199,729688,736695,738468,741928,769792,773896,778936,782896,785295,789250,789525,789750,791289,792585,794088,798682,809919,809937,809964,815958,829696,841995,859968,899019,936985,939658,960988,1000255,1000525,1002501,1002505,1002550,1002595,1002955,1004251,1005025,1005201,1005250,1005295,1008126,1009525,1012099,1012198,1012297,1012396,1012495,1012581,1012594,1012693,1012792,1012891,1012990,1014975,1016568,1016635,1017382,1019722,1020051,1020510,1020537,1021968,1021999,1024555,1024582,1024884,1025005,1025041,1025046,1025050,1025095,1025100,1025410,1025500,1025779,1025950,1025995,1029042,1029420,1029505,1029550,1029595,1029955,1031899,1032565,1032655,1032876,1039680,1040026,1040260,1040368,1041799,1042353,1042542,1042600,1043680,1043968,1045296,1046209,1050021,1050025,1050075,1050210,1050250,1050295,1050750,1051263,1051533,1051699,1052100,1052235,1052500,1052640,1052950,1052995,1053153,1053265,1053315,1057108,1057162,1057230,1057500,1058715,1058890,1061599,1062247,1062517,1063251,1064254,1065325,1065748,1066572,1067166,1068192,1068592,1071063,1071499,1071630,1071958,1072512,1072539,1073029,1073290,1077219,1079239,1079653,1080126,1080135,1080216,1080612,1080864,1081206,1081260,1081350,1081399,1082160,1083285,1083537,1083942,1086012,1086120,1086129,1088640,1088964,1089612,1089913,1090525,1091299,1092816,1095025,1095250,1095295,1098238,1098522,1099525,1104264,1104966,1106424,1106428,1107580,1109295,1113385,1114852,1116684,1116846,1118466,1118736,1123632,1124199,1124680,1124689,1125009,1125090,1125900,1130436,1131448,1134486,1134688,1136268,1137339,1137393,1137933,1138986,1139125,1139229,1140862,1140885,1142680,1144786,1147923,1148175,1150677,1152027,1152225,1152549,1152837,1155996,1156428,1156720,1156833,1156990,1160725,1160995,1163484,1163974,1164096,1164780,1164960,1167250,1167259,1167714,1169280,1169478,1169496,1170670,1172682,1175625,1176039,1176754,1177254,1177384,1178248,1178464,1178635,1179603,1179616,1180242,1181565,1182537,1184008,1184080,1184400,1184625,1184800,1185075,1185678,1185750,1186528,1186992,1187455,1188265,1189206,1189260,1192045,1192554,1193017,1193283,1194831,1195236,1196496,1198408,1198476,1198480,1198575,1198926,1199848,1200006,1200060,1200384,1200600,1200762,1200843,1201086,1201815,1202355,1203084,1203651,1203840,1203894,1204168,1205406,1205482,1205595,1205685,1206000,1206108,1206814,1207620,1207714,1208196,1208403,1208430,1208943,1209541,1209564,1209735,1210806,1210860,1215180,1215760,1215972,1216894,1216948,1218015,1218150,1219576,1225462,1226745,1227460,1227640,1227694,1229548,1229674,1230084,1230840,1230894,1232896,1233540,1234768,1234876,1235038,1235380,1236384,1236726,1236748,1236874,1237369,1237468,1237486,1238400,1238584,1238940,1238994,1240537,1240677,1240843,1241284,1243584,1244502,1244830,1244880,1245208,1245420,1245964,1246396,1247958,1248876,1249528,1249668,1249780,1250005,1250050,1250095,1250496,1250500,1250950,1250964,1250995,1252480,1253065,1253632,1254330,1254600,1254748,1255000,1255005,1255729,1255810,1256436,1256490,1256530,1256827,1258816,1259473,1259500,1259649,1259793,1259950,1259995,1260000,1260108,1260270,1261080,1261399,1261885,1262079,1263456,1263604,1263748,1264086,1264536,1265305,1265530,1268316,1268374,1268460,1269342,1269774,1270647,1270948,1271943,1274170,1274368,1274665,1274836,1274872,1275264,1275286,1275925,1276065,1276200,1276348,1276524,1276834,1279642,1280524,1281582,1282716,1283166,1283359,1283476,1283544,1283674,1283746,1284003,1284030,1284300,1284435,1285384,1285915,1286374,1286608,1286968,1287436,1287634,1288354,1289376,1289403,1289430,1289943,1290564,1291234,1291675,1292458,1292746,1294380,1294519,1295005,1295014,1295050,1295095,1295140,1295500,1295640,1295644,1295694,1295950,1295964,1295995,1296400,1296648,1297611,1297750,1298475,1298632,1299505,1299550,1299595,1299955,1302448,1302565,1302655,1302714,1303438,1304118,1305265,1306246,1306278,1306525,1307826,1312420,1312542,1312726,1314895,1318648,1320241,1320475,1320493,1320867,1322046,1322455,1324125,1324300,1324584,1324854,1324917,1325065,1325650,1325695,1325776,1325965,1326150,1326204,1326415,1326505,1326550,1326595,1326717,1326955,1328445,1329565,1329655,1332450,1335442,1336176,1338246,1338768,1339416,1340163,1341027,1341274,1342750,1342768,1342876,1345360,1347250,1347628,1347682,1348276,1348285,1348762,1348974,1348996,1349023,1350045,1350450,1352286,1352416,1352457,1352664,1352929,1354284,1354288,1354500,1356376,1356498,1357398,1357884,1357924,1358280,1358370,1358442,1360435,1361785,1362438,1362748,1362874,1365250,1367428,1367482,1368054,1368274,1368432,1368540,1368594,1368742,1369480,1369732,1371784,1373071,1374268,1374286,1374628,1374682,1374826,1374862,1375479,1379128,1379448,1380645,1381743,1386571,1387840,1387984,1388178,1392435,1395000,1395648,1396782,1397281,1398240,1400035,1400350,1401696,1402533,1402695,1402978,1403500,1406137,1409278,1409782,1413045,1413445,1413450,1413472,1417437,1418679,1418976,1419165,1420978,1423318,1425375,1425753,1426225,1427368,1427899,1428736,1429780,1429798,1429978,1430941,1432768,1432876,1434069,1435000,1435036,1436472,1436526,1436728,1436872,1437039,1437093,1437268,1437286,1437309,1437390,1437520,1437903,1437930,1439059,1439739,1439793,1443096,1443906,1448392,1452343,1452730,1452888,1453140,1453450,1455970,1456798,1456803,1456830,1458810,1458828,1458832,1459354,1461370,1462072,1463728,1465200,1465290,1465870,1468372,1468953,1469520,1470568,1471365,1472368,1472836,1473628,1473664,1473678,1473682,1473934,1475266,1475635,1476328,1476688,1476832,1480279,1482138,1482736,1483276,1483672,1483726,1484892,1486372,1487236,1487286,1487362,1487632,1489752,1492456,1492632,1493640,1493739,1493793,1493964,1495683,1495786,1497366,1497802,1497820,1497982,1498032,1498783,1499782,1500003,1500030,1500246,1500300,1500435,1500624,1502406,1502460,1502946,1503000,1504350,1506024,1506240,1506294,1506325,1506523,1507968,1508026,1508260,1510267,1510533,1512396,1518264,1519978,1520365,1520608,1520766,1522710,1523277,1524006,1524060,1524339,1524600,1524762,1524978,1525630,1526080,1526287,1526305,1526850,1529325,1529406,1529460,1529946,1530000,1530054,1530625,1531053,1532389,1532560,1532605,1532776,1533105,1534360,1537263,1537425,1538181,1538433,1538964,1541938,1542343,1542496,1543284,1543500,1543716,1547334,1548738,1552630,1552770,1553260,1553269,1553409,1558228,1558426,1560024,1560240,1560325,1562224,1562346,1562400,1562530,1562890,1563025,1563048,1563250,1563264,1563295,1563507,1565329,1568484,1569150,1570392,1572925,1574253,1576827,1579419,1579486,1579500,1579648,1581268,1581930,1583145,1583865,1584432,1585390,1586245,1586304,1587820,1588158,1590435,1590835,1591884,1592419,1594138,1596325,1597725,1599426,1601626,1603255,1605208,1605325,1608246,1608520,1608624,1613538,1614235,1614262,1615374,1615833,1620072,1620720,1624338,1624536,1625026,1625260,1625305,1625476,1625530,1626322,1627200,1627348,1627524,1627632,1627857,1628734,1629396,1629576,1629760,1630255,1630287,1630525,1632505,1632550,1632595,1632708,1632748,1632874,1632955,1633545,1634728,1634872,1637950,1638054,1638540,1638594,1639440,1642356,1642455,1643292,1645312,1645735,1645803,1645830,1645839,1647436,1647828,1648732,1649583,1652008,1652080,1652472,1652584,1657062,1662039,1664892,1667952,1672348,1672398,1672528,1672834,1672884,1672965,1673257,1673428,1673482,1673752,1674328,1674832,1675728,1677672,1679458,1680520,1682032,1682608,1682734,1683274,1683346,1683472,1685200,1687149,1687234,1687342,1687432,1687950,1688328,1691865,1693237,1693795,1695537,1698327,1698412,1698642,1698750,1699137,1702345,1702624,1704312,1704339,1712434,1713649,1715098,1715980,1716975,1717699,1718248,1722460,1723036,1723468,1723486,1723698,1723806,1723860,1723927,1724184,1724886,1726348,1726834,1726884,1727896,1728220,1728342,1728346,1728634,1732153,1732414,1732500,1734129,1734268,1734286,1734628,1734682,1734826,1734862,1739128,1739250,1739925,1740028,1740082,1740208,1740235,1740280,1740298,1740802,1740820,1740982,1742008,1742080,1742098,1742800,1742958,1742980,1742998,1743268,1743286,1743700,1743997,1746328,1746832,1747039,1747930,1748002,1748020,1748200,1748326,1748632,1749802,1749820,1749982,1750432,1753290,1755918,1756890,1758393,1759198,1760535,1762069,1762150,1762384,1765273,1768248,1772941,1775038,1779975,1780294,1780942,1782094,1782562,1782940,1782994,1783584,1784695,1785204,1785726,1789402,1789420,1789942,1790995,1792386,1793250,1793925,1794028,1794082,1794208,1794280,1794298,1794802,1794820,1794883,1794982,1795680,1798294,1798942,1799325,1799428,1799482,1800225,1802250,1802727,1802970,1802974,1804288,1806021,1806210,1807029,1809702,1809742,1812636,1813747,1815835,1820065,1820227,1820650,1820763,1820875,1820974,1822500,1823845,1823976,1824732,1825416,1826055,1826500,1826892,1827000,1828075,1828701,1829079,1829740,1829794,1829974,1831752,1834128,1835046,1835644,1839744,1839852,1841260,1847286,1851988,1852384,1854832,1854972,1856272,1856277,1858212,1861249,1863504,1866240,1867216,1867536,1870209,1870290,1871428,1873264,1874520,1879195,1879326,1882435,1887291,1890265,1890702,1893258,1895364,1897020,1897213,1897402,1897420,1897942,1899742,1900521,1902109,1902465,1902600,1902775,1904274,1904728,1905025,1908270,1908324,1908522,1909026,1909215,1912050,1912806,1913886,1914129,1915893,1917958,1919232,1920235,1920285,1920555,1920919,1921500,1923628,1923750,1925658,1925896,1926504,1926850,1927062,1927170,1928115,1929816,1932417,1932570,1934946,1935220,1935756,1937592,1937848,1938321,1939450,1942290,1942978,1946853,1949782,1950835,1956325,1962675,1963255,1965433,1965537,1965820,1966288,1967238,1968219,1973826,1974028,1974082,1974208,1974280,1974298,1974802,1974820,1974982,1977250,1978294,1978942,1979428,1979482,1979725,1979802,1980252,1982061,1982974,1984248,1985328,1989742,1994265,1997428,1997482};

int main()

{

//freopen("in.txt","r",stdin);

//freopen("out.txt","w",stdout);

int n;

/*

int cnt = 0;

for(int i = 10;i <= 2000000;i++)

if(check(i))

a[cnt++] = i;

for(int i = 0;i < cnt;i++)

printf("%d,",a[i]);

cout<<endl;

*/

int cnt = sizeof(a)/sizeof(int);

while(scanf("%d",&n) == 1 && n)

{

int t = lower_bound(a,a+cnt,n)-a;

printf("%d\n",a[t]);

}

return 0;

}
------ 本文结束------
  • 本文作者: kuangbin
  • 本文链接: 255.html
  • 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!
0%