1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #include <algorithm> #include <iostream> using namespace std; const int N=1000; int c[N]; int logic(int x, int y){ return (x&y)^((x^y)|(~x&y)); } void generate(int a, int b, int *c){ for(int i=0;i<b;i++) c[i]=logic(a,i)%(b+1); } void recursion(int depth, int *arr, int size){ if(depth<=0||size<=1)return ; int pivot=arr[0]; int i=0,j=size-1; while(i<=j){ while(arr[i]<pivot)i++; while(arr[j]>pivot)j--; if(i<=j){ int temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; i++;j--; } } recursion(depth-1, arr, j+1); recursion(depth-1, arr+i, size-i); } int main(){ int a,b,d; cin>>a>>b>>d; generate(a,b,c); recursion(d,c,b); for(int i=0;i<b;i++)cout<<c[i]<<" "; cout<<endl; } |
0 of 5 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 5 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
2、当输入 5 5 1
时,输出为 1 1 5 5 5
。( )
3、假设数组 c 长度无限制,该程序所实现的算法的时间复杂度是 O(b) 的。( )
4、函数 int logic(int x, int y)
的功能是( )
5、当输入为 10 100 100
时,输出的第 100 个数是?( )