一道模拟题不过要担心的是牛或者人在转弯的时候,另一方如果能走,那么要走,不能停留。

还是蛮简单的。

调试输出的话可以看到具体追击过程

Source Code:

/*
ID: wushuai2
PROG: ttwo
LANG: 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>
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
#define MOD 1000000007
#define pi acos(-1.0)
#define RV(num) ((num) > 0 ? 0 : 1) using namespace std; typedef long long ll ;
typedef unsigned long long ull ;
typedef unsigned int uint ;
typedef unsigned char uchar ; template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;} const double eps = 1e- ;
const int M = ;
const ll P = 10000000097ll ;
const int INF = 0x3f3f3f3f ;
const int MAX_N = ;
const int MAXSIZE = ; ofstream fout ("ttwo.out");
ifstream fin ("ttwo.in"); int dir[][] = {{-, }, {, }, {, }, {, -}};
char gra[][];
int dir_f, dir_c; struct sc{
int x, y;
}pos[], nxt_pos[], sta[]; bool check(int x, int y){
if(x >= && x <= && y >= && y <= ){
if(gra[x][y] != '*'){
return true;
}
}
return false;
} bool finish(){
if(pos[].x == pos[].x && pos[].y == pos[].y){
return true;
} else return false;
} int main(){
int i, j, k, l, m, n, t, s, c, w, q, u, v, num, val;
for(i = ; i <= ; ++i){
for(j = ; j <= ; ++j){
fin >> gra[i][j];
if(gra[i][j] == 'F'){
sta[].x = i, sta[].y = j;
//pos[0].x = i, pos[0].y = j;
} else if(gra[i][j] == 'C'){
sta[].x = i, sta[].y = j;
//pos[1].x = i, pos[1].y = j;
}
}
}
int ans = ;
int dir_f = ;
int dir_c = ;
pos[] = sta[], pos[] = sta[];
for(;;){
/*
for(i = 1; i <= 10; ++i){
for(j = 1; j <= 10; ++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[].x = pos[].x + dir[dir_f][];
nxt_pos[].y = pos[].y + dir[dir_f][];
nxt_pos[].x = pos[].x + dir[dir_c][];
nxt_pos[].y = pos[].y + dir[dir_c][];
if(check(nxt_pos[].x, nxt_pos[].y) && check(nxt_pos[].x, nxt_pos[].y)){
pos[] = nxt_pos[], pos[] = nxt_pos[];
} else if(!check(nxt_pos[].x, nxt_pos[].y) && !check(nxt_pos[].x, nxt_pos[].y)){
dir_f = (dir_f + ) % ;
dir_c = (dir_c + ) % ;
} else if(check(nxt_pos[].x, nxt_pos[].y) && !check(nxt_pos[].x, nxt_pos[].y)){
dir_c = (dir_c + ) % ;
pos[] = nxt_pos[];
} else if(!check(nxt_pos[].x, nxt_pos[].y) && check(nxt_pos[].x, nxt_pos[].y)){
dir_f = (dir_f + ) % ;
pos[] = nxt_pos[];
}
if(finish()){
break;
}
++ans;
if(ans > ){
ans = ;
break;
}
} fout << ans << endl;
fin.close();
fout.close();
return ;
}

USACO The Tamworth Two 模拟的更多相关文章

  1. USACO2.4 The Tamworth Two[模拟]

    题目描述 两只牛逃跑到了森林里.农夫John开始用他的专家技术追捕这两头牛.你的任务是模拟他们的行为(牛和John). 追击在10x10的平面网格内进行.一个格子可以是: 一个障碍物, 两头牛(它们总 ...

  2. 【USACO】Transformations(模拟)

    Transformations A square pattern of size N x N (1 <= N <= 10) black and white square tiles is ...

  3. USACO 1.2 Transformations (模拟)

    模拟题目,依照题目给定的要求变换图形就可以,变换的优先级依次减小. 这个题目我写的非常乱.只是最还还是勉强能够执行 /* ID:twd30651 PROG:transform LANG:C++ */ ...

  4. 【题解】Acting Cute

    题目简介 正在 rainbow 的城堡游玩的 Freda 恰好看见了在地毯上跳舞卖萌的水叮当--于是-- Freda:"呜咕>_< 我也要卖萌T_T!" rainbow ...

  5. USACO 1.3... 虫洞 解题报告(搜索+强大剪枝+模拟)

    这题可真是又让我找到了八数码的感觉...哈哈. 首先,第一次见题,没有思路,第二次看题,感觉是搜索,就这样写下来了. 这题我几乎是一个点一个点改对的(至于为什么是这样,后面给你看一个神奇的东西),让我 ...

  6. Your Ride Is Here 你的飞碟在这儿 USACO 模拟

    1001: 1.1.1 Your Ride Is Here 你的飞碟在这儿 时间限制: 1 Sec  内存限制: 128 MB提交: 9  解决: 9[提交] [状态] [讨论版] [命题人:外部导入 ...

  7. USACO Runaround Numbers 模拟

    根据题意的 Runaround 规则去找比当前数大的最近的一个 Runaround数字 模拟题~ Source code: /* ID: wushuai2 PROG: runround LANG: C ...

  8. Transformations 方块转换 USACO 模拟 数组 数学 耐心

    1006: 1.2.2 Transformations 方块转换 时间限制: 1 Sec  内存限制: 128 MB提交: 10  解决: 7[提交] [状态] [讨论版] [命题人:外部导入] 题目 ...

  9. Milking Cows 挤牛奶 USACO 排序 模拟

    1005: 1.2.1 Milking Cows 挤牛奶 时间限制: 1 Sec  内存限制: 128 MB提交: 15  解决: 9[提交] [状态] [讨论版] [命题人:外部导入] 题目描述 1 ...

随机推荐

  1. [转]iOS多线程编程之NSThread的使用

    1.简介: 1.1 iOS有三种多线程编程的技术,分别是: 1..NSThread 2.Cocoa NSOperation (iOS多线程编程之NSOperation和NSOperationQueue ...

  2. Linux下使用ps命令来查看Oracle相关的进程

    Linux下可以使用ps命令来查看Oracle相关的进程 Oracle Listener 这个命令会列出Oracle Net Listener的进程 [oracle@ www.linuxidc.com ...

  3. 从51跳cortex-m0学习2——程序详解

    跳cortex-m0——思想转变>之后又一入门级文章,在此不敢请老鸟们过目.不过要是老鸟们低头瞅了一眼,发现错误,还请教育之,那更是感激不尽.与Cortex在某些操作方式上的异同,让自己对Cor ...

  4. Delphi函数指针的两种定义(对象方法存在一个隐藏参数self,所以不能相互赋值)

    delphi中经常见到以下两种定义 Type TMouseProc = procedure (X,Y:integer); TMouseEvent = procedure (X,Y:integer) o ...

  5. perl unicode utf-8 \x转换

    [root@dr-mysql01 ~]# cat x5.pl use Encode; use JSON; use URI::Escape; use LWP::Simple; my $host = &q ...

  6. Ubuntu系统下在Eclipse中使用真实手机运行调试Android应用

    本文是在Ubuntu下已搭建好JRE+Eclipse+AndroidSDK的环境中进行的. 如果从未进行过如下的操作的话,在运行Android应用时,在设备选择器那里你的手机会显示为一大串" ...

  7. 如何用python抓取js生成的数据 - SegmentFault

    如何用python抓取js生成的数据 - SegmentFault 如何用python抓取js生成的数据 1赞 踩 收藏 想写一个爬虫,但是需要抓去的的数据是js生成的,在源代码里看不到,要怎么才能抓 ...

  8. Warning: Unable to send packet: Error with PF_PACKET send() [11]: Message too long (errno = 90)

    今天在使用tcpreplay重放流量时,发现有的数据包没有发送成功: Warning: Unable to send packet: Error with PF_PACKET send() [215] ...

  9. Hat’s Words(字典树)

    Hat’s Words Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  10. Java之JDOM生成XML和解析

    一.生成XML文件 1.JDOM是对Java原始的类进行了封装.让解析XML文件变得很方便 2.创建一个XML文件的根节点: Element root = new Element("HD&q ...