这道题考试的时候没看,导致没做;
其实就是一个简单的暴力。
枚举每一个位置,计算其他位置的所有人到这个位置来所画的钱数,比较输出最佳即可。
A C C o d e AC~Code AC Code
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
long long js=0,ans=2147483647214748364,k=1;
string ans_s;
struct node
{
int a,b;
string s;
}e[100010];
int main()
{
freopen("reuntion.in","r",stdin);
freopen("reuntion.out","w",stdout);
while(cin>>e[k].a>>e[k].b>>e[k].s)
{
if(e[k].b==0) //先把零剔除
break;
else
k++;
}
for(int i=1; i<=k; i++)
{
js=0;
for(int j=1; j<=k; j++)
js=js+(e[j].a*abs(e[j].b-e[i].b)); //累计
if(ans>=js)
ans=js,ans_s=e[i].s; //比较
}
cout<<ans_s<<" "<<ans;
return 0;
}