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

算法是清楚了~why wa~~谁给点测试数据~~

Posted by thomas_wu at 2009-03-15 10:59:12 on Problem 3485
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;

struct range
{
   double head;
   double tail;
};

bool cmp(range i,range j)
{
  if(i.tail!=j.tail)return i.tail<j.tail;
  return i.tail>j.tail;
}

int main()
{
    int l;
    vector<range>vil;
    while(scanf("%d",&l)!=EOF){
       int d;
       cin>>d;
       int v;
       cin>>v;
       for(int i=0;i<v;i++){
          int x,y;
          cin>>x>>y;
          range inp;
          double r=pow(d*d-y*y,1.0/2);
          if(x-r>0)inp.head=x-r;
          else inp.head=0;
          if(x+r<l)inp.tail=x+r;
          else inp.tail=l;
          vil.push_back(inp);
       }
       sort(vil.begin(),vil.end(),cmp);
       double current=-1;
       int sum=0;
       for(int i=0;i<vil.size();i++){
          if(current>=vil[i].head);
          else{
             current=vil[i].tail;
             sum++;
          }
       }
       cout<<sum<<endl;
    }
}
       
          
          
       

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