zoukankan      html  css  js  c++  java
  • 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);  
        	}  
    	}
    }
    

      

  • 相关阅读:
    Windows XP中万能断点
    c#运算符 ?
    转神秘的程序员
    经典解决“线程间操作无效
    文件上传
    dowload.aspx
    mail
    js 正则
    新年快乐
    DataTable Compute
  • 原文地址:https://www.cnblogs.com/dragondragon/p/11372675.html
Copyright © 2011-2022 走看看