在写cmp判断函数时,如果直接相乘比较会溢出,需要转化下比较的式子~
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn = 1010;
typedef long long ll;
struct Node
{
ll a, b, c;
double r;
ll mul;
int idx;
}node[maxn];
int n;
bool cmp(Node aa, Node bb)
{
aa.mul = aa.c * (bb.a + bb.b); //需要优化
bb.mul = (aa.a + aa.b) * bb.c;
if(aa.mul == bb.mul)
return aa.idx < bb.idx;
return aa.mul > bb.mul;
}
int main()
{
while(scanf("%d", &n) != EOF)
{
for(int i = 1; i <= n; i++)
{
scanf("%lld%lld%lld", &node[i].a, &node[i].b, &node[i].c);
node[i].idx = i;
}
sort(node + 1, node + n + 1, cmp);
for(int i = 1; i < n; i++)
{
printf("%d ", node[i].idx);
}
printf("%d\n", node[n].idx);
}
return 0;
}