Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
算法是清楚了~why wa~~谁给点测试数据~~#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator