蒟蒻萌新再也不写交互题了
#include <bits/stdc++.h>
using namespace std;
extern "C" bool inside_shape(int x,int y);
int up(int x,int y,int s)
{
int l=s,r=x-1,mid,ans=x;
while(l<=r)
{
mid=(l+r)/2;
if(inside_shape(mid,y))
{
ans=mid;
r=mid-1;
}
else
{
l=mid+1;
}
}
return ans;
}
int down(int x,int y,int s)
{
int l=x+1,r=s,mid,ans=x;
while(l<=r)
{
mid=(l+r)/2;
if(inside_shape(mid,y))
{
ans=mid;
l=mid+1;
}
else
{
r=mid-1;
}
}
return ans;
}
int left(int x,int y,int s)
{
int l=s,r=y-1,mid,ans=y;
while(l<=r)
{
mid=(l+r)/2;
if(inside_shape(x,mid))
{
ans=mid;
r=mid-1;
}
else
{
l=mid+1;
}
}
return ans;
}
int right(int x,int y,int s)
{
int l=y+1,r=s,mid,ans=y;
while(l<=r)
{
mid=(l+r)/2;
if(inside_shape(mid,y))
{
ans=mid;
l=mid+1;
}
else
{
r=mid-1;
}
}
return ans;
}
extern "C" bool am_i_square(int N, int Q)
{
int x_1=N+1,x_2=0,y_1=N+1,y_2=0;
int plus=ceil(N*0.2);
for(int i=1;i<N;i+=plus)
{
for(int j=1;j<N;j+=plus)
{
if(inside_shape(i,j))
{
x_1=min(x_1,i);
x_2=max(x_2,i);
y_1=min(y_1,j);
y_2=max(y_2,j);
}
}
}
if(x_2)
{
int new_x_1=0,new_y_1=0,new_x_2=0,new_y_2=0;
new_x_1=up(x_1,y_1,min(N,x_1+plus));
new_y_1=left(x_1,y_1,y_1-plus+1);
new_x_2=down(x_2,y_2,x_2-plus+1);
// new_y_2=right(x_2,y_2,min(N,y_2+plus)); 会超时哦~
new_y_2=new_y_1+(new_x_1-new_x_2+1)-1;
return new_y_2<=N and (inside_shape(new_x_2,new_y_2) and (new_y_2==N or !inside_shape(new_x_1,new_y_2)));
}
if(inside_shape(N,N))
{
return !inside_shape(N,plus) and !inside_shape(N,N-plus);
}
int new_x=0,new_y=0;
for(int i=plus;i<N;i+=plus)
{
if(inside_shape(i,N))
{
new_x=up(i,N,min(N,i+plus));
return !inside_shape(new_x+plus,N);
}
}
for(int i=plus;i<N;i+=plus)
{
if(inside_shape(N,i))
{
new_y=left(N,i,min(N,i+plus));
return !inside_shape(N,new_y+plus);
}
}
return 0;
}