Round 1201 (Codeforces Round #577(div.2)) 题解

Problem A

The meaning of problems

N-students, m examination questions. Every fraction has questions ai. Each student answered each question (answer exists only A, B, C, D, E). They do not know the correct answer. Q score of students in the best case is.

Thinking

Violence can be. For every questions enumerate all possible answers, the questions all the students calculate the total score, taking the total answer to a maximum of added them to go.

# include <bits/stdc++.h>
# define rr register
const int N=1010;
int n,m;
int val[N];
char a[N][N];
char ans[10]={' ','A','B','C','D','E'};
int sum;
int main(void){
    scanf("%d%d",&n,&m);
    for(rr int i=1;i<=n;++i){
        for(rr int j=1;j<=m;++j){
            std::cin>>a[i][j];
        }
    }
    for(rr int i=1;i<=m;++i){
        scanf("%d",&val[i]);
    }
    for(rr int i=1,maxx,tmp;i<=m;++i){
        maxx=-1e9;
        for(rr int k=1;k<=5;++k){
            tmp=0;
            for(rr int j=1;j<=n;++j){
                if(a[j][i]==ans[k]){
                    tmp+=val[i];
                }
            }
            maxx=std::max(maxx,tmp);            
        }
        sum+=maxx;
    }
    printf("%d",sum);
    return 0;
}

Problem B

The meaning of problems

Give you an array of length n, array elements are positive integers. Each can select two different elements, all of which are decremented by one. After asking several times after the operation can not be the entire array of elements have become zero.

Thinking

The nightmare began ... This question had to pay three times before, fined 100 points.Love dearly

First, if the entire array and an odd number, then there must not. Because each array element such that the action and minus 2, and if desired array elements of 0, and then the original array is not odd (odd - even-odd integer).

Further, if the array elements is greater than the maximum sum of other elements, it is not possible. Because when all other elements becomes zero, the largest element can not be changed to 0.

# include <bits/stdc++.h>
# define rr register
# define int long long
const int N=200010;
int a[N];
int b[N];
int sum;
int n;
signed main(void){
    scanf("%I64d",&n);
    for(rr int i=1;i<=n;++i){
        scanf("%I64d",&a[i]);
        sum+=a[i];
    }
    std::sort(a+1,a+1+n);
    if(sum%2||a[n]>(sum-a[n])){
        printf("NO");
        return 0;
    }else{
        printf("YES");
        return 0;
    }
    return 0;
}

Problem C

(Go to write in the morning. Xianshui)

Problem D,E1,E2

He glanced. too difficult.

Guess you like

Origin www.cnblogs.com/liuzongxin/p/11300830.html