hdu - 6281,2018CCPC湖南全国邀请赛F题,快排

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6281

题意:
  根据已给出的式子,进行排序,然后输出排完序后原先的下表。

题解:用结构体保存,在用结构体排序,利用stable_sort()稳定排序。因为会爆long long ,所以对式子进行转换。
  


代码:

#include<bits/stdc++.h>

using namespace std;

struct node{
    int n;
    long long a,b,c;
    friend  bool operator< (const node &a,const node &b){
        return a.c*(b.a+b.b)>b.c*(a.a+a.b);
    }
}num[1010];

int main(){
    long long n,a,b,c;
    while(~scanf("%lld",&n)){
        for(int i=1;i<=n;i++){
            scanf("%lld%lld%lld",&a,&b,&c);
            num[i].a=a,num[i].b=b,num[i].c=c;
            num[i].n=i;
        }
        stable_sort(num+1,num+n+1);
        for(int i=1;i<=n;i++){
            printf("%d%c",num[i].n,i==n?'\n':' ');
        }
    }
}

By Rvelamen

猜你喜欢

转载自www.cnblogs.com/hzuCode/p/9142833.html