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:1A贴个代码

Posted by 20142430124 at 2016-05-20 20:24:01 on Problem 1328
In Reply To:1A贴个代码 Posted by:wotok at 2016-02-19 22:34:13
> #include <iostream>
> #include <cstring>
> #include <stdio.h>
> #include <algorithm>
> #include <cmath>
> #include <map>
> #include <vector>
> using namespace std;
> 
> int n;
> double d; 
> struct Node{
> 	double l,r;
> }node[1010];
> bool cmp(const Node& x, const Node& y) {
> 	if(fabs(x.r - y.r) < 1e-5) {
> 		return x.l < y.l;
> 	}
> 	return x.r < y.r; 
> }
> int main() {
> 	int C = 1;
> 	while(scanf("%d%lf",&n,&d),n + d) {
> 		double rmax = -0x3f3f3f3f;
> 		bool ok = true;
> 		for(int i = 0;i < n;i ++) {
> 			double x,y;
> 			scanf("%lf%lf",&x,&y);
> 			if(d < y) {
> 				ok = false;
> 				continue;
> 			}
> 			double dx = sqrt(d * d - y * y);
> 			node[i].r = x + dx; 
> 			node[i].l = x - dx;
> 			rmax = max(rmax,node[i].r);
> 		}
> 
> 		if(ok == false) {
> 			printf("Case %d: %d\n",C++,-1);
> 			continue;
> 		}
> 		sort(node,node+n,cmp);
> 		int ret = 0;
> 		int index = 0;
> 		double end;
> 		do {
> 			end = node[index].r;
> 			while(index < n && (node[index].l < end || fabs(node[index].l - end) < 1e-5)) {
> 				index ++;
> 			}
> 			ret ++;
> 			if(index >= n) {
> 				break;
> 			}
> 		}while(end < rmax || fabs(end-rmax) > 1e-5);
> 		printf("Case %d: %d\n",C++,ret);
> 	}
> }

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