Codeforces Round #206 (Div. 2) 部分题解

传送门:http://codeforces.com/contest/355

A:水题,特判0

int k,d;
int main(){
    //FIN;
    while(cin>>k>>d){
        if(d != 0){
            cout<<d;
            for(int i = 0 ; i < k-1 ; i++)
                cout<<"0";
            cout<<endl;
        }else {
            if(k >= 2){
                cout<<"No solution"<<endl;
            }else {
                cout<<"0"<<endl;
            }
        }
    }
    return 0;
}

B:水题 直接加就行了

LL c1,c2,c3,c4;
int n,m;
LL a[MAXN];
LL b[MAXN];
int main(){
    //FIN;
    while(cin>>c1>>c2>>c3>>c4){
        cin>>n>>m;
        for(int i = 0 ; i < n ; i++) cin>>a[i];
        for(int i = 0 ; i < m ; i++) cin>>b[i];
        LL suma = 0;
        for(int i = 0 ; i < n ; i++){
            if(c1 * a[i] >= c2) suma+=c2;
            else suma+=(c1*a[i]);
        }
        LL sumb = 0;
        for(int i = 0 ; i < m ; i++){
            if(c1 * b[i] >= c2) sumb+=c2;
            else sumb+=(c1*b[i]);
        }
        suma = min(suma,c3);
        sumb = min(sumb,c3);
        LL res = min(suma+sumb,c4);
        cout<<res<<endl;
    }
    return 0;
}

C:求一遍前缀和,枚举中间线,两边的差值就是没有进行交换位置的次数,计算一下取最小值就行了

LL n,l,r,ql,qr;
LL w[MAXN];
LL pre[MAXN];
LL suf[MAXN];
int main(){
    while(cin>>n>>l>>r>>ql>>qr){
        LL sum = 0;
        for(int i = 0 ; i < n ; i++){
            cin>>w[i];
            sum += w[i];
        }
        for(int i = 0 ; i <= n ; i++){
            pre[i] = (i==0 ? 0 : pre[i-1]+w[i-1]);
            suf[i] = sum - pre[i];
        }
        LL res = LINF;
        for(int i = 0 ; i <= n ; i++){
            LL t = pre[i] * l + suf[i] * r;
            int j = n - i;
            if(i > j) t += (i - j - 1) * ql;
            if(i < j) t += (j - i - 1) * qr;
            res = min(res,t);
        }
        cout<<res<<endl;
    }
    return 0;
}

 

posted @ 2013-10-31 20:42  Felix_F  阅读(207)  评论(0编辑  收藏  举报