# CodeForces 1245D Shichikuji and Power Grid

cf题面

## 解题思路

3
1 1
2 2
2 1
1 5 100
1 2 1

## 源代码

#include<cstdio>
#include<algorithm>
int n;
struct City{
int id;
long long x,y;
long long cc,kk;
bool self;
int fa;
bool operator < (const City & a)const{
return cc<a.cc;
}
}c[2005];
int main()
{
// freopen("test.in","r",stdin);
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
c[i].id=i;
c[i].self=1;
scanf("%lld%lld",&c[i].x,&c[i].y);
}
for(int i=1;i<=n;i++) scanf("%lld",&c[i].cc);
for(int i=1;i<=n;i++) scanf("%lld",&c[i].kk);
long long ans=0,selfnum=0;
for(int i=1;i<=n;i++)
{
std::sort(c+i,c+1+n);//大概就是要随时排序，每次找到最小的
ans+=c[i].cc;
if(c[i].self) selfnum++;
for(int j=i+1;j<=n;j++)
{
long long cost=(c[i].kk+c[j].kk)*(std::abs(c[i].x-c[j].x)+std::abs(c[i].y-c[j].y));
if(cost<c[j].cc)
{
c[j].cc=cost;
c[j].self=0;//放弃自建
c[j].fa=c[i].id;
}
}
}
printf("%lld\n%lld\n",ans,selfnum);
for(int i=1;i<=n;i++)
if(c[i].self) printf("%d ",c[i].id);
printf("\n%lld\n",n-selfnum);
for(int i=1;i<=n;i++)
if(!c[i].self) printf("%d %d\n",c[i].id,c[i].fa);
return 0;
}
posted @ 2019-11-02 15:08  wawcac  阅读(...)  评论(...编辑  收藏