天天看点

2021.08.24【NOIP提高A、B组】模拟 YL杯超级篮球赛 c o d e code code

2021.08.24【NOIP提高A、B组】模拟 YL杯超级篮球赛 c o d e code code
思路:

了解加权平均数

c o d e code code

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>

using namespace std;

int n;
struct node
{
	int w, x, y;
}a[100100];

bool cmp(node x, node y)
{
	return x.x<y.x;
}

bool cmp2(node x, node y)
{
	return x.y<y.y;
}

int main()
{
	scanf("%d", &n);
	int p=0;
	for(int i=1; i<=n; i++)
		scanf("%d", &a[i].w);
	int sumx=0, sumy=0;
	for(int i=1; i<=n; i++)
		scanf("%d%d", &a[i].x, &a[i].y), sumx+=a[i].w, sumy+=a[i].w;
	sort(a+1, a+1+n, cmp);
	sumx=(sumx+1)/2, sumy=(sumy+1)/2;
	int j=0,sum=0;
	while(sum<sumx)
	{
		j++;
		sum+=a[j].w;
	}
	long long ans=0;
	for(int i=1; i<=n; i++)
		ans+=a[i].w*abs(a[i].x-a[j].x);
	sort(a+1, a+1+n, cmp2); 
	j=0,sum=0;
	while(sum<sumy)
	{
		j++;
		sum+=a[j].w;
	}
	for(int i=1; i<=n; i++)
		ans+=a[i].w*abs(a[i].y-a[j].y);
	printf("%lld.00", ans);
	return 0;
}
           

继续阅读