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 |
Re:Notice~暴力加scanf水过~cin。。TLE#include<iostream> #include<fstream> #include<algorithm> using namespace std; int num[1025]; int main() { //ifstream cin("a.txt"); int tot, n, m; scanf("%d", &tot); while (tot--) { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &num[i]); while (m--) { int i, signal = 0; for (i = n - 1; i > 0; i--) if (num[i] < num[i + 1]) { signal = 1; break; } if (!signal) { for (int i = 1; i <= n; i++) num[i] = i; continue; } int min = 10000, k; for (int j = i + 1; j <= n; j++) if (num[j] - num[i] > 0 && num[j] - num[i] < min) { min = num[j] - num[i]; k = j; } int temp = num[k]; num[k] = num[i]; num[i] = temp; for (int l = i + 1; l <= (n + i + 1) / 2; l++) { temp = num[l]; num[l] = num[n + i + 1 - l]; num[n + i + 1 - l] = temp; } } for (int j = 1; j <= n; j++) printf("%d ", num[j]); printf("\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator