codeforces Codeforces Round #597 (Div. 2) D. Shichikuji and Power Grid

#include <bits / STDC ++ H.>
 the using  namespace STD;
 int n-;
 struct City {
     int ID;
     Long  Long X, Y;   // coordinate 
    Long  Long CC, KK;   // takes self cost, connection 
    BOOL Self ; // Website or 
    int FA; // connection station 
    BOOL  operator <( const City a &) const {
         return CC < a.cc.;
    }
} c[2005];
int main() {
    scanf("%d",&n);
    for(int i=1; i<=n; i++) {
        C [I] .id = I; // stations number 
        C [I] = .self . 1 ;   // first of all a self default 
        Scanf ( " %% LLD LLD " , & C [I] .x, & C [ I] .y);   // input coordinate 
    }
     for ( int I = . 1 ; I <= n-; I ++) Scanf ( " % LLD " , & C [I] .cc);   // initial self are 
    for ( int = I . 1 ; I <= n-; I ++) Scanf ( " % LLD " , & C [I] .kk); // connection 
    Long  Long ANS = 0 , = selfnum0;
    for(int i=1; i<=n; i++) {
        the Sort (c + i, c + 1 + the n-); // probably be ready to sort, find the smallest each time, every time before ordering to exclude, prevent pay more fees 
        ANS + = c [i] .cc;   // fee 
        iF (C [I] .self) selfnum ++;   // determines whether self 
        for ( int J = I + . 1 ; J <= n-; J ++ ) {
             Long  Long cost = (C [I] .kk + C [J]. KK) * (ABS (C [I] .xc [J] .x) + ABS (C [I] .y- C [J] .y));
             IF (cost < C [J] .cc) {
                c[j].cc=cost;
                c [J] .self = 0 ; // give up self, she said to have established contacts with other stations 
                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;
}
/ * First, assume that each point are self-built, so the cost of each point is self-built price.
Then sorted according to the cost, with minimal costs to the point that the update point behind,
If you can update the price of electricity, put those points are connected to the current point.
Then enter the next cycle, exclude the last time the minimum price to pay, the rest of the points again in accordance with the cost of sorting,
And then use these points to update the minimum cost of the other, and so on.   * /

 

Guess you like

Origin www.cnblogs.com/QingyuYYYYY/p/11784800.html