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. Always clear download 下载 谷歌浏览器插件

    由于该博文不支持上传压缩包,因此,如有需要always clear download插件的可点击此链接在百度网盘上下载https://pan.baidu.com/s/13wWchis3iKqXkIA5 ...

  2. freeswitch 显示主叫名称和主叫号码

    1.指定主叫号码 origination_caller_id_number 参数来指定显示的主叫号码 2.指定主叫名称 origination_caller_id_name 参数来指定显示的主叫名称 ...

  3. Java基础学习-HelloWorld案例常见问题

    注意:控制台曾经写过的命令,我们可以通过上下箭头进行选择,不需要重新进行输入,以节省时间,提高效率.   1.单词拼写问题     -class    不要写成Class     -String    ...

  4. MVC扩展HttpHandler

    扩展用来做防盗链    访问特殊后缀名的处理方式 localhost:8080/Home/index.aspx      localhost:8080/Home/mao.jpg 比如 这样一个地址  ...

  5. Android 开发版本统一

    一.概述 对于 Android 开发版本的统一涉及到的东西就是 Gradle 中的全局设置,我们通过配置 gradle 也就是编写 Groovy 代码将开发中的版本号设置为全局参数.这样就能够在 mo ...

  6. R 语言 decostand() 函数

    参考自:https://wenku.baidu.com/view/ae5f76f94b35eefdc9d3336e.html

  7. ST MCU_GPIO的八种工作模式详解。

    补充: N.P型的区别,就是一个为正电压启动(NMOS),一个为负电压启动(PMOS) GPIO的八种工作模式详解 浮空输入_IN_FLOATING带上拉输入_IPU带下拉输入_IPD模拟输入_AIN ...

  8. SAM文件格式

    帮朋友处理sam各式文件,又记不住sam各式每列代表的什么内容,干脆转个帖子留着以后查询. 在SAM输出的结果中每一行都包括十二项通过Tab分隔,从左到右分别是: 1 序列的名字 2 概括出一个合适的 ...

  9. Practical Node.js (2018版) 第10章:Getting Node.js Apps Production Ready

    Getting Node.js Apps Production Ready 部署程序需要知道的方面: Environment variables Express.js in production So ...

  10. HBuild 连接苹果手机

    PC.苹果手机.数据线 1.在电脑端安装iTunes,安装完成之后提示重启. 2.用数据线连接苹果手机 PC 3.打开HBuild      菜单栏   -->  运行   -->  真机 ...