USACO March. 2012
Connect the Cows
Times17
水题
Landscaping
Flowerpot
Tractor
广搜 搜到边界就可以终止了 没什么难度
#include <stdio.h>
#include <string.h>
#include <queue>
using namespace std;
const int MAX = 1010;
int a[MAX][MAX];
int dir[4][2] = {0,1,0,-1,1,0,-1,0};
struct node
{
int x;
int y;
int step;
bool friend operator < (node a,node b)
{
return a.step > b.step;
}
}s; void bfs()
{
int i;
s.step = 0;
priority_queue <node> q;
q.push(s);
while(!q.empty())
{
node p = q.top();
q.pop();
if(p.x == 0 || p.y == 0 || p.x == 1001 || p.y == 1001)
{
printf("%d\n",p.step);
return;
}
for(i = 0;i < 4; i++)
{
node t;
t.x = p.x + dir[i][0];
t.y = p.y + dir[i][1];
t.step = p.step;
if(a[t.x][t.y] == -1)
continue;
if(a[t.x][t.y])
t.step++;
a[t.x][t.y] = -1;
q.push(t);
} }
}
int main()
{
int n,x,y;
scanf("%d %d %d",&n,&s.x,&s.y);
while(n--)
{
scanf("%d %d",&x,&y);
a[x][y] = 1;
}
bfs();
return 0;
}
Haybale Restacking
USACO March. 2012的更多相关文章
- USACO Feb. 2012
Moo 找规律 吧 第一个是很久以前自己写的递归 #include<stdio.h> __int64 n; __int64 dfs(__int64 l,__int64 r,__int64 ...
- [文章泛读] The varying faces of a program transformation systems (ACM Inroads, 2012)
Beevi S. Nadera, D. Chitraprasad, and Vinod S. S. Chandra. 2012. The varying faces of a program tran ...
- centos各版本信息
CentOS version Architectures RHEL base Kernel CentOS release date RHEL release date Delay (days) 2.1 ...
- HTML5+CSS3学习笔记(二) 页面布局:HTML5新元素及其特性
HTML5的语义化标签以及属性,可以让开发者非常方便地实现清晰的web页面布局,加上CSS3的效果渲染,快速建立丰富灵活的web页面显得非常简单. 本次学习HTML5的新标签元素有: <head ...
- MPLS
Multiprotocol Label Switching From Wikipedia, the free encyclopedia "MPLS" redirects here. ...
- IMS Global Learning Tools Interoperability™ Implementation Guide
Final Version 1.1 Date Issued: 13 March 2012 Latest version: http://www.imsglobal ...
- Linux网络统计工具/命令
我在Linux(基于CentOS 或者 Debian 的发行版)中该如何查看当前网络端口吞吐量的统计信息?在Linux操作系统中如何查看当前内核snmp计数器以及网络端口的统计信息? 你可以使用以下任 ...
- (转)The Road to TensorFlow
Stephen Smith's Blog All things Sage 300… The Road to TensorFlow – Part 7: Finally Some Code leave a ...
- MDX : Non Empty v/s NonEmpty
MDX : Non Empty v/s NonEmpty User Rating: / 50 PoorBest Written by Jason Thomas Friday, 07 May 20 ...
随机推荐
- HDU2007-平方和与立方和
描述: 给定一段连续的整数,求出他们中所有偶数的平方和以及所有奇数的立方和. 代码: #include<stdio.h> #include<string.h> #include ...
- 加装 ImageMagick 性能更佳!
1. 下载 Download ImageMagick 以此文件ImageMagick-6.9.1-10-Q16-x64-dll-win进行,第二次开发的研发 2. 安装 Install ImageMa ...
- Python 爬取CSDN博客频道
初次接触python,写的很简单,开发工具PyCharm,python 3.4很方便 python 部分模块安装时需要其他的附属模块之类的,可以先 pip install wheel 然后可以直接下载 ...
- iter, yield与enumerate的实现
模拟实现一个enumerate函数 def myEnumerate(seq, start=0): results = [] n = start for i in seq: results.append ...
- selenium 学习笔记 ---新手学习记录(3) 问题总结(java)
1.验证码简单处理 /** * 验证码等待输入函数 * */ private void ZcYzm(WebDriver driver){ boolean flag=false; while(flag= ...
- 高质量程序设计指南C/C++语言——内存管理
• free()和delete只是把指针所指的内容给释放掉,并没有把指针本身删掉.指针被free()或delete以后其地址仍然不变(不等于NULL),只是该地址对应的内存是垃圾——p成了野指针.如果 ...
- javascript的isPrototypeOf函数的理解
JavaScript中isPrototypeOf函数方法是返回一个布尔值,指出对象是否存在于另一个对象的原型链中.使用方法: object1.isPrototypeOf(object2)~~~原型链理 ...
- poj 2503 Babelfish(Map、Hash、字典树)
题目链接:http://poj.org/bbs?problem_id=2503 思路分析: 题目数据数据量为10^5, 为查找问题,使用Hash或Map等查找树可以解决,也可以使用字典树查找. 代码( ...
- 使用js对select动态添加和删除OPTION示例代码
动态删除select中的所有options.某一项option以及动态添加select中的项option,在IE和FireFox都能测试成功,感兴趣的朋友可以参考下,希望对大家有所帮助 <s ...
- struts之拦截器
拦截器是为了让一些自己不希望发生的事情进行预防.以下我说一下struts自己定义拦截器. 以下我贴下struts.xml里的自定义的拦截器: <package name="my&quo ...