• Radar Installation(利用数据有序化进行贪心选择)


    English appre:

    an infinite straight line:一条无限长的直线

    on the coasting:在海岸线上

    Cartesian coordinate system,

    题目地址:http://poj.org/problem?id=1328

    我的代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    
    struct dao
    {
    	double x,y;
    }da[10000];
    bool cmp(dao a,dao b)
    {
    	return (a.y<b.y)||(a.y==b.y && a.x>b.x);
    }
    
    int main()
    {
    	int n,d;
    	double x1,y1;
    	int k=0;
    	while(~scanf("%d%d",&n,&d)&&(n||d))
    	{
    		int ans=1;
    		for(int i=0;i<n;i++)
    		{
    			scanf("%lf%lf",&x1,&y1);
    			da[i].x=x1-sqrt((double)d*(double)d-(double)y1*y1);
    			da[i].y=x1+sqrt((double)d*(double)d-(double)y1*y1); 
        		if((d-y1)<0||d<=0) ans=-1; 
        	}
    	 
    		if(ans==-1)
     		{
    	 		printf("Case %d: -1
    ",++k);
     	 		continue;
    		}
      		else
        	{
        		sort(da,da+n,cmp);  
        		double t1=da[0].y;  
        		for(int i=1;i<n;i++)  
            		if(da[i].x>t1)//要是用=号,有些数据不可通过。  
            		{  	
    					ans++;  
            			t1=da[i].y;//更新右范围  
            		}  
             	printf("Case %d: %d
    ",++k, ans);  
        	}  
    	}
    }
    

      

  • 相关阅读:
    POJ 3349 HASH
    POJ 1840 HASH
    POJ 2785 HASH
    HDU 3926 图的同构
    POJ 2549 二分+HASH
    POJ 2002 统计正方形 HASH
    POJ 1971 统计平行四边形 HASH
    POJ 1635 树的最小表示法/HASH
    POJ 1200 字符串HASH
    ACM学习历程—HDU 1272 小希的迷宫(并查集)
  • 原文地址:https://www.cnblogs.com/dragondragon/p/11372675.html
Copyright © 2020-2023  润新知