USACO The Tamworth Two 模拟
一道模拟题不过要担心的是牛或者人在转弯的时候,另一方如果能走,那么要走,不能停留。
还是蛮简单的。
调试输出的话可以看到具体追击过程
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 模拟的更多相关文章
- USACO2.4 The Tamworth Two[模拟]
题目描述 两只牛逃跑到了森林里.农夫John开始用他的专家技术追捕这两头牛.你的任务是模拟他们的行为(牛和John). 追击在10x10的平面网格内进行.一个格子可以是: 一个障碍物, 两头牛(它们总 ...
- 【USACO】Transformations(模拟)
Transformations A square pattern of size N x N (1 <= N <= 10) black and white square tiles is ...
- USACO 1.2 Transformations (模拟)
模拟题目,依照题目给定的要求变换图形就可以,变换的优先级依次减小. 这个题目我写的非常乱.只是最还还是勉强能够执行 /* ID:twd30651 PROG:transform LANG:C++ */ ...
- 【题解】Acting Cute
题目简介 正在 rainbow 的城堡游玩的 Freda 恰好看见了在地毯上跳舞卖萌的水叮当--于是-- Freda:"呜咕>_< 我也要卖萌T_T!" rainbow ...
- USACO 1.3... 虫洞 解题报告(搜索+强大剪枝+模拟)
这题可真是又让我找到了八数码的感觉...哈哈. 首先,第一次见题,没有思路,第二次看题,感觉是搜索,就这样写下来了. 这题我几乎是一个点一个点改对的(至于为什么是这样,后面给你看一个神奇的东西),让我 ...
- Your Ride Is Here 你的飞碟在这儿 USACO 模拟
1001: 1.1.1 Your Ride Is Here 你的飞碟在这儿 时间限制: 1 Sec 内存限制: 128 MB提交: 9 解决: 9[提交] [状态] [讨论版] [命题人:外部导入 ...
- USACO Runaround Numbers 模拟
根据题意的 Runaround 规则去找比当前数大的最近的一个 Runaround数字 模拟题~ Source code: /* ID: wushuai2 PROG: runround LANG: C ...
- Transformations 方块转换 USACO 模拟 数组 数学 耐心
1006: 1.2.2 Transformations 方块转换 时间限制: 1 Sec 内存限制: 128 MB提交: 10 解决: 7[提交] [状态] [讨论版] [命题人:外部导入] 题目 ...
- Milking Cows 挤牛奶 USACO 排序 模拟
1005: 1.2.1 Milking Cows 挤牛奶 时间限制: 1 Sec 内存限制: 128 MB提交: 15 解决: 9[提交] [状态] [讨论版] [命题人:外部导入] 题目描述 1 ...
随机推荐
- HTML+CSS笔记 CSS进阶续集
元素分类 在CSS中,html中的标签元素大体被分为三种不同的类型:块状元素.内联元素(又叫行内元素)和内联块状元素. 常用的块状元素有: <div>.<p>.<h1&g ...
- MVC-04 视图(1)
不可否认的,View应该是整个ASP.NET MVC项目开发过程中最花时间的部分,因为与显示逻辑相关的技术五花八门,你可能要学习的有HTML.CSS.JavaScript.DOM.JQuery.JSO ...
- HDU 2147 kiki's game
题解:画图可得当横纵坐标均为奇数时为必败态…… #include <cstdio> int main(){ int a,b; while(scanf("%d%d",&a ...
- FIB数列
斐波那契级数除以N会出现循环,此周期称为皮萨诺周期. 下面给出证明 必然会出现循环 这是基于下面事实: 1. R(n+2)=F(n+2) mod P=(F(n+1)+F(n)) mod P=(F(n+ ...
- HDU 3746 Cyclic Nacklace KMP
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3746 KMP算法—— AC代码: #include <iostream> #include ...
- 利用jxl读取excel合并的单元格的一个小样例
工作中我们可能要把Excel文件的记录保存到数据库, 今天我用jxl读取Excel文件时遇到了合并格的问题,记录例如以下: 如Excel文件例如以下: watermark/2/text/aHR0cDo ...
- 远程登录 Windows server 2008 黑屏
scenerio: 远程登录 Windows server 2008 黑屏,别人那里一切正常. Solution:在黑屏界面,点击桌面,按住Ctrl+Alt+End键 -> Log Off. ...
- 【node.js】本地模式安装express:'express' 不是内部或外部命令,也不是可运行的程序或批处理文件。
今天闲来无事想起了node.js,因此到网上下载了一个node.js的安装程序进行安装.其中: 安装程序:node-v0.11.13-x64.msi PC系统:Windows 7 自定义安装路径:D: ...
- Arduino101 中使用 Mirf 库的问题(2016-04-04)
Mirf 库在使用 NRF24L01 的时候接触到,感觉很好用.但在用 Arduino101 的时候遇到一些问题,记录一下,对于底层不了解,希望有熟悉的同学能给点指点: 编译会提示 MirfHardw ...
- [LeetCode]题解(python):062-Unique Paths
题目来源: https://leetcode.com/problems/unique-paths/ 题意分析: 给定两个整型m,n.判断从一个m×n的矩阵里面,从(0,0)走到(m-1,n-1)一共有 ...