Luo Valley 1583

#include "cstdio"
#include "iostream"
#include "algorithm"
using namespace std;
struct node {
    int w;
    int id;
}s[20010];
bool cmp(node a,node b){
    if (a.w==b.w)
    return a.id<b.id;
    return a.w>b.w;
}
int main (){
    int n,m,e[12];
    scanf ("%d%d",&n,&m);
    for (int i = 1 ; i <= 10 ; i++)scanf ("%d",&e[i]);
    for (int i = 1 ; i <= n ; i++){
        scanf("%d",&s[i].w);
        s[i].id=i;
    }
    sort(s+1,s+n+1,cmp);
    for (int i = 1 ; i <= n ; i++){
        s[i].w +=e[(i-1)%10+1];
    }
    sort(s+1,s+n+1,cmp);
    for (int i = 1; i <= m; i++){
        if (i==m)
        printf ("%d",s[i].id);
        else 
        printf ("%d ",s[i].id);
    }
    printf ("\n");
}
  1. Array size problem
  2. Problems descending sort ascending sort (sorted first identical value not considered)

Guess you like

Origin www.cnblogs.com/AChappy/p/12144551.html