Usaco the Tamworth-simulation

Source: Internet
Author: User

A simulation problem but to worry about is the cow or the person in the turn, if the other side can walk, then must go, cannot stay.

It's pretty simple.

Debug the output, you can see the specific pursuit process

Source Code:

/*id:wushuai2prog:ttwolang:c++*///#pragma COMMENT (linker, "/stack:16777216")//For C + + Compiler#include <stdio.h>#include<iostream>#include<fstream>#include<cstring>#include<cmath>#include<stack>#include<string>#include<map>#include<Set>#include<list>#include<queue>#include<vector>#include<algorithm>#defineMax (b) ((a) > (b))? (a): (b))#defineMin (b) ((a) < (a))? (a): (b))#defineAbs (x) (((x) > 0)? (x): (-(x)))#defineMOD 1000000007#definePi ACOs (-1.0)#defineRV (num) (num) > 0? 0:1)using namespaceStd;typedefLong Longll; typedef unsignedLong Longull; typedef unsignedint        UINT; typedef unsignedCharUchar; template<classT> InlinevoidCheckmin (T &a,t b) {if(a>b) a=b;} Template<classT> InlinevoidCheckmax (T &a,t b) {if(a<b) a=b;}Const DoubleEPS = 1e-7      ;Const intM =660000         ;Constll P =10000000097ll;Const intINF =0x3f3f3f3f   ;Const intMax_n = -         ;Const intMAXSIZE =101000000; ofstream Fout ("Ttwo.out"); ifstream Fin ("ttwo.in");intdir[4][2] = {{-1,0}, {0,1}, {1,0}, {0, -1}};Chargra[ One][ One];intdir_f, Dir_c;structsc{intx, y;} pos[2], nxt_pos[2], sta[2];BOOLCheckintXinty) {    if(x >=1&& x <=Ten&& y >=1&& y <=Ten){        if(Gra[x][y]! ='*'){            return true; }    }    return false;}BOOLFinish () {if(pos[0].x = = pos[1].x && pos[1].y = = pos[0].y) {return true; } Else  return false;}intMain () {intI, J, K, L, M, N, T, S, c, W, q, u, V, num, Val;  for(i =1; I <=Ten; ++i) {         for(j =1; J <=Ten; ++j) {Fin>>Gra[i][j]; if(Gra[i][j] = ='F') {sta[0].x = i, sta[0].Y =J; //pos[0].x = i, pos[0].y = j;}Else if(Gra[i][j] = ='C') {sta[1].x = i, sta[1].Y =J; //pos[1].x = i, pos[1].y = j;            }        }    }    intAns =1; intDir_f =0; intDir_c =0; pos[0] = sta[0], pos[1] = sta[1];  for(;;) {        /*For (i = 1; I <=, ++i) {for (j = 1; J <=; ++j) {if (pos[0].x = = i && ;                Pos[0].y = = j) {fout << ' F ';                } else if (pos[1].x = = I && pos[1].y = = j) {fout << ' C ';                } else if (gra[i][j] = = ' * ') fout << ' * ';            else Fout << '. ';        } fout << Endl;        } fout << Endl; */nxt_pos[0].x = pos[0].x + dir[dir_f][0]; nxt_pos[0].Y = pos[0].y + dir[dir_f][1]; nxt_pos[1].x = pos[1].x + dir[dir_c][0]; nxt_pos[1].Y = pos[1].y + dir[dir_c][1]; if(Check (nxt_pos[0].x, nxt_pos[0].Y) && Check (nxt_pos[1].x, nxt_pos[1].y)) {pos[0] = nxt_pos[0], pos[1] = nxt_pos[1]; } Else if(!check (nxt_pos[0].x, nxt_pos[0].Y) &&!check (nxt_pos[1].x, nxt_pos[1].y)) {Dir_f= (Dir_f +1) %4; Dir_c= (Dir_c +1) %4; } Else if(Check (nxt_pos[0].x, nxt_pos[0].Y) &&!check (nxt_pos[1].x, nxt_pos[1].y)) {Dir_c= (Dir_c +1) %4; pos[0] = nxt_pos[0]; } Else if(!check (nxt_pos[0].x, nxt_pos[0].Y) && Check (nxt_pos[1].x, nxt_pos[1].y)) {Dir_f= (Dir_f +1) %4; pos[1] = nxt_pos[1]; }        if(Finish ()) { Break; }        ++ans; if(Ans >10000) {ans=0;  Break; }} fout<< ans <<Endl;    Fin.close ();    Fout.close (); return 0;}

Usaco the Tamworth-simulation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.