• 个人简介

    #include<bits/stdc++.h> #include<windows.h> #define int long long #define endl '\n' using namespace std; void in(int &x) { int f = 1; char c = getchar(); while ((c < '0' || c > '9') && c != '-') c = getchar(); if (c == '-') f = -1, c = getchar(); for (x = 0; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0'; x = f; } int a[10005]; int n; int k; int ans; signed main() { //freopen("XXX.in","r",stdin); //freopen("XXX.out","w",stdout); //ios::sync_with_stdio(0); //cin.tie(0); //cout.tie(0); srand(time(0)); printf("欢迎使用Monkey-Very-Slow-Sort,请输入数据数量与排序依据\n"); cin >> n >> k; cout<<"\033c"; printf("请输入%d个数据\n",n); for (int i = 1; i <= n; i++) { cin >> a[i]; } bool f = 0; while (f == 0) { f = 1; cout<<"\033c"; printf("请稍等"); for (int i = 1; i <= 5; i++) { Sleep(100); cout << "."; } int temp=0; for (int i = 1; i < n; i++) { int t = (rand() - 1) % k + 1; if (k % 2 == 1) { if (t == ceil(1.0k / 2)) { continue; } else { if (t <= k / 2) { if (a[i] > a[i + 1]) { swap(a[i], a[i + 1]); f = 0;temp++; }

    } else if(t > k / 2) {
    					if (a[i] < a[i + 1]) {
    						swap(a[i], a[i + 1]);
    						f = 0;
    						temp++;
    					}
    				}
    			}
    		}if (k % 2 == 0) {
    			if (t == ceil(1.0*k / 2)||t==(k=2)) {
    				continue;
    			} else {
    				if (t < k / 2) {
    					if (a[i] > a[i + 1]) {
    						swap(a[i], a[i + 1]);
    						f = 0;
    						temp++;
    					}
    				} else if(t > ceil(1.0*k / 2)) {
    					if (a[i] < a[i + 1]) {
    						swap(a[i], a[i + 1]);
    						f = 0;
    						temp++;
    					}
    				}
    			}
    		}
    		Sleep(temp*100);
    		ans++;
    	}
    }
    cout<<"\033c";
    printf("您的数据已经排好了\n");
    for(int i=1;i<=n;i++){
    	cout<<a[i]<<" ";
    }
    printf("\n您的数据共排了%d次",ans);
    return 0;
    

    }

    /* #include<stdio.h> #define N 100005 long long max(long long a,long long b){ if (a>b){ return a; }else { return b; } } int main(){ freopen("jump.in","r",stdin); freopen("jump.out","w",stdout); int T; scanf("%d",&T); while(T--){ int a[N]={0},k[N]={0}; int n; scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); } for(int i=n;i>=1;i--){ k[i]+=a[i]; if(i+a[i]<=n) k[i]+=k[i+a[i]]; } int maxn=0; for(int i=1;i<=n;i++){ maxn=max(maxn,k[i]); } printf("%lld\n",maxn); } return 0; } */

  • 通过的题目

  • 最近活动

    This person is lazy and didn't join any contests or homework.
  • 最近编写的题解

    This person is lazy and didn't write any solutions.

题目标签

系统测试
2