题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6147
感觉算是百度之星2017复赛最简单的一道题了
画个图就可以发现规律
因为是按照一个方向转的,那么在不存在路径覆盖的情况下,转圈只能越来越大或越来越小,而且在这种一圈圈包含的情况下,若要路径覆盖,只能和上一级进行覆盖,如图示
那么每一条线段只可能和前8段进行路径覆盖(实际上会更小),枚举判断就可以了,或者记录相邻圈层四个面的极值,看是否有超出
贴代码
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
int n,Q,ans;
int x[1000005];
int fg[8][2]={{1,0},{0,-1},{-1,0},{0,1},{1,0},{0,-1},{-1,0},{0,1}};
char nc(){
static char buf[100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
void read(int &x){
int res=0,ff=1;char ch=nc();
while (!('0'<=ch&&ch<='9'))ch=='-'?ff=-1:0,ch=nc();
while ('0'<=ch&&ch<='9')res=(res<<3)+(res<<1)+ch-'0',ch=nc();
x=ff*res;
}
bool check(ll xx,ll y1,ll y2,ll yy,ll x1,ll x2){
return ((y1<=yy&&yy<=y2)||(y2<=yy&&yy<=y1))&&((x1<=xx&&xx<=x2)||(x2<=xx&&xx<=x1));
}
bool Check(ll x1,ll y1,ll y2,ll x2,ll y3,ll y4){
return (x1==x2)&&((y3<=y1&&y1<=y4)||(y4<=y1&&y1<=y3)||(y3<=y2&&y2<=y4)||(y4<=y2&&y2<=y3));
}
int main(){
// freopen("6147.in","r",stdin);
// freopen("6147.out","w",stdout);
read(Q);
while (Q--){
read(n);
ans=0;
for (int i=1;i<=n;i++)read(x[i]);
for (int i=1;i<=n;i++){
ll a,b;
a=0,b=x[i];
for (int j=0;j<=7;j++){
if (j%2==0&&j!=0)
if ((i>j+1)&&check(0,0,x[i],b,a,a+ll(fg[j][0])*ll(x[i-j-1])))ans=i;
if (j%2==1)
if ((i>j+1)&&Check(0,0,x[i],a,b,b+ll(fg[j][1])*ll(x[i-j-1])))ans=i;
a=a+fg[j][0]*x[i-j-1];b=b+fg[j][1]*x[i-j-1];
}
if (ans!=0)break;
}
if (ans==0)printf("Catch you\n");else printf("%d\n",ans);
}
return 0;
}
【写的有漏洞的,欢迎路过大神吐槽】
2017/08/23 23:04:27
Ending.