练习codeforces1196

题目如下
A. Three Piles of Candies
time limit per test1 second
memory limit per test256 megabytes
Alice and Bob have received three big piles of candies as a gift. Now they want to divide these candies as fair as possible. To do this, Alice takes one pile of candies, then Bob takes one of the other two piles. The last pile is split between Alice and Bob as they want: for example, it is possible that Alice takes the whole pile, and Bob gets nothing from it.

After taking the candies from the piles, if Alice has more candies than Bob, she discards some candies so that the number of candies she has is equal to the number of candies Bob has. Of course, Bob does the same if he has more candies.

Alice and Bob want to have as many candies as possible, and they plan the process of dividing candies accordingly. Please calculate the maximum number of candies Alice can have after this division process (of course, Bob will have the same number of candies).

You have to answer 𝑞 independent queries.

Let's see the following example: [1,3,4]. Then Alice can choose the third pile, Bob can take the second pile, and then the only candy from the first pile goes to Bob — then Alice has 4 candies, and Bob has 4 candies.

Another example is [1,10,100]. Then Alice can choose the second pile, Bob can choose the first pile, and candies from the third pile can be divided in such a way that Bob takes 54 candies, and Alice takes 46 candies. Now Bob has 55 candies, and Alice has 56 candies, so she has to discard one candy — and after that, she has 55 candies too.

Input
The first line of the input contains one integer 𝑞 (1≤𝑞≤1000) — the number of queries. Then 𝑞 queries follow.

The only line of the query contains three integers 𝑎,𝑏 and 𝑐 (1≤𝑎,𝑏,𝑐≤1016) — the number of candies in the first, second and third piles correspondingly.

Output
Print 𝑞 lines. The 𝑖-th line should contain the answer for the 𝑖-th query — the maximum number of candies Alice can have after the division, if both Alice and Bob act optimally (of course, Bob will have the same number of candies).
题目大意
有如下三对糖果,有两个来分,每个人各先选择一对,然后再对剩下一堆进行分配,每个人可以丢弃糖果,最后使得两个人能够拥有最多并且数量相同的糖果

题目分析
题目很长,但是,底层逻辑,就是把三堆平均分给两个人,只要两个人先选最少的两队堆,剩下一堆再进行分配,一定能获得最多且数量相同的糖果
所以,只要三堆的糖果加起来除以二即可
完整代码

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

int main(){
    int t;
    scanf("%d",&t);
    while (t--){
        unsigned long long a, b, c;
        scanf(" %llu %llu %llu ",&a, &b, &c);
        printf("%llu\n",(a + b + c) / 2);
    }
    return 0;
}
posted @ 2025-07-06 21:57  sirro1uta  阅读(14)  评论(0)    收藏  举报