| ||||||||||
| 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 | |||||||||
why WA???代码不长#include <stdio.h>
int r[100],l[100],u[100],d[100];
bool overlap(short i,short j)
{
if(r[i]==0&&l[i]==0&&u[i]==0&&d[i]==0)
return 0;
if(r[j]==0&&l[j]==0&&u[j]==0&&d[j]==0)
return 0;
if(r[i]<=r[j]&&r[i]>=l[j]&&!(d[i]>u[j]||u[i]<d[j]))
return 1;
if(r[j]<=r[i]&&r[j]>=l[i]&&!(d[j]>u[i]||u[j]<d[i]))
return 1;
return 0;
}
int main(int argc, char* argv[])
{
int x,y,xi[100],yi[100],ri[100];
short n;
scanf("%d%d%d",&x,&y,&n);
for(short i=0;i<n;i++)
{
scanf("%d%d%d",&xi[i],&yi[i],&ri[i]);
r[i]=xi[i]+ri[i];
l[i]=xi[i]-ri[i];
u[i]=yi[i]+ri[i];
d[i]=yi[i]-ri[i];
}
bool sign=1;
while(sign)
{
sign=0;
for(i=1;i<n;i++)
if(overlap(i-1,i))
{
sign=1;
if(r[i]<r[i-1])
r[i]=r[i-1];
if(u[i]<u[i-1])
u[i]=u[i-1];
if(l[i]>l[i-1])
l[i]=l[i-1];
if(d[i]>d[i-1])
d[i]=d[i-1];
r[i-1]=l[i-1]=u[i-1]=d[i-1]=0;
}
}
int total=0;
for(i=0;i<n;i++)
total+=(r[i]-l[i])*(u[i]-d[i]);//printf("%d %d\n",(r[i]-l[i]),(u[i]-d[i]));}
printf("%d\n",x*y-total);
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator