zoukankan      html  css  js  c++  java
  • 贪心Poj1328

    题目:http://poj.org/problem?id=1328 注意 输出 Case :这里是有个空格的。。和之前序列想法差不多 尽可能 向一边贪心。

    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <stack>
    #include <queue>
    #include <vector>
    #include <map>
    #include <string>
    #include <iostream>
    using namespace std;
    struct Node
    {
    	double l;double r;
    }node[11111];
    
    double  gao(double r,double x )
    {
    	return sqrt(r*r-x*x);
    }
    
    int cmp(const Node &a,const Node &b)
    {
    	return a.r<b.r;
    }
    int main()
    {
    	int n,d;
    	//freopen("in.txt","r",stdin);
    	//freopen("out.txt","w",stdout);
    	double x,y;int sum=1;
    	while(scanf("%d%d",&n,&d),n||d){
    		int jiba=0;
    		for(int i=0;i<n;i++){
    			scanf("%lf%lf",&x,&y);
    			if(y>d||d<0||y<0){
    				jiba=1;continue;
    			}
    			double len=gao(d,y);
    			double l,r;
    			l=x-len;r=x+len;
    			node[i].l=l;node[i].r=r;
    		}
    		sort(node,node+n,cmp);
    		double ret[11111];
    		int ans=0;
    		for(int i=0;i<n;i++){
    			int flag=0;
    			for(int j=0;j<ans;j++){
    				if(node[i].l<=ret[j]&&node[i].r>=ret[j]){
    					flag=1;break;
    				}
    			}
    			if(!flag){
    				ret[ans++]=node[i].r;
    			}
    		}
    		printf("Case %d: ",sum++);
    		if(jiba)
    			printf("-1
    ");
    		else
    		    printf("%d
    ",ans);
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    [JZOJ3388] 绿豆蛙的归宿

    [JZOJ3464] 秀姿势
    [JZOJ3462] 休息
    [JZOJ3461] 小麦亩产一千八
    [JZOJ3509] 倒霉的小C
    [JZOJ1267] 路障
    CF52C Circular RMQ
    P4162 [SCOI2009]最长距离
    P4047 [JSOI2010]部落划分
  • 原文地址:https://www.cnblogs.com/yigexigua/p/3773604.html
Copyright © 2011-2022 走看看