Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:为什么TLE?

Posted by YuRuochen at 2022-08-30 14:02:05 on Problem 1328
In Reply To:为什么TLE? Posted by:YuRuochen at 2022-08-30 14:00:40
> 代码如下(很好理解):
> #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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator