| ||||||||||
| 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 | |||||||||
为什么TLE?代码如下(很好理解):
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int n,d,x,y,t;
struct line{
double s,e;
} ls[1010];
bool cmp(line a,line b){
return a.s<b.s;
}
int main(){
while(~scanf("%d%d",&n,&d)){
if(!n&&!d) break;
t++;
bool flag=1;
for(int i=1;i<=n;i++){
scanf("%d%d",&x,&y);
if(y>d){
flag=0;
break;
}
double p=sqrt(d*d-y*y);
ls[i].s=x-p;
ls[i].e=x+p;
}
if(!flag){
printf("Case %d: -1\n",t);
continue;
}
sort(ls+1,ls+n+1,cmp);
int cnt=0;
double now=-1e9;
for(int i=1;i<=n;i++){
if(ls[i].s>now){
cnt++;
now=ls[i].e;
}else if(ls[i].e<now) now=ls[i].e;
}
printf("Case %d: %d\n",t,cnt);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator