codeforces 252B Unsorting Array 暴力+贪心
失算啊,水题啊,比赛没A

#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int a[100005], b[100005]; int main() { int i, j, n; scanf("%d", &n); for(i = 0; i < n ;i++) scanf("%d", &a[i]), b[i] = a[i]; if(n <= 2) { puts("-1"); return 0;} sort(b, b+n); for(i = 0; i < n-1; i++) { if(a[i] == a[i+1]) continue; swap(a[i], a[i+1]); for(j = 0; j < n && a[j] == b[j]; j++); if(j == n) { swap(a[i], a[i+1]); continue; } for(j = 0; j < n && a[j] == b[n-j-1]; j++); if(j == n) { swap(a[i], a[i+1]); continue; } printf("%d %d\n", i+1, i+2); return 0; } puts("-1"); }