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的更多相关文章

  1. USACO Feb. 2012

    Moo 找规律 吧 第一个是很久以前自己写的递归 #include<stdio.h> __int64 n; __int64 dfs(__int64 l,__int64 r,__int64 ...

  2. [文章泛读] 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 ...

  3. centos各版本信息

    CentOS version Architectures RHEL base Kernel CentOS release date RHEL release date Delay (days) 2.1 ...

  4. HTML5+CSS3学习笔记(二) 页面布局:HTML5新元素及其特性

    HTML5的语义化标签以及属性,可以让开发者非常方便地实现清晰的web页面布局,加上CSS3的效果渲染,快速建立丰富灵活的web页面显得非常简单. 本次学习HTML5的新标签元素有: <head ...

  5. MPLS

    Multiprotocol Label Switching From Wikipedia, the free encyclopedia "MPLS" redirects here. ...

  6. IMS Global Learning Tools Interoperability™ Implementation Guide

    Final Version 1.1 Date Issued:            13 March 2012 Latest version:         http://www.imsglobal ...

  7. Linux网络统计工具/命令

    我在Linux(基于CentOS 或者 Debian 的发行版)中该如何查看当前网络端口吞吐量的统计信息?在Linux操作系统中如何查看当前内核snmp计数器以及网络端口的统计信息? 你可以使用以下任 ...

  8. (转)The Road to TensorFlow

    Stephen Smith's Blog All things Sage 300… The Road to TensorFlow – Part 7: Finally Some Code leave a ...

  9. MDX : Non Empty v/s NonEmpty

    MDX : Non Empty v/s NonEmpty User Rating: / 50 PoorBest Written by Jason Thomas    Friday, 07 May 20 ...

随机推荐

  1. sqlserver 在将 nvarchar 值 'XXX' 转换成数据类型 int 时失败

    最近做oracle和sqlserver数据库兼容,感觉sqlserver真心没oracle好用,存储过程竟然只能返回int类型,疯了 疯了 存储过程的output及return的区别 sql取整 ce ...

  2. 我的Python成长之路---第一天---Python基础(4)---2015年12月26日(雾霾)

    五.数据运算与数据运算符 1.算术运算符 算术运算符 运算符 描述 示例 + 加法 >>> 14 - 5 9 - 减法 >>> 14 - 5 9  *  乘法 &g ...

  3. app 转caf 音频 代码

    afconvert /Users/xiaoye/Downloads/cat.caf     /Users/xiaoye/Downloads/cat1.caf  -d ima4 -f caff -v;

  4. 常见排序算法C++总结

    看了总结图,我这里就总结一下 直接插入排序,冒泡排序,快速排序,堆排序和归并排序,使用C++实现 重新画了总结图 直接插入排序 整个序列分为有序区和无序区,取第一个元素作为初始有序区,然后第二个开始, ...

  5. ThreadSafeClientConnManager用来支持多线程的使用http client

    import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.clien ...

  6. angulajs 当input使用 bootstrap的email类型时,如果是无效的email格式,则ng-model无效的情况

    当使用bootstrap的如下input时 <input type="email" ng-model="userid"> 如果输入的内容是无效的em ...

  7. 使用Docker构建持续集成与自动部署的Docker集群

    为什么使用Docker " 从我个人使用的角度讲的话  部署来的更方便 只要构建过一次环境 推送到镜像仓库 迁移起来也是分分钟的事情 虚拟化让集群的管理和控制部署都更方便 hub.docke ...

  8. poj 2001 Shortest Prefixes(字典树)

    题目链接:http://poj.org/problem?id=2001 思路分析: 在Trie结点中添加数据域childNum,表示以该字符串为前缀的字符数目: 在创建结点时,路径上的所有除叶子节点以 ...

  9. CALayer3-层的属性

    一.隐式动画属性 * 在前面几讲中已经提到.每个UIView内部都默认关联着一个CALayer,我们可用称这个Layer为Root Layer(根层). 全部的非Root Layer.也就是手动创建的 ...

  10. Android ScrollView嵌套HorizontalScrollView 滑动问题 ScrollView包括GridView显示问题

    今天项目使用到ScrollView嵌套HorizontalScrollView,ScrollView里包括GridView,发现几个问题非常经典.在此记录: 问题1.ScrollView嵌套Horiz ...