| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
这道题的onlinejudge有bug这样的代码也通过了
我开始做错了
但还ac了
include<iostream.h>
struct pis{ //点的位置
int x;
int y;
};
pis* p;
int work(pis *,int,int,int); //核心算法
void main()
{
int n;
cin>>n;
while(n--)
{
int m,a;
cin>>m>>a;
p=new pis[m];
int i=0;
while(i<m)
{
cin>>p[i].x>>p[i].y;
i++;
}
int max=0;
i=0;
while(i<m)
{
int temp=work(p,i,m,a);
if(temp>max)
max=temp;
i++;
}
cout<<max<<endl;
delete p;
}
}
int work(pis* p,int i,int m,int a)
{
int max=0;
int dec=0;
pis fix;
fix.x=p[i].x;
fix.y=p[i].y;
while(dec<4)
{
int count=0;
if(dec==0)
{
for(int j=0;j<m;j++)
{
if(p[j].x>=fix.x&&p[j].y>=fix.y&&p[j].x<=fix.x+a&&p[j].y<=fix.y+a)
count++;
}
}
if(dec==1)
{
for(int j=0;j<m;j++)
{
if(p[j].x>=fix.x&&p[j].y<=fix.y&&p[j].x<=fix.x+a&&p[j].y>=fix.y-a)
count++;
}
}
if(dec==2)
{
for(int j=0;j<m;j++)
{
if(p[j].x<=fix.x&&p[j].y<=fix.y&&p[j].x>=fix.x-a&&p[j].y>=fix.y-a)
count++;
}
}
if(dec==3)
{
for(int j=0;j<m;j++)
{
if(p[j].x<=fix.x&&p[j].y>=fix.y&&p[j].x>=fix.x-a&&p[j].y<=fix.y+a)
count++;
}
}
if(count>max)
max=count;
dec++;
}
return max;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator