• usaco-2.4-ttwo-pass


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

    /*
    ID: qq104801
    LANG: 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};
    //grid
    char g[10][10];
    //farmer row,col,direction
    int fr,fc,fd;
    int cr,cc,cd;
    //int inc row/col each step
    int 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 Training
    Grader Results     
    15 users online
    AUS/1 CAN/1 CHN/6 IND/1 SGP/1 USA/5
    
    USER: cn tom [qq104801]
    TASK: ttwo
    LANG: C++
    
    Compiling...
    Compile: OK
    
    Executing...
       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!
    /***********************************************

    看书看原版,原汁原味。

    不会英文?没关系,硬着头皮看下去慢慢熟练,才会有真正收获。

    没有原书,也要网上找PDF来看。

    网上的原版资料多了去了,下载东西也到原始下载点去看看。

    你会知其所以然,呵呵。

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

  • 相关阅读:
    零知识证明入门
    Vue入门语法(二)表单,组件,路由和ajax
    Vue入门语法(一)
    okexchain整体架构分析
    写了个unsigned Tx生成二维码的web站点
    metamusk与web3相关资料
    QRCode.js:使用 JavaScript 生成二维码
    js工程安装,发布等命令
    C语言学习笔记-9.结构体
    C语言学习笔记-8.指针
  • 原文地址:https://www.cnblogs.com/dpblue/p/3959286.html
Copyright © 2020-2023  润新知