[乱搞]Hdu 6147——Pokémon GO II
来源:互联网 发布:画图软件有哪些 编辑:程序博客网 时间:2024/06/01 08:13
题目描述
众所周知,度度熊最近沉迷于 Pokémon GO。
由于太过沉迷,现在它只能按照游戏内置的指令行走了:对,简直就像一个现实中的Pokémon!
游戏内置的指令实际上可以抽象成一种:保持现在的朝向前行X米,然后右转。度度熊相信,只要遵循这个指令,它就一定可以抓到最珍奇的精灵球。
但不幸的是,这个指令并不是很有可信度,有时会引导度度熊走回原来的位置。现在它想知道,在第几条指令时它第一次回到已经走过的位置?如果这种情况没有发生,请输出 “Catch you”。
解题思路
最开始的想法就是把线段搞一起,判断是否相交,但是无论怎么优都是带log的,显然超时。
仔细观察题目,每次转动的方向是确定的,必然存在某种规律。
通过画图可以发现,只有以下三种相交方式。
所以对于新加的线段只需要判断它与它的前4,5,6条线段是否相交就可以了。
#include<cstdio>#include<algorithm>#define LL long longusing namespace std;char readc(){ static char buf[100000], *l=buf,*r=buf; if (l==r) r=(l=buf)+fread(buf,1,100000,stdin); if (l==r) return EOF;else return *l++;}inline int _read(){ int num=0;char ch=readc(); while (ch<'0'||ch>'9') ch=readc(); while (ch>='0'&&ch<='9') num=num*10+ch-48,ch=readc(); return num;}struct jz{ LL x1,y1,x2,y2;}a[1000005];int t,n,ans;bool check(int x,int y){ if (a[x].x1!=a[x].x2) swap(x,y); if (a[x].y1<=a[y].y1&&a[y].y1<=a[x].y2&&a[y].x1<=a[x].x1&&a[x].x1<=a[y].x2) return 1; return 0;}void work(){ n=_read(); LL x=0,y=0;ans=-1; for (int i=1;i<=n;i++){ int w=_read(); if (ans!=-1) continue; if ((i+1)/2%2==1) w=-w; a[i].x1=x;a[i].y1=y; if (i%2==1) x+=w;else y+=w; a[i].x2=x;a[i].y2=y; if (a[i].y1>a[i].y2) swap(a[i].y1,a[i].y2); if (a[i].x1>a[i].x2) swap(a[i].x1,a[i].x2); if ((i>=4&&check(i,i-4+1))||(i>=6&&check(i,i-6+1))) ans=i; } if (ans==-1) printf("Catch you\n");else printf("%d\n",ans);}int main(){ freopen("exam.in","r",stdin); freopen("exam.out","w",stdout); t=_read(); while(t--) work(); return 0;}
阅读全文
0 0
- [乱搞]Hdu 6147——Pokémon GO II
- hdu[6147] Pokémon GO II
- HUU6147 Pokémon GO II
- hdu 6146 Pokémon GO(DP)
- HDU 6146:Pokémon GO
- 【递推+乱搞】HDU6146 Pokémon GO
- Pokémon GO
- 【结论+简单几何】HDU6147 Pokémon GO II
- 【模拟】HDU6147[Pokémon GO II]题解
- Unbundling Pokémon Go
- HDU6146-Pokémon GO
- HDU6146 Pokémon GO
- HDU 6146 Pokémon GO (dp)
- HDU 6146 Pokémon GO(dp)
- Pokémon GO的蝴蝶效应——国内哪些APP借了任天堂的东风?
- HDU6146 Pokémon GO【DP】
- [递推] HDU6146 Pokémon GO
- HDU6147 Pokémon GO II (2017百度之星程序设计大赛
- ORA-04091错误解决
- webpack2+angular2 按需加载,优化首屏速度
- 2017多校第10场第8题(树上边匹配)
- 监听器(Listener)
- My Oracle Note
- [乱搞]Hdu 6147——Pokémon GO II
- 算法系列——扑克牌的顺子
- 基于 Mathematica 的机器人仿真环境(机械臂篇)
- beamer模版
- ES6 class与ES5 function区别及联系
- 线程安全、非线程安全,同步、异步
- 最小生成树
- codeforces600E. Lomsat gelral(dsu on tree)
- 控制台日志打印乱码的问题