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

还是蛮简单的。

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

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. Git Command Summary (Updated)

    取得Git仓库 初始化一个版本仓库 git init Clone远程版本库 git clone git@xbc.me:wordpress.git 添加远程版本库origin,语法为 git remot ...

  2. Webx pull service

    1.概述 pull service的功能是将对象置入模板中.被pull service放到模板中的对象,不需要应用程序的干预即可直接使用.如果模板没有用到某个对象,则不会产生创建该对象的开销.看起来, ...

  3. freebsd

    #cd /usr/ports/devel/binutils && make install

  4. NuGet安装软件包故障解决

    今晚在家工作,使用NuGet安装 Install-Package Microsoft.AspNet.Web.Optimization 时,一直提示无法连接到nuget.org. 搜索后,可使用如下方法 ...

  5. Javascript中的位运算符和技巧

    ECMAScript 整数有两种类型,即有符号整数(允许用正数和负数)和无符号整数(只允许用正数).在 ECMAScript 中,所有整数字面量默认都是有符号整数,这意味着什么呢? 有符号整数使用 3 ...

  6. Silverlight CheckBoxList

    项目要用到复选框,可是在Silverlight中不存在CheckBoxList.通过查阅资料以及依据自己的理解,写了简单演示样例: 1.XAML <UserControl x:Class=&qu ...

  7. 用javap命令反编译来分析字符串问题

    编写Test.java.编译完后生成Test.class文件,然后对该文件运行javap -c Test命令,生成字节码指令.阅读并得出结论 一.s1和s2指向常量池的不同常量 ①java代码 pub ...

  8. Unity的NGUI插件篇——入场效果

    Unity的NGUI插件篇--入场效果 入场效果 入场效果须要借助于NGUI提供的TweenPosition类来完毕.为了说明此类的用法.本节将使会解说两个演示样例.本文选自  大学霸 <NGU ...

  9. js取整

    综述 js中经常会遇到取整问题,所以做了下总结.总的来说分为两个方面,直接取整(不考虑小数点后的部分)还是计算后取整(例如四舍五入,向上取整等). 一.直接取整 1.parseInt(number) ...

  10. 使用uWSGI+nginx部署Django项目

    最近使用django写了一些项目,不过部署到服务器上碰到一些问题,还有静态文件什么的一堆问题,这里总结一下碰到的问题和解决方案,总体思路是按照官方文档走的. 原文地址:http://uwsgi-doc ...