练习codeforces1511A. Review Site

题目如下
A. Review Site
time limit per test2 seconds
memory limit per test256 megabytes
You are an upcoming movie director, and you have just released your first movie. You have also launched a simple review site with two buttons to press — upvote and downvote.

However, the site is not so simple on the inside. There are two servers, each with its separate counts for the upvotes and the downvotes.

𝑛 reviewers enter the site one by one. Each reviewer is one of the following types:

type 1: a reviewer has watched the movie, and they like it — they press the upvote button;
type 2: a reviewer has watched the movie, and they dislike it — they press the downvote button;
type 3: a reviewer hasn't watched the movie — they look at the current number of upvotes and downvotes of the movie on the server they are in and decide what button to press. If there are more downvotes than upvotes, then a reviewer downvotes the movie. Otherwise, they upvote the movie.
Each reviewer votes on the movie exactly once.

Since you have two servers, you can actually manipulate the votes so that your movie gets as many upvotes as possible. When a reviewer enters a site, you know their type, and you can send them either to the first server or to the second one.

What is the maximum total number of upvotes you can gather over both servers if you decide which server to send each reviewer to?

Input
The first line contains a single integer 𝑡 (1≤𝑡≤104) — the number of testcases.

Then the descriptions of 𝑡 testcases follow.

The first line of each testcase contains a single integer 𝑛 (1≤𝑛≤50) — the number of reviewers.

The second line of each testcase contains 𝑛 integers 𝑟1,𝑟2,…,𝑟𝑛 (1≤𝑟𝑖≤3) — the types of the reviewers in the same order they enter the site.

Output
For each testcase print a single integer — the maximum total number of upvotes you can gather over both servers if you decide which server to send each reviewer to.

题目大意
根据投票机制,每组有n位评审投票,其中分为三种评审,概括为:1.投赞成票 2.投反对票 3.跟风投票(跟着投的多的投)
因为需要得到尽可能多的赞成票,分为两个服务器,可以将不同的票分进两个服务器,最终递交赞成票数更多的票数

题目分析
根据这种机制,因为第一第二种票不可更改,为了获得更多的赞成票,我们只能通过操纵第三种评审,把赞成票全部投放至第一个服务器,那么第三种评审也一定投出赞成票,此时第一个服务器赞成票最多

所以只要把通过统计1,3两种评审人数,并相加即可

点击查看代码
#include <stdio.h>

int main(){
    int t;
    scanf("%d", &t);
    while(t--){
        int n;
        scanf("%d", &n);
        int reviewer[55];
        int up = 0,down = 0,ne = 0;
        for(int i = 0; i < n; i++){
            scanf("%d", &reviewer[i]);
            if(reviewer[i] == 1)
                up++;
            if(reviewer[i] == 2)
                down++;
            if(reviewer[i] == 3)
                ne++;
        }
        printf("%d\n", up + ne);
    }
    return 0;
}
posted @ 2025-07-08 20:49  sirro1uta  阅读(13)  评论(0)    收藏  举报