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 |
哪儿错了?#include <iostream> #include <sstream> #include <string> #include<vector> #include <algorithm> #include<math.h> using namespace std; #define MAXN 10000 int A[MAXN]; int N; int h(0); int i, L1; int k(0); vector<int> v; struct a { int b; int e; int l; }c[500]; void BinarySearch(int x) { int p, q, L; for(int m=0;m<10001;m++) { N=m; q = N-1; p = 0; L = 0; while (p <= q) { i = (p + q) / 2; ++L; if ((A[i] == x)&&(L==L1 )) { v.push_back(m); if((m)!=h+1 ) { k++; } h=m; } if (x < A[i]) q = i - 1; else p = i + 1; } } return ; } void main() { int i; int k2(0); for(i=0;i<10001;i++) A[i]=i; cin>>i>>L1; BinarySearch(i); vector<int> v1; cout<<k<<endl; //sort(v.begin(),v.end()); if(v.size()==0) ; else { for(i=0;i<v.size()-1;i++) { v1.push_back(v.at(i)); if((v.at(i)+1)!=v.at(i+1)) { k2++; c[k2].b=v1.front(); c[k2].e=v1.back(); c[k2].l=v1.size(); //cout<<v1.front()<<" "<<v1.back()<<endl; v1.clear(); } } v1.push_back(v.back()); k2++; c[k2].b=v1.front(); c[k2].e=v1.back(); c[k2].l=v1.size(); for( i=1;i<=k2;i++) for(int j=i+1;j<=k2;j++) if(c[i].l>c[j].l ) { swap(c[i].l,c[j].l); swap(c[i].b,c[j].b); swap(c[i].e,c[j].e); } for( i=1;i<=k2;i++) { cout<<c[i].b<<" "<<c[i].e<<endl; } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator