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

贴代码

Posted by lvweihua at 2017-08-08 12:09:59 on Problem 1328
#include<cstdio>  //本问题转化成贪心思想的区间选点问题
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN=1003;
int X[MAXN],Y[MAXN];
struct Line{
    double l,r;
}line[MAXN];
int n,d;
int cmp(const Line &a,const Line &b){
    return a.r<b.r;
}
int solve(){
    if(d<=0||n<=0)return -1;   //注意极端特殊的情况
    for(int i=0;i<n;i++){
        double dis=d*d*1.0-Y[i]*Y[i]*1.0;
        if(dis<0)return -1;   //不满足条件
        line[i].l=X[i]-sqrt(dis);
        line[i].r=X[i]+sqrt(dis);
    }
    sort(line,line+n,cmp);
    int t=0,ans=1;   //第一个雷达站肯定要放置
    for(int i=1;i<n;i++){
        if(line[i].l>line[t].r){
            t=i;
            ans++;
        }
    }
    return ans;
}
int main()
{
    int t=0;
    while(scanf("%d%d",&n,&d)){
        if(n==0&&d==0)break;
        for(int i=0;i<n;i++)
            scanf("%d%d",&X[i],&Y[i]);
        int res=solve();
        printf("Case %d: %d\n",++t,res);
    }
    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