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 ...
随机推荐
- PowerShell Remove all user defined variable in PowerShell
When PS scripts executes, it is possibly create much user defined variables. So, sometimes these var ...
- Bootstrap 响应式瀑布流 (使用wookmark)
使用瀑布布局 官方 http://www.wookmark.com/jquery-plugin GitHub https://github.com/GBKS/Wookmark-jQuery (下载后 ...
- contains 和 ele.compareDocumentPosition确定html节点间的关系
~~~ nodeA.contains(nodeB) //ie , nodeA.compareDocumentPosition(nodeB) //firefox opera 1.DOMElement ...
- perl5 第三章 操作符
第三章 操作符 by flamephoenix 一.算术操作符二.整数比较操作符三.字符串比较操作符四.逻辑操作符五.位操作符六.赋值操作符七.自增自减操作符八.字符串联结和重复操作符九.逗号操作符十 ...
- HDU 3015 Disharmony Trees
题解:在路边有一行树,给出它们的坐标和高度,先按X坐标排序.记录排名,记为rankx,再按它们的高度排序,记录排名,记为rankh.两颗树i,j的差异度为 fabs(rankx[i]-rankx[j] ...
- Oracle 日期计算
日期相减,求天数 方法一: )),createdate from goods t
- Spring MVC遭遇checkbox的问题解决方式
Spring MVC遭遇checkbox的问题是:当checkbox全不选时候,则该checkbox域的变量为null,不能动态绑定到spring的controller方法的入參上,并抛出异常. 解决 ...
- 设计模式 - 适配器模式(adapter pattern) 具体解释
适配器模式(adapter pattern) 详细解释 本文地址: http://blog.csdn.net/caroline_wendy 适配器模式(adapter pattern): 将一个类的接 ...
- linux之grep用法
运用场景:在当前目录下查找,比如代码目录,不需要在.svn目录下,以及ctags生成的tags文件中查找: grep的--exclude-dir=参数就是为了排除某个目录的,即不包含等号后面的目录: ...
- Oracle语句优化规则(一)
1. 选用适合的ORACLE优化器 ORACLE的优化器共有3种: a. RULE (基于规则) b. COST (基于成本) c. CHOOSE (选择性) 设置缺省的优化 ...