70pts 9,10两点RE 数组足够大 求助
查看原帖
70pts 9,10两点RE 数组足够大 求助
227723
syysongyuyang楼主2021/11/29 13:47

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
const int N=100006;
long long sum=0;
int n;
struct node
{
    long long time;
    long long cost;
    double worth;
};
node a[N];
bool comp(node a,node b)
{
    if (a.worth!=b.worth)
        return a.worth>b.worth;
}
int main()
{
	//freopen("1.txt","r",stdin);
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
    {
        double square;
        scanf("%d%d",&a[i].time,&a[i].cost);
        square=a[i].time*2;
        double value=a[i].cost;
        a[i].worth=1.0*a[i].cost/square;
    }
    sort(a+1,a+1+n,comp);
    for (int i=1;i<=n;i++)
    {
        for (int j=i+1;j<=n;j++)
        {
            sum+=a[j].cost*2*a[i].time;
        }
    }
    printf("%lld",sum);
    return 0;
}

求大佬帮助,改了半天了

2021/11/29 13:47
加载中...