10 2
3
5 3
3 7
9 4
3
5 3
3 7
9 4
- /*
- * 喷泉问题
- * tanliboy Nov.25 2008
- */
- #include<iostream>
- #include<vector>
- #include<cmath>
- using namespace std;
- template<class T,class O>
- int partition(T a,int from,int to,O order)
- {
- int cur = from;
- for(int i = from;i<to-1;i++)
- {
- if(a[i] < a[to-1])
- {
- swap(a[i],a[cur]);
- swap(order[i],order[cur]);
- cur++;
- }
- }
- swap(a[cur],a[to-1]);
- swap(order[cur],order[to-1]);
- return cur;
- }
- template<class T,class O>
- void quickSort(T a,int from,int to,O order)
- {
- if(from>= to)
- {
- return;
- }
- int p = partition(a,from,to,order);
- quickSort(a,from,p,order);
- quickSort(a,p+1,to,order);
- }
- int main()
- {
- double l,w;
- cin>>l>>w;
- int n;
- cin>>n;
- vector<double> a(n);
- vector<double> b(n);
- for(int i =0;i<n;i++)
- {
- double x,r;
- cin>>x>>r;
- double d=0;
- if(r>w/2)
- {
- d = sqrt(r*r - w*w/4);
- }
- a[i] = x - d;
- b[i] = x + d;
- }
- vector<int> order(n);
- for(int i = 0;i<n;i++)
- {
- order[i] = i;
- }
- quickSort(a.begin(),0,n,order.begin());
- //calculate
- double pos = 0;
- for(int i = 0;i<n;)
- {
- int maxIndex = -1;
- double max = 0;
- while(a[i]<pos && i<n)
- {
- double r = b[order[i]];
- if(r > max)
- {
- max = r;
- maxIndex = i;
- }
- i++;
- }
- if(maxIndex == -1)
- {
- //error: can't cover
- cerr<<"error"<<endl;
- return -1;
- }else
- {
- cout<<order[maxIndex]<<endl;
- pos = max;
- if(max >= l)
- {
- return 0;
- }
- }
- }
- return 0;
- }