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 |
貌似数据都对啊,想不通为什么wa#include<iostream> #define MAXN 10001 using namespace std; int a[MAXN],b[MAXN]; int N; int BinarySearch(int x) { int p, q, i, L; p = 0; /* Left border of the search */ q = N-1; /* Right border of the search */ L = 0; /* Comparison counter */ while (p <= q) { i = (p + q) / 2; ++L; if(L>14) return 0; if (i == x) { // printf("N=%d,Found item i = %d" // " in L = %d comparisons\n", N,i, L); return L; } if (x < i) q = i - 1; else p = i + 1; } } int main() { int i,l,k,ans,x,y,count; cin>>i>>l; ans=i; a[0]=0; k=0; for(int j=0;j<l;j++) ans=(ans+1)*2; for(N=i+1;N<=ans && N<=10000;N++) { if(BinarySearch(i)==l) a[k++]=N; } count=k; y=0; b[y]=b[++y]=a[0]; for(int j=0;j<k-1;j++) { while(j<k-1 && a[j]+1 == a[j+1] ) { count--; b[y]=a[j+1]; j++; } b[++y]=b[++y]=a[j+1]; } cout<<count<<endl; for(int j=0;j<2*count;j++) { cout<<b[j]; cout<<" "<<b[++j]<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator