首页 > 代码库 > usaco-2.4-ttwo-pass

usaco-2.4-ttwo-pass

oh,pass!First,I think it‘s a game,hehe.....

/*ID: qq104801LANG: C++TASK: ttwo*/#include <iostream>#include <fstream>#include <cstring>#include <vector>#include <list>#include <set>#include <cstdio>#include <algorithm>using namespace std;//visited?bool v[10][10][4][10][10][4]={false};//gridchar g[10][10];//farmer row,col,directionint fr,fc,fd;int cr,cc,cd;//int inc row/col each stepint ddr[4]={-1,0,1,0};int ddc[4]={0,1,0,-1};bool canadvance(int i,int j){    if(i>=0&&i<=9&&j>=0&&j<=9&&g[i][j]!=*)        return true;    else         return false;}void move(){    if(canadvance(fr+ddr[fd],fc+ddc[fd]))        fr+=ddr[fd],fc+=ddc[fd];    else        fd+=1,fd%=4;        if(canadvance(cr+ddr[cd],cc+ddc[cd]))        cr+=ddr[cd],cc+=ddc[cd];        else        cd+=1,cd%=4;    }void test(){        freopen("ttwo.in","r",stdin);    freopen("ttwo.out","w",stdout);    int n=10;    for(int i=0;i<n;i++)            for(int j=0;j<n;j++)        {            cin>>g[i][j];            if(g[i][j]==F)                fr=i,fc=j,fd=0;            if(g[i][j]==C)                cr=i,cc=j,cd=0;        }    v[fr][fc][fd][cr][cc][cd]=true;    int count=0;    while(true)    {        move();        count++;        if((fr==cr)&&(fc==cc))        {            cout<<count<<endl;            break;        }        if (v[fr][fc][fd][cr][cc][cd])        {            cout<<0<<endl;            break;        }        v[fr][fc][fd][cr][cc][cd]=true;    }}int main () {            test();            return 0;}

test data:

USACO TrainingGrader Results     15 users onlineAUS/1 CAN/1 CHN/6 IND/1 SGP/1 USA/5USER: cn tom [qq104801]TASK: ttwoLANG: C++Compiling...Compile: OKExecuting...   Test 1: TEST OK [0.003 secs, 3528 KB]   Test 2: TEST OK [0.003 secs, 3528 KB]   Test 3: TEST OK [0.005 secs, 3528 KB]   Test 4: TEST OK [0.003 secs, 3528 KB]   Test 5: TEST OK [0.003 secs, 3528 KB]   Test 6: TEST OK [0.005 secs, 3528 KB]   Test 7: TEST OK [0.008 secs, 3528 KB]   Test 8: TEST OK [0.003 secs, 3528 KB]   Test 9: TEST OK [0.005 secs, 3528 KB]All tests OK.YOUR PROGRAM (‘ttwo‘) WORKED FIRST TIME! That‘s fantastic -- and a rare thing. Please accept these special automated congratulations.Here are the test data inputs:------- test 1 ----.****...*...*......**...................*........**.**.*..**F..*......***....*.*.C.......*.......*.*------- test 2 ----..................................*.........F.........C.............................................------- test 3 ----...........********..********..********..********..********..********.C********..********.F.........------- test 4 ----...........*................*....*............*.......*.*...F....*......*.......C......*..*.........------- test 5 ----...*.....***.......*.....*..*.*.*................*F.....*.*.**.*C....*.......**......*........*.*...------- test 6 ----.................C............****..****...*..*......*..*...****..****............F.................------- test 7 ----*...*....*.......*...*...*.F...*............*..**.*.......*.......**..*..C........*...*..**.....*.*.------- test 8 ----*..C.**.....**...*.***......*......**.*.......*.**.......**.**..**...*.**.......*...*....**...F.*...------- test 9 ----*.*.**..*.*.*.*..*.**.*.**.****.*.C*.*.****.**.*.*..........F***...**.*.....*..**.....*..*.***...**.Keep up the good work!Thanks for your submission!

 

usaco-2.4-ttwo-pass