FZU2235 国王的出游 水题
因为只有1e5个点,所以直接离散化bfs就好
- #include <cstdio>
- #include <cstring>
- #include <queue>
- #include <set>
- #include <map>
- #include <stack>
- #include <cstdlib>
- #include <algorithm>
- #include <vector>
- #include <cmath>
- using namespace std;
- typedef long long LL;
- typedef pair<int,int>pii;
- const int N=1e5+;
- const int INF=0x3f3f3f3f;
- const int mod=;
- pii p[N],tmp;
- int dx[]={-,-,-,,,,,};
- int dy[]={-,,,-,,-,,};
- int head[N],tot,d[N],cnt;
- struct Edge{
- int v,next;
- }edge[*N];
- void add(int u,int v){
- edge[tot].v=v;
- edge[tot].next=head[u];
- head[u]=tot++;
- }
- queue<int>q;
- int get(int s,int t){
- while(!q.empty())q.pop();
- memset(d,-,sizeof(d));
- d[s]=;q.push(s);
- while(!q.empty()){
- int u=q.front();
- q.pop();
- if(u==t)return d[t];
- for(int i=head[u];~i;i=edge[i].next){
- int v=edge[i].v;
- if(d[v]==-)d[v]=d[u]+,q.push(v);
- }
- }
- return -;
- }
- int main(){
- int x1,x2,y1,y2,n,s,t;
- while(~scanf("%d%d%d%d",&x1,&y1,&x2,&y2)){
- scanf("%d",&n);
- memset(head,-,sizeof(head)),cnt=tot=;
- for(int i=;i<=n;++i){
- int x,l,r;
- scanf("%d%d%d",&x,&l,&r);
- for(int j=l;j<=r;++j)
- ++cnt,p[cnt].first=x,p[cnt].second=j;
- }
- sort(p+,p++cnt);
- cnt=unique(p+,p++cnt)-p-;
- for(int i=;i<=cnt;++i){
- for(int j=;j<;++j){
- tmp.first=p[i].first+dx[j];
- tmp.second=p[i].second+dy[j];
- int pos=lower_bound(p+,p++cnt,tmp)-p;
- if(pos==cnt+||p[pos].first!=tmp.first||p[pos].second!=tmp.second)
- continue;
- add(i,pos);
- }
- }
- tmp.first=x1,tmp.second=y1;
- s=lower_bound(p+,p++cnt,tmp)-p;
- tmp.first=x2,tmp.second=y2;
- t=lower_bound(p+,p++cnt,tmp)-p;
- printf("%d\n",get(s,t));
- }
- return ;
- }
FZU2235 国王的出游 水题的更多相关文章
- 【BZOJ】3850: ZCC Loves Codefires(300T就这样献给了水题TAT)
http://www.lydsy.com/JudgeOnline/problem.php?id=3850 题意:类似国王游戏....无意义.. #include <cstdio> #inc ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- ACM :漫漫上学路 -DP -水题
CSU 1772 漫漫上学路 Time Limit: 1000MS Memory Limit: 131072KB 64bit IO Format: %lld & %llu Submit ...
- ytu 1050:写一个函数,使给定的一个二维数组(3×3)转置,即行列互换(水题)
1050: 写一个函数,使给定的一个二维数组(3×3)转置,即行列互换 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 154 Solved: 112[ ...
- [poj2247] Humble Numbers (DP水题)
DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...
- gdutcode 1195: 相信我这是水题 GDUT中有个风云人物pigofzhou,是冰点奇迹队的主代码手,
1195: 相信我这是水题 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 821 Solved: 219 Description GDUT中有个风云人 ...
- BZOJ 1303 CQOI2009 中位数图 水题
1303: [CQOI2009]中位数图 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2340 Solved: 1464[Submit][Statu ...
- 第十一届“蓝狐网络杯”湖南省大学生计算机程序设计竞赛 B - 大还是小? 字符串水题
B - 大还是小? Time Limit:5000MS Memory Limit:65535KB 64bit IO Format: Description 输入两个实数,判断第一个数大 ...
- ACM水题
ACM小白...非常费劲儿的学习中,我觉得目前我能做出来的都可以划分在水题的范围中...不断做,不断总结,随时更新 POJ: 1004 Financial Management 求平均值 杭电OJ: ...
随机推荐
- xml simpleXML_load_file(), simpleXML_load_string()
xml.xml文件 <?xml version='1.0'?><man> <att> <name>lin3615</name& ...
- Aspose.Words 总结
生成答题卡 try { string tempPath = @"D:\moban\ttt.doc"; //Open document and create Documentbuil ...
- 【转】C# Excel 导入到 Access数据库表(winForm版)
/// <summary> /// 获取Excel文件 /// </summary> /// <param name="sender">< ...
- WPF中添加Ribbon遇到的问题
很奇怪的说,当我新建WPF工程,添加RibbonControlsLibary.dll后会运行时会报错,System.Windows.Markup.XamlParseException.引发的异常信息为 ...
- JSON对象的stringify()和parse()方法
1.stringify() ---- JavaScript对象序列化为JSON字符串 eg1. var book = {title: 'JS', authors: ['Van'], edition:3 ...
- Html盒子模型学习总结
Html的盒子模型 1.总的来说Html元素可以分为两类:即块状元素和行内元素. 2.块状元素(Block)类型的元素可以设置Width和Height值属性,而行内(Inline)类型无效. 3.浏览 ...
- HTTP协议(4)
HTTP 概括总结 方便以后使用.遗忘时有侧重点的去学习,方便查阅: 开始看到webservice 和restful 有些不理解 现在可以简单理解为 : webservice = http协议+XM ...
- uCOS-II任务的挂起和恢复
函数描述 OSTaskSuspend() 功能描述:无条件挂起一个任务.调用此函数的任务也可以传递参数OS_PRIO_SELF,挂起调用任务本身.函数原型:INT8U OSTaskSuspend ( ...
- sencha touch json store
js: Ext.define('MyApp.store.MyJsonStore', { extend: 'Ext.data.Store', requires: [ 'MyApp.model.Perso ...
- Java编程思想(2)之一切皆对象