SCU 4445 Right turn
模拟。
每次找一下即将要遇到的那个点,这个数据范围可以暴力找,自己的写的时候二分了一下。如果步数大于$4*n$一定是$-1$。
#include<bits/stdc++.h>
using namespace std; const int INF = 0x7FFFFFFF;
const int mod = 1e9 + ;
const int N = 5e6 + ;
const int M = 1e4 + ;
const double eps = 1e-;
int T,n,m; struct P
{
int x,y;
P(int X=,int Y=)
{
x=X;
y=Y;
}
}p[],q[]; bool cmp1(P a,P b)
{
if(a.x!=b.x) return a.x<b.x;
return a.y<b.y;
} bool cmp2(P a,P b)
{
if(a.y!=b.y) return a.y<b.y;
return a.x<b.x;
} int nowx,nowy,nowd; int main()
{
while(~scanf("%d",&n))
{
for(int i=;i<=n;i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
q[i].x=p[i].x;
q[i].y=p[i].y;
} sort(p+,p++n,cmp1);
sort(q+,q++n,cmp2); nowx=nowy=; nowd=; int ans=; while()
{
if(nowd==)
{
int k = lower_bound(q+,q+n+,P(nowx,nowy),cmp2)-q;
if(k==n+||q[k].y!=nowy)
{
printf("%d\n",ans);
break;
}
else ans++,nowx = q[k].x-,nowd=(nowd+)%;
}
else if(nowd==)
{
int k = lower_bound(q+,q+n+,P(nowx,nowy),cmp2)-q-;
if(k==||q[k].y!=nowy)
{
printf("%d\n",ans);
break;
}
else ans++,nowx = q[k].x+,nowd=(nowd+)%;
} else if(nowd==)
{
int k = lower_bound(p+,p+n+,P(nowx,nowy),cmp1)-p-;
if(k==||p[k].x!=nowx)
{
printf("%d\n",ans);
break;
}
else ans++,nowy = p[k].y+,nowd=(nowd+)%;
} else
{
int k = lower_bound(p+,p+n+,P(nowx,nowy),cmp1)-p;
if(k==n+||p[k].x!=nowx)
{
printf("%d\n",ans);
break;
}
else ans++,nowy = p[k].y-,nowd=(nowd+)%;
} if(ans>*n)
{
printf("-1\n");
break;
}
}
}
return ;
}
SCU 4445 Right turn的更多相关文章
- 模拟+贪心 SCU 4445 Right turn
题目传送门 /* 题意:从原点出发,四个方向,碰到一个点向右转,问多少次才能走出,若不能输出-1 模拟:碰到的点横坐标相等或纵坐标相等,然而要先满足碰到点最近, 当没有转向或走到之前走过的点结束循环. ...
- SCU 4445 Right turn(dfs)题解
思路:离散化之后,直接模拟就行,标记vis开三维 代码: #include<iostream> #include<algorithm> #include<cstdio&g ...
- SCU Right turn
Right turn frog is trapped in a maze. The maze is infinitely large and divided into grids. It also c ...
- Lesson 11 One good turn deserves another
Text I was having dinner at a restaurant when Tony Steele came in. Tony worked in a layer's office y ...
- ACM:SCU 4437 Carries - 水题
SCU 4437 Carries Time Limit:0MS Memory Limit:0KB 64bit IO Format:%lld & %llu Practice ...
- ACM: SCU 4438 Censor - KMP
SCU 4438 Censor Time Limit:0MS Memory Limit:0KB 64bit IO Format:%lld & %llu Practice D ...
- ACM: SCU 4440 Rectangle - 暴力
SCU 4440 Rectangle Time Limit:0MS Memory Limit:0KB 64bit IO Format:%lld & %llu Practic ...
- webrtc进阶-信令篇-之三:信令、stun、turn、ice
webRTC支持点对点通讯,但是webRTC仍然需要服务端: . 协调通讯过程中客户端之间需要交换元数据, 如一个客户端找到另一个客户端以及通知另一个客户端开始通讯. . 需要处理NAT(网 ...
- HDU-4869 Turn the pokers
原题: Turn the pokers 思路:假设正面为0,反面为1.牌就像这样 000000....... .考虑到假如可以实现最终反面个数为m, 牌共n张, 则这n张排任取m个为反面 ...
随机推荐
- Ajax-更新
ajax是与服务器进行(异步/同步)交互的技术之一交互就是对服务器一种访问ajax对服务器进行交互时页面不刷新ajax的语言载体是JS 比如我在百度输入个东西 自动弹出信息像和一些搜索字体相关的页面标 ...
- 还不会做! 树上的gcd 树分治 UOJ33
题目链接:http://uoj.ac/problem/33 题解链接:http://vfleaking.blog.uoj.ac/blog/38 现在感觉到了做OI的层层递进的思路的伟大之处,作为一个大 ...
- UIDynamicBehavior的行为类翻译
CHENYILONG Blog UIDynamicBehavior的行为类翻译 © chenyilong. Powered by Postach.io Blog
- Please move or remove them before you can merge
在使用git pull时,经常会遇到报错: Please move or remove them before you can merge 这是因为本地有修改,与云端别人提交的修改冲突,又没有merg ...
- AngularJs几种服务区别
下面说说这几种函数之间的区别: 函数 定义 适合场景 provider(name, Object OR constructor() ) 一个可配置的.有复杂逻辑的服务.如果你传递了一个对象,那么它应该 ...
- css3全屏背景显示
background:url(zhongyi2.png) no-repeat center center fixed;/* -webkit-background-size:cover; -moz-ba ...
- 福建工程学院寒假作业第三周B题
第二集 你说,你的女朋友就是你的电脑 TimeLimit:2000ms MemoryLimit:128000KB 64-bit integer IO format:%lld Problem De ...
- MAC泛洪攻击
先来解释一下啥是泛洪攻击 交换机里有一张专门记录MAC地址的表,为了完成数据的快速转发,该表具有自动学习机制:泛洪攻击即是攻击者利用这种学习机制不断发送不同的MAC地址给交换机,充满整个MAC表,此时 ...
- awk正则匹配nginx日志【原创】
查看网页访问代码不为200和30x所有行的内容 awk '{if($9!~/200|30*/) print $0}' /app/logs/http_access.log 或 awk '$9!~/200 ...
- python常用运维脚本实例【转】
file是一个类,使用file('file_name', 'r+')这种方式打开文件,返回一个file对象,以写模式打开文件不存在则会被创建.但是更推荐使用内置函数open()来打开一个文件 . 首先 ...