码迷,mamicode.com
首页 > 其他好文 > 详细

usaco-5.2-snail-passed

时间:2014-10-01 19:29:31      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   for   sp   

有点水:

/*
ID: qq104801
LANG: C++
TASK: snail
QQ:104804687
*/

#include <iostream>
#include <fstream>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>

using namespace std;

#define loop(i,n) for(int i=0;i<(n);i++)
#define loop2(i,n) for(int i=1;i<=(n);i++)
const int maxn=205;
const int inf=1<<30;

int n,m,k;
int a[maxn][maxn];
int go[4][2]={{0,-1},{1,0},{0,1},{-1,0}};
int ans;

void dfs(int y,int x,int turn,int step)
{
  if(step-1>ans)ans=step-1;
  if(a[y][x]==1)
  {
    y-=go[turn][1];
    x-=go[turn][0];
    k=(turn+1)%4;
    if(!a[y+go[k][1]][x+go[k][0]])
      dfs(y+go[k][1],x+go[k][0],k,step);
    k=(turn+3)%4;
    if(!a[y+go[k][1]][x+go[k][0]])
      dfs(y+go[k][1],x+go[k][0],k,step);
    return;
  }
  if(a[y][x]==2)return;
  a[y][x]=2;
  dfs(y+go[turn][1],x+go[turn][0],turn,step+1);
  a[y][x]=0;
}

void test()
{   
  freopen("snail.in","r",stdin);  
  freopen("snail.out","w",stdout); 
  cin>>n>>m;  
  for(int i=0;i<=n+1;i++)a[0][i]=a[n+1][i]=a[i][0]=a[i][n+1]=1;
  int ii;
  char c;
  while(m--)
  {
    cin>>c>>ii;
    a[ii][c-A+1]=1;
  }
  ans=0;
  dfs(1,1,1,1);
  dfs(1,1,2,1);
  cout<<ans<<endl;
}

int main () 
{        
    test();        
    return 0;
}

test data:

bubuko.com,布布扣
USACO Training
Grader Results     
6 users online
CHN/2 MYS/1 NZL/1 TJK/1 USA/1

USER: cn tom [qq104801]
TASK: snail
LANG: C++

Compiling...
Compile: OK

Executing...
   Test 1: TEST OK [0.003 secs, 3536 KB]
   Test 2: TEST OK [0.005 secs, 3536 KB]
   Test 3: TEST OK [0.005 secs, 3536 KB]
   Test 4: TEST OK [0.008 secs, 3536 KB]
   Test 5: TEST OK [0.005 secs, 3536 KB]
   Test 6: TEST OK [0.005 secs, 3536 KB]
   Test 7: TEST OK [0.005 secs, 3536 KB]
   Test 8: TEST OK [0.005 secs, 3536 KB]
   Test 9: TEST OK [0.005 secs, 3536 KB]
   Test 10: TEST OK [0.011 secs, 3536 KB]
   Test 11: TEST OK [0.005 secs, 3536 KB]
   Test 12: TEST OK [0.041 secs, 3536 KB]

All tests OK.

YOUR PROGRAM (‘snail‘) WORKED FIRST TIME! That‘s fantastic -- and a rare thing. Please accept these special automated congratulations.

Here are the test data inputs:

------- test 1 [length 16 bytes] ----
8 4
E2
A6
G1
F5
------- test 2 [length 16 bytes] ----
5 4
C1
B4
D5
E4
------- test 3 [length 35 bytes] ----
8 10
A3
B1
B6
C5
D2
E7
F4
G1
G6
H8
------- test 4 [length 37 bytes] ----
10 10
A2
A9
B2
C7
D4
F5
G8
H3
I10
J1
------- test 5 [length 33 bytes] ----
10 9
A9
B2
C7
D4
F5
G8
H3
I10
J1
------- test 6 [length 48 bytes] ----
10 14
A3
C1
B4
D2
C5
E3
D6
F4
E7
G5
F8
H6
G9
I7
------- test 7 [length 81 bytes] ----
15 22
I1
C2
M2
G3
K3
D5
N5
F6
J6
B7
H8
G9
I9
B10
N10
E11
K11
F13
J13
C14
M14
H15
------- test 8 [length 67 bytes] ----
15 18
I1
B2
N2
H3
C5
M5
H6
A7
O7
G9
I9
H10
A11
O11
G13
I13
A15
O15
------- test 9 [length 76 bytes] ----
20 20
C1
G1
K1
O1
S1
T1
A3
A7
A11
A15
A19
A20
E20
I20
M20
Q20
T5
T9
T13
T17
------- test 10 [length 136 bytes] ----
20 37
F1
I1
Q1
D2
O2
A3
L4
S4
P5
K6
A7
C7
E7
I7
K7
Q8
F9
Q9
J10
L10
E11
O11
I12
F13
K13
A14
P14
R14
P15
I16
E17
S17
F18
L18
T18
H19
E20
------- test 11 [length 183 bytes] ----
120 48
T1
B2
F3
R3
U3
L4
E5
J6
M6
D8
K8
F9
A11
C11
M10
L11
P6
R7
O8
Q9
N10
P11
M12
O13
L14
N15
K16
M17
J18
L19
I20
K21
H22
J23
G24
I25
F26
H27
E28
G29
D30
F31
C32
E33
B34
D35
A36
C37
------- test 12 [length 271 bytes] ----
120 72
A4
A8
A12
A16
A20
A24
C4
E6
F8
H10
I12
K14
L16
N18
O20
Q22
R24
S25
T26
D1
E2
F3
G4
G5
H6
I7
J8
J9
K10
L11
M12
M13
N14
O15
P16
P17
Q18
R19
S20
S21
T22
U23
V24
H2
J4
K6
M8
N10
P12
Q14
S16
T18
V20
Y2
Y6
Y10
Y14
Y18
Y22
Y26
Z3
Z5
Z7
Z9
Z11
Z13
Z15
Z17
Z19
Z21
Z23
Z25

Keep up the good work!
Thanks for your submission!
View Code

 

usaco-5.2-snail-passed

标签:style   blog   http   color   io   os   ar   for   sp   

原文地址:http://www.cnblogs.com/dpblue/p/4003453.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!