首页 > 代码库 > usaco-5.2-snail-passed
usaco-5.2-snail-passed
有点水:
/*ID: qq104801LANG: C++TASK: snailQQ: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:
USACO TrainingGrader Results 6 users onlineCHN/2 MYS/1 NZL/1 TJK/1 USA/1USER: cn tom [qq104801]TASK: snailLANG: C++Compiling...Compile: OKExecuting... 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 4E2A6G1F5------- test 2 [length 16 bytes] ----5 4C1B4D5E4------- test 3 [length 35 bytes] ----8 10A3B1B6C5D2E7F4G1G6H8------- test 4 [length 37 bytes] ----10 10A2A9B2C7D4F5G8H3I10J1------- test 5 [length 33 bytes] ----10 9A9B2C7D4F5G8H3I10J1------- test 6 [length 48 bytes] ----10 14A3C1B4D2C5E3D6F4E7G5F8H6G9I7------- test 7 [length 81 bytes] ----15 22I1C2M2G3K3D5N5F6J6B7H8G9I9B10N10E11K11F13J13C14M14H15------- test 8 [length 67 bytes] ----15 18I1B2N2H3C5M5H6A7O7G9I9H10A11O11G13I13A15O15------- test 9 [length 76 bytes] ----20 20C1G1K1O1S1T1A3A7A11A15A19A20E20I20M20Q20T5T9T13T17------- test 10 [length 136 bytes] ----20 37F1I1Q1D2O2A3L4S4P5K6A7C7E7I7K7Q8F9Q9J10L10E11O11I12F13K13A14P14R14P15I16E17S17F18L18T18H19E20------- test 11 [length 183 bytes] ----120 48T1B2F3R3U3L4E5J6M6D8K8F9A11C11M10L11P6R7O8Q9N10P11M12O13L14N15K16M17J18L19I20K21H22J23G24I25F26H27E28G29D30F31C32E33B34D35A36C37------- test 12 [length 271 bytes] ----120 72A4A8A12A16A20A24C4E6F8H10I12K14L16N18O20Q22R24S25T26D1E2F3G4G5H6I7J8J9K10L11M12M13N14O15P16P17Q18R19S20S21T22U23V24H2J4K6M8N10P12Q14S16T18V20Y2Y6Y10Y14Y18Y22Y26Z3Z5Z7Z9Z11Z13Z15Z17Z19Z21Z23Z25Keep up the good work!Thanks for your submission!
usaco-5.2-snail-passed
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。