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. mysql 本机root密码忘记

    1.找到对应的my.conf,在mysqld节点添加:skip-grant-tables  2.重启mysql 即可无密登录 3.update user表中的密码后,去除skip-grant-tabl ...

  2. C#代码模拟http发送get和post请求

    private string HttpPost(string Url, string postDataStr) { HttpWebRequest request = (HttpWebRequest)W ...

  3. Linux C 简易聊天室

    Linux下实现聊天室 介绍:程序在CentOS下,采用C语言实现,结构为Client/Server结构; 服务端程序通过共享存储区存储聊天数据,并发送给每个连接的客户端: 服务端程序和客户端程序都是 ...

  4. 【转】关于UItableViewCell的accessoryType属性

    转载自:http://blog.csdn.net/kmyhy/article/details/6442351 使用的话,例如: cell.accessoryType = UITableViewCell ...

  5. 清除缓存、开启IO统计

    SQL性能优化前期准备-清除缓存.开启IO统计 如果需要进行SQl Server下的SQL性能优化,需要准备以下内容: 一.SQL查询分析器设置: 1.开启实际执行计划跟踪. 2.每次执行需优化SQL ...

  6. TMOUT

    设置TMOUT可以踢用户,直接从shell端. 实际上如果ssh或telnet也可以在其配置里面设定.

  7. Delphi中使用TXMLDocument控件应注意的问题

    今天写了一个类,其中用到了TXMLDocument控件.这个控件我是要动态生成的. 但是却遇到了非常奇怪的问题,下面分享一下 procedure TMainForm.Button1Click(Send ...

  8. 【C++学习笔记】继承与派生基础概念

    面向对象的程序设计主要有四个特点:抽象.封装.继承和多态.其中继承是我认为最最重要的一个特性,可以说继承是面向对象的精华所在. 举一个继承的浅显易懂的例子:假如我们已经有了一个“马”的类,其中成员变量 ...

  9. apache添加fastcgi支持

    A,安装apache服务器和fastcgi模块支持(ubuntu测试) sudo apt-get install apache2 sudo apt-get install libapache2-mod ...

  10. UVA 12230 - Crossing Rivers(概率)

    UVA 12230 - Crossing Rivers 题目链接 题意:给定几条河,每条河上有来回开的船,某一天出门,船位置随机,如今要求从A到B,所须要的期望时间 思路:每条河的期望,最坏就是船刚开 ...