题的意思是有r个街道,有一个小女孩刚开始在X,Y 上, 下面r行,给出街道名称,以及每个街道的两个点,由两个点我们可以确定一条直线,也就是这条街道,小女孩最初在一条街道上,如果遇到两个街道的交界处就向右转,问小女孩转n次后,在哪条街道上。
做法:小女孩最后一定是被围在一圈里面,那么我把小女孩看做中间的一个点,那么由半平面交判定小女孩在线的右边,那么可以先围成一个图,再找到小女孩对应最初的那根线上,也就是这个点离当前平面交最近的这根线,当然有可能最后整个图并不能围成封闭的图形,那么会到哪根线呢,一定小女孩会到不能再右转的那根线上为止就停止了移动。
或者就是围成封闭图形,那么找最初的那个点,然后循环之后,也就是n%tot就得出答案了。很多细节操作全在代码里了。
//china no.1
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <vector>
#include <iostream>
#include <string>
#include <map>
#include <stack>
#include <cstring>
#include <queue>
#include <list>
#include <stdio.h>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <cctype>
#include <sstream>
#include <functional>
#include <stdlib.h>
#include <time.h>
#include <bitset>
using namespace std;
#define pi acos(-1)
#define s_1(x) scanf("%d",&x)
#define s_2(x,y) scanf("%d%d",&x,&y)
#define s_3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define s_4(x,y,z,X) scanf("%d%d%d%d",&x,&y,&z,&X)
#define S_1(x) scan_d(x)
#define S_2(x,y) scan_d(x),scan_d(y)
#define S_3(x,y,z) scan_d(x),scan_d(y),scan_d(z)
#define PI acos(-1)
#define endl '\n'
#define srand() srand(time(0));
#define me(x,y) memset(x,y,sizeof(x));
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define close() ios::sync_with_stdio(0); cin.tie(0);
#define FOR(x,n,i) for(int i=x;i<=n;i++)
#define FOr(x,n,i) for(int i=x;i<n;i++)
#define fOR(n,x,i) for(int i=n;i>=x;i--)
#define fOr(n,x,i) for(int i=n;i>x;i--)
#define W while
#define sgn(x) ((x) < 0 ? -1 : (x) > 0)
#define bug printf("***********\n");
#define db double
#define ll long long
#define mp make_pair
#define pb push_back
typedef long long LL;
typedef pair <int, int> ii;
const int INF=0x3f3f3f3f;
const LL LINF=0x3f3f3f3f3f3f3f3fLL;
const int dx[]={-1,0,1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,-1,1,-1,1};
const int maxn=105;
const int maxx=4e5+10;
const double EPS=1e-8;
const double eps=1e-8;
const int mod=1e9+7;
template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}
template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}
template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}
template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}
template <class T>
inline bool scan_d(T &ret){char c;int sgn;if (c = getchar(), c == EOF){return 0;}
while (c != '-' && (c < '0' || c > '9')){c = getchar();}sgn = (c == '-') ? -1 : 1;ret = (c == '-') ? 0 : (c - '0');
while (c = getchar(), c >= '0' && c <= '9'){ret = ret * 10 + (c - '0');}ret *= sgn;return 1;}
inline bool scan_lf(double &num){char in;double Dec=0.1;bool IsN=false,IsD=false;in=getchar();if(in==EOF) return false;
while(in!='-'&&in!='.'&&(in<'0'||in>'9'))in=getchar();if(in=='-'){IsN=true;num=0;}else if(in=='.'){IsD=true;num=0;}
else num=in-'0';if(!IsD){while(in=getchar(),in>='0'&&in<='9'){num*=10;num+=in-'0';}}
if(in!='.'){if(IsN) num=-num;return true;}else{while(in=getchar(),in>='0'&&in<='9'){num+=Dec*(in-'0');Dec*=0.1;}}
if(IsN) num=-num;return true;}
void Out(LL a){if(a < 0) { putchar('-'); a = -a; }if(a >= 10) Out(a / 10);putchar(a % 10 + '0');}
void print(LL a){ Out(a),puts("");}
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );
//cerr << "run time is " << clock() << endl;
int dcmp(double x)
{
if(fabs(x) < EPS) return 0;
else return x < 0 ? -1 : 1;
}
struct Point
{
double x, y;
Point(const Point& rhs): x(rhs.x), y(rhs.y) { } //拷贝构造函数
Point(double x = 0, double y = 0) : x(x), y(y) { }
inline void input()
{
scanf("%lf%lf",&x,&y);
}
inline void print()
{
printf("%.6lf %.6lf\n",x,y);
}
bool operator < (const Point& e) const
{
return dcmp(x - e.x) < 0 || (dcmp(x - e.x) == 0 && dcmp(y - e.y) < 0);
}
bool operator == (const Point& e) const
{
return dcmp(x - e.x) == 0 && dcmp(y - e.y) == 0;
}
Point operator + (Point q){ return Point(x+q.x,y+q.y);}
Point operator - (Point q){ return Point(x-q.x,y-q.y);}
Point operator * (double q){ return Point(x*q,y*q);}
Point operator / (double q){ return Point(x/q,y/q);}
Point &operator +=(Point q){ x+=q.x;y+=q.y; return *this;}
Point &operator -=(Point q){ x-=q.x;y-=q.y; return *this;}
double operator *(const Point& q) const{
return x*q.x+y*q.y;
}
double operator ^(const Point& q) const{
return x*q.y-y*q.x;
}
double len()
{
return sqrt(x*x+y*y);
}
void read()
{
int xx,yy;
scanf("%d%d",&xx,&yy);
x=xx,y=yy;
}
};
typedef Point Vector;
int r;
LL n;
int route[maxn];
bool vis[maxn];
string s[maxn];
Point A[maxn],B[maxn];
Vector ip;
bool on(Point a,Point b,Point p)
{
return fabs((a-b)^(p-b))<eps;
}
Vector getLineCircleIntersecion(int x,int y)//两直线相交的点
{
Vector p1 = A[x], p2 = B[x], q1 = A[y], q2 = B[y];
return p1+(p2-p1)*(((q2-q1)^(q1-p1))/((q2-q1)^(p2-p1)));
}
void solve()
{
W(scanf("%d%I64d%lf%lf",&r,&n,&ip.x,&ip.y)!=EOF)
{
me(vis,0);
int now=0,tot=0;
Vector iv;
FOR(1,r,i)
{
cin>>s[i];
A[i].read();
B[i].read();
if(on(A[i],B[i],ip))
{
now=route[tot++]=i;
iv=B[i]-A[i];
vis[i]=1;
if(iv*Vector(1,0)<0)
{
iv=Vector(0,0)-iv;
}
}
}
W(1)
{
int nxt=-1;
db dis=1e20;
Vector np,nv;
FOR(1,r,i)
{
if(i!=now)
{
Vector p=getLineCircleIntersecion(i,now);
//printf("%f %f\n",p.x,p.y);
if((p-ip)*iv<eps)//
continue;
db dx=(ip-p).len();
if(dx<dis)
{
nxt=i;
dis=dx;
nv=B[i]-A[i];
if((nv^iv)<0) nv=Vector(0,0)-nv;
np=p+nv*eps;
}
}
}
if(nxt==-1)
{
if(n>=tot) n=tot-1;
cout<<s[route[n]]<<endl;
return ;
}
if(vis[nxt]) break;
route[tot++]=now=nxt;
iv=nv;
ip=np;
}
n%=tot;
cout<<s[route[n]]<<endl;
}
}
int main()
{
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );
int t=1;
//s_1(t);
for(int cas=1;cas<=t;cas++)
{
//printf("Case %d:\n",cas);
solve();
}
}