#include <stdio.h> int main(int argc, const char * argv[]) { // insert code here... int T,m=0,n=0; scanf("%d",&T); while (T--) { scanf("%d %d",&n,&m); int arr[100000]={0},brr[100000]={0},i,crr[100000]={0}; for (i=1; i<n+1; i++) { scanf("%d %d",&arr[i],&brr[i]); crr[i]=i; } int temp; for (int k=1 ; k<n+1 ; k++) for (int j = 1; j < n - k+1 ; j++) { //如果前面的数比后面的小,进行交换 if (arr[j] <arr[j + 1]) { temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; temp = brr[j]; brr[j] = brr[j + 1]; brr[j + 1] = temp; temp = crr[j]; crr[j] = crr[j + 1]; crr[j + 1] = temp; } if (arr[j] ==arr[j + 1]) { if (brr[j]<brr[j+1]) { temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; temp = brr[j]; brr[j] = brr[j + 1]; brr[j + 1] = temp; temp = crr[j]; crr[j] = crr[j + 1]; crr[j + 1] = temp; } } } for (int i=1; i<n; i++) { printf("%d ",crr[i]); }printf("\n"); } return 0; } |
Double click to view unformatted code.