2016陕西省赛 Rui and her sequences

2016陕西省赛 Rui and her sequences

题目链接:http://oj.xjtuacm.com/contest/4/problem/36/

题目大:将一个只含0,1,2的数组按不递减排序,仅有两种操作1.将所有的2置前,所有的0置后,花费a;2.将两个数交换,花费b.问最小花费.

贪心

提示里的Please ignore the first operation!什么鬼(╯‵□′)╯︵┻━┻

代码如下:

#include <cstdio>
#include <iostream>
#include <cstring>
#define N 100005
using namespace std;
int n,x,y,a[N],num[3];
struct node{
    int n[3];
    void init(){
        memset(n,0,sizeof(n));
    }
}A,B,C;
int main(void){
    while(~scanf("%d%d%d",&n,&x,&y)){
        int cost=0;
        num[0]=num[1]=num[2]=0;
        for(int i=0;i<n;++i){
            scanf("%d",&a[i]);
            num[a[i]]++;
        }

        A.init(),B.init(),C.init();
        for(int i=0;i<n;++i){
            if(i<num[0])A.n[a[i]]++;
            else if(i<num[0]+num[1])B.n[a[i]]++;
            else if(i<num[0]+num[1]+num[2])C.n[a[i]]++;
        }
        int one=min(A.n[1],B.n[0]),two=min(A.n[2],C.n[0]);
        cost=y*(A.n[1]+A.n[2]+max(B.n[2],C.n[1]));

        //cost=min(cost,x+y*max(num[0],num[2]));
        printf("%d\n",cost);
    }
}

 

posted @ 2017-05-11 16:48  barriery  阅读(241)  评论(0编辑  收藏  举报