1 条题解
-
0
C :
#include<stdio.h> int main() { int finger[10001]; int a, b; scanf("%d %d", &a, &b); for( int i = 0; i < a ; i++ ) scanf("%d", &finger[i]); for( int i = 0; i < b; i++ ) { for(int m = a-1; a >= 0; m-- ) { if ( finger[m] < finger [m + 1] ) { int tmp = finger[m+1] - finger[m ]; int k = m + 1 ; for(int i = m + 2; i < a; i++) { if(finger[m] > finger[i]); else { if ((finger[i] - finger[m]) < tmp) { tmp = finger[i] - finger[m]; k = i; } } } tmp = finger[m]; finger[m] = finger[k]; finger[k] = tmp; for( int i = 0 ; i < a - m - 2; i++) { int tmp; for( int f=m+1 ; f < a-i-1 ; f++ ) { if ( finger[f] > finger[f + 1]) { tmp = finger[f]; finger[f] = finger [f + 1]; finger[f + 1] = tmp; } } } break; } } // for( int i = 0; i < a ; i++ ) // { // if (i == 0) // printf("%d", finger[i]); // else // printf(" %d", finger[i]); // } // printf("\n"); } for( int i = 0; i < a ; i++ ) { if (i == 0) printf("%d", finger[i]); else printf(" %d", finger[i]); } printf("\n"); return 0; }
C++ :
#include<iostream> using namespace std; int main() { int n,m,i,j,k,t,a[10001]; cin>>n>>m; for(i=n-1;i>=0;i--) cin>>a[i]; a[n]=333333333; while(m--) { j=1; while(a[j]>a[j-1]) j++; t=n; for(k=0;k<j;k++) if((a[k]<a[t])&&(a[k]>a[j])) t=k; int temp=a[t]; a[t]=a[j]; a[j]=temp; for(i=0;i<(j/2);i++) { t=a[i]; a[i]=a[j-i-1]; a[j-i-1]=t; } } for(i=n-1;i>0;i--) cout<<a[i]<<" "; cout<<a[0]<<endl; return 0; }
Pascal :
var n,m,max,maxs,i,j,t,k:longint; a:array[0..100000]of longint; p:array[0..100000]of boolean; begin read(n); read(m); for i:=1 to n do read(a[i]); for i:=1 to m do begin max:=maxlongint;maxs:=0; fillchar(p,sizeof(p),false); for j:=n-1 downto 1 do if a[j]<a[j+1]then break; for k:=j+1 to n do if(a[k]<max)and(a[k]>a[j]) then begin max:=a[k];maxs:=k;end; t:=a[j];a[j]:=a[maxs];a[maxs]:=t; for k:=j+1 to n do p[a[k]]:=true; k:=j; for j:=1 to n do if p[j] then begin inc(k);a[k]:=j;end; end; for i:=1 to n-1 do write(a[i],' '); write(a[n]); end.
- 1
信息
- ID
- 233
- 时间
- 1000ms
- 内存
- 125MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者