pro:给定R条街道,现在小孩在某条街上骑车车,最开始他沿着所在街道向东(1,4象限的方向)驶去,如果他遇到街道的交叉口,他会右转。问他转N次后在哪个街道。有特殊情况是他一只遇不到交叉口,会沿着街道一只走下去,这个时候如果不够N,就直接输出当前街道。

sol:(其实算是模拟题,假装是半平面交)。思路很好想,但是要AC还是有坑要de的。

1,先找到起点所在街道,然后定向。

2,每次求离当前点最近的且同向的交点,然后走到所在直线上,且需要定向。

如果形成了一个环,那么N%循环节即可。

坑:有可能有有相互垂直的两个街道,写法不完美的情况下,可能会一直在这个死字路口转圈(WA17)。

解决方案是,每次走一条街的时候,手动向前走一点;或者每次求出一个交点,要排除交点和出发点相同的情况。

#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
const double eps=1e-;
struct point{
double x,y;
point(){}
point(double xx,double yy):x(xx),y(yy){}
};
struct line{
point s,t;
point p;
line(){}
line(point ss,point pp):s(ss),p(pp){}
};
double det(point a,point b){ return a.x*b.y-a.y*b.x; }
double dot(point a,point b){ return a.x*b.x+a.y*b.y; }
point operator *(point a,double x){ return point(a.x*x,a.y*x);}
point operator +(point a,point b){ return point(a.x+b.x,a.y+b.y);}
point operator -(point a,point b){ return point(a.x-b.x,a.y-b.y);}
line road[maxn]; string name[maxn];
ll N;int R,Now; point S; line st;
point llintersect(line a,line b)
{
point w=a.s-b.s;
double t=det(b.p,w)/det(a.p,b.p);
return a.s+a.p*t;
}
bool Online(point p,line L)
{
return fabs(det(p-L.t,p-L.s))<eps;
}
bool parl(point p,point q){
return fabs(det(p,q))<eps;
}
void Change(int i)
{
swap(road[i].s,road[i].t); road[i].p=road[i].t-road[i].s;
}
void find()
{
rep(i,,R){
if(Online(S,road[i])) {
if(dot(point(,),road[i].p)<eps) Change(i);
st=road[i];
Now=i; return ;
}
}
}
int tot,h[maxn],vis[maxn]; point p[maxn];
int main()
{
scanf("%d%lld%lf%lf",&R,&N,&S.x,&S.y);
rep(i,,R) {
cin>>name[i];
scanf("%lf%lf%lf%lf",&road[i].s.x,&road[i].s.y,&road[i].t.x,&road[i].t.y);
road[i].p=road[i].t-road[i].s;
}
if(R==||N==){
cout<<name[]<<endl;
return ;
}
int C=;
find(); h[]=Now; vis[Now]=; p[]=S;
while(){
int t=; point tp;
rep(i,,R){
if(i==Now) continue;
if(parl(st.p,road[i].p)) continue;
point o=llintersect(st,road[i]);
if(dot(o-p[tot],st.p)<=eps) continue;
if(fabs(o.x-p[tot].x)+fabs(o.y-p[tot].y)<=eps) continue;
if(det(st.p,road[i].p)>eps) Change(i);
if(t==||dot(o-p[tot],o-p[tot])<dot(tp-p[tot],tp-p[tot])){
t=i; tp=o;
}
}
if(t==||tot==N){
cout<<name[Now]<<endl;
return ;
}
Now=t; st=road[t]; h[++tot]=t; p[tot]=tp;//+st.p*eps;
if(vis[Now]) { break;} vis[Now]=;
if(tot==N){
cout<<name[Now]<<endl;
return ;
}
}
cout<<name[h[N%tot]]<<endl;
return ;
}

Gym - 101490F:Endless Turning (半平面交)的更多相关文章

  1. POJ 2451 Uyuw's Concert (半平面交)

    题目链接:POJ 2451 Problem Description Prince Remmarguts solved the CHESS puzzle successfully. As an awar ...

  2. 【POJ 3525】Most Distant Point from the Sea(直线平移、半平面交)

    按逆时针顺序给出n个点,求它们组成的多边形的最大内切圆半径. 二分这个半径,将所有直线向多边形中心平移r距离,如果半平面交不存在那么r大了,否则r小了. 平移直线就是对于向量ab,因为是逆时针的,向中 ...

  3. 【BZOJ-2618】凸多边形 计算几何 + 半平面交 + 增量法 + 三角剖分

    2618: [Cqoi2006]凸多边形 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 959  Solved: 489[Submit][Status] ...

  4. 【CSU1812】三角形和矩形 【半平面交】

    检验半平面交的板子. #include <stdio.h> #include <bits/stdc++.h> using namespace std; #define gg p ...

  5. 简单几何(半平面交+二分) LA 3890 Most Distant Point from the Sea

    题目传送门 题意:凸多边形的小岛在海里,问岛上的点到海最远的距离. 分析:训练指南P279,二分答案,然后整个多边形往内部收缩,如果半平面交非空,那么这些点构成半平面,存在满足的点. /******* ...

  6. poj 3335(半平面交)

    链接:http://poj.org/problem?id=3335     //大牛们常说的测模板题 ------------------------------------------------- ...

  7. poj3525Most Distant Point from the Sea(半平面交)

    链接 求凸多边形内一点距离边最远. 做法:二分+半平面交判定. 二分距离,每次让每条边向内推进d,用半平面交判定一下是否有核. 本想自己写一个向内推进..仔细一看发现自己的平面交模板上自带.. #in ...

  8. poj1474Video Surveillance(半平面交)

    链接 半平面交的模板题,判断有没有核.: 注意一下最后的核可能为一条线,面积也是为0的,但却是有的. #include<iostream> #include <stdio.h> ...

  9. 半平面交模板(O(n*n)&& O(n*log(n))

    摘自http://blog.csdn.net/accry/article/details/6070621 首先解决问题:什么是半平面? 顾名思义,半平面就是指平面的一半,我们知道,一条直线可以将平面分 ...

随机推荐

  1. vue中使用cookies和crypto-js实现记住密码和加密

    前端加密 使用crypto-js加解密 第一步,安装 npm install crypto-js 第二步,在你需要的vue组件内import import CryptoJS from "cr ...

  2. CSS布局学习(三) - Normal Flow 正常布局流(官网直译)

    默认情况下,元素是如何布局? 首先,取得元素的内容,加上内边距(padding),边框(border),外边距(margin)放在一个盒子中 - 这就是我们之前看到的盒子模型 默认情况下,块级元素的内 ...

  3. Dubbox:来自当当网的SOA服务框架

    Dubbox:来自当当网的SOA服务框架 http://www.open-open.com/lib/view/open1417426480618.html

  4. LoadRunner遇到的错误及解决方法

    1.返回的报文太长: intweb_set_max_html_param_len(const char * length); intweb_set_max_html_param_len(") ...

  5. frameset,iframe框架之间如何互相调用变量、函数

    以往一直在编写的都是前台的UI,很少使用到frameset.iframe,对其了解也是十分有限,只是知道其可以为其当前页面引入html文件成为当前页的一部分,但是这两天在做后台UI界面的时候,发现这样 ...

  6. Awesome Tools

    Awesome R: https://awesome-r.com/ (Chinese translation: http://www.ppvke.com/Blog/archives/40981) Aw ...

  7. python笔记二

    一 运算符 1算术运算+ - * /  % ** //其中%为取余,**为取幂如2**10=1024    9//4=2 需要注意的是python2.7中如9/2=4 需要正确表示,则在开头添加 fr ...

  8. 微服务-封装-docker by daysn大雄

    目录 序言一.什么是容器二.docker入门 2.1安装启动2.2docker使用 2.2.1 helloworld 2.2.2 容器 2.2.3 镜像 2.2.4 容器的连接     序言 虚拟化一 ...

  9. day062 中间件

    中间件:  作用: 介于request和response之间的一到处理过程,相对比较轻量级,并且在全局上改变django的输入与输出,因为改变的是全局,所以需要谨慎使用,用不好会影响到性能. 当用户发 ...

  10. 安装Ruby、Sass在WebStrom配置Scss编译环境css自动压缩

    安装Sass和Compass sass基于Ruby语言开发而成,因此安装sass前需要安装Ruby.(注:mac下自带Ruby无需在安装Ruby!) window下安装SASS首先需要安装Ruby,先 ...