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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
| #include <iostream>
using namespace std; void test4(); int main(int argc, char *argv[]) { test4(); return 0; }
void test1(){ int p,e,i,d,count = 0; int j,k; while(1) { scanf("%d%d%d%d",&p,&e,&i,&d); if(p != -1) { count ++; for(j = d +1; j < 21252; j++){ if((j - p) % 23 ==0) break; }
for(; j < 21252; j = j +23){ if((j - e) % 28 ==0) break; }
for(; j < 21252; j = j + 23 * 28){ if((j - i) % 33 ==0) break; } printf("Case %d: the next triple peak occurs in %d days.\n",count,j-d); } else{ break; } } }
void test2(){ int N=0; cin>>N; for(int a=2;a<=N;a++){ for(int b=2;b<=a-1;b++){ for(int c=b;c<a-1;c++){ for(int d=c;d<=a-1;d++){ if(a*a*a==b*b*b+c*c*c+d*d*d){ cout<<"Cube = "<<a<<", Triple = ("<<b<<","<<c<<","<<d<<")"<<endl; } } } } } }
void test3(){ int n,m,i,j; scanf("%d%d",&n,&m); for(i=0;i<n;i++){ for(j=0;j<m;j++){ scanf("%d",&a[i][j]); } }
for(i=m-1;i>=0;i--){ for(j=0;j<n;j++){ printf("%d",a[j][i]); if(j!=n-1){ putchar(' '); } } putchar('\n'); } }
void queen(int i,int n) { if(i>n){ dispasolution(n); }else{ for(int j=1;j<=n;j++){ if(place(i,j)){ q[i]=j; queen(i+1,n); } } } }
void Hanoi(int n,char x,char y,char z) { if(n==1){ printf("将第%d个盘片从%c移动到%c\n",n,x,z); }else{ Hanoi(n-1,x,z,y); printf("将第%d个盘片从%c移动到%c\n",n,x,z); Hanoi(n-1,y,x,z); }
}
int Partition(int a[],int low,int high){ int pivot = a[low]; while(low<high){ while(high>low&&a[high]>=pivot){ high--; } a[low]=a[high]; while(low<high&&a[low]<=pivot){ low++; } a[high]=a[low]; } a[low]=pivot; output(a,n); return low; }
void QuickSort(int a[],int low,int high){ int mid=0; if(low<high){ mid = Partition(a,low,high); QuickSort(a,low,mid-1); QuickSort(a,mid+1,high); } }
void InsertSort(int *a,int n){ int j; for(int i=1;i<n;i++){ int temp = a[i]; for(j=i-1;j>=0&&temp<a[j];j--){ a[j+1]=a[j]; } a[j+1]=temp; output(a,n); } }
void ShellInsert(int *L,int n,int dk){ int j; for(int i=dk;i<n;i++){ if(L[i]<L[i-dk]){ int temp = L[i]; for(j=i-dk;j>=0&&temp<L[j];j-=dk){ L[j+dk]=L[j]; } L[j+dk] = temp; } } }
void ShellSort(int *L,int n,int dlta[],int t){ for(int k=0;k<t;k++){ ShellInsert(L,n,dlta[k]); printf("第%d趟排序结果:\n",k+1); output(L,n); } }
void HeapAdjust(int* a,int s,int e) { int dad = s; int son = dad * 2 + 1; while (son <= e) { if (son + 1 <= e && a[son] < a[son + 1]) son++; if (a[dad] > a[son]) return; else { swap(a[dad], a[son]); dad = son; son = dad * 2 + 1; } } }
void HeapSort(int *a,int n) { int t; int i; for(i=n/2-1;i>=0;--i) { HeapAdjust(a,i,n-1); } output(a,n); for(i=n-1;i>0;--i) { swap(a[0],a[i]); output(a,n); HeapAdjust(a,0,i-1); output(a,n); } }
|