比赛 |
20101110 |
评测结果 |
WWWWWTWTTT |
题目名称 |
YL杯超级篮球赛 |
最终得分 |
0 |
用户昵称 |
Pom |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2010-11-10 21:31:02 |
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
const int MAXN=500001;
const int oo=100000000000LL;
long long n,i,j,x[MAXN],y[MAXN],w[MAXN];
long long p1,p2,ans,t,k,da;
long long liml=oo,limr=-oo,limu=-oo,limd=oo;
long long cal(long long x1,long long y1)
{
long long tt;
long long re=0;
for (tt=1;tt<=n;tt++)
re+=w[tt]*(abs(x[tt]-x1)+abs(y[tt]-y1));
return re;
}
void init()
{
freopen("ballc.in","r",stdin);
freopen("ballc.out","w",stdout);
scanf("%d",&n);
for (i=1;i<=n;i++)
scanf("%d",&w[i]);
for (i=1;i<=n;i++)
{
scanf("%d%d",&x[i],&y[i]);
if (x[i]<liml) liml=x[i];
if (x[i]>limr) limr=x[i];
if (y[i]<limd) limd=y[i];
if (y[i]>limu) limu=y[i];
}
}
void solve()
{
ans=limr;
srand(1);
for (;;)
{
if (cal(ans,0)>cal(ans-1,0))
{
ans=ans-1;
limr=ans;
}
else
if (cal(ans,0)>cal(ans+1,0))
{
ans=ans+1;
liml=ans;
}
else break;
t=rand()%(limr-liml+1)+liml;
if (cal(t,0)<cal(ans,0)) ans=t;
}
k=limu;
for (;;)
{
if (cal(k,0)>cal(k-1,0))
{
k=k-1;
limu=k;
}
else
if (cal(k,0)>cal(k+1,0))
{
k=k+1;
limd=k;
}
else break;
t=rand()%(limu-limd+1)+limd;
if (cal(0,t)<cal(0,k)) k=t;
}
da=cal(ans,k);
cout<<da<<".00"<<endl;
}
int main()
{
init();
solve();
return 0;
}