Codeforces Round #575 (Div. 3) (A. Three Piles of Candies)(数学)

A. Three Piles of Candies
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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 q 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 q (1≤q≤1000) — the number of queries. Then q queries follow.

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

Output
Print q lines. The i-th line should contain the answer for the i-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).

Example
inputCopy
4
1 3 4
1 10 100
10000000000000000 10000000000000000 10000000000000000
23 34 45
outputCopy
4
55
15000000000000000
51

题意:

思路:

不难得到最后的最有答案一定是(a+b+c)/2

细节见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
ll a[5];
int main()
{
    //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
    //freopen("D:\\common_text\code_stream\\out.txt","w",stdout);

    int q;
    cin>>q;

    while(q--)
    {
        repd(i,1,3)
        {
            cin>>a[i];
        }
        sort(a+1,a+1+3);
        ll x=a[1];
        ll y=a[2];
        ll z=(a[3]-(a[2]-a[1]));
        if(a[3]>a[2]-a[1])
        {
            x=a[2];
            x+=z/2;
            y+=z/2;
        }else
        {
            x+=a[3];
        }
        cout<<min(x,y)<<endl;
    }

    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}
 

原文地址:https://www.cnblogs.com/qieqiemin/p/11247850.html

时间: 2024-10-09 08:57:48

Codeforces Round #575 (Div. 3) (A. Three Piles of Candies)(数学)的相关文章

Codeforces Round #575 (Div. 3) D1. RGB Substring (easy version)

Codeforces Round #575 (Div. 3) D1 - RGB Substring (easy version) The only difference between easy and hard versions is the size of the input. You are given a string s consisting of n characters, each character is 'R', 'G' or 'B'. You are also given a

Codeforces Round #575 (Div. 3)记录

Codeforces Round #575 (Div. 3)记录 错过了上分的机会,上次不小心打了个div. 2结果直接掉了100多分. 我绿了,也变弱了.找下场Div. 3上上分吧. A 随便写了. 我的思路是三个东西先排序,一个人先拿最少的,另一个人拿次少的. 然后看剩下的能不能填补相差,如果能的话继续左右两边各补,补到剩1或0为止. 其实上面说这么多,答案就等于\(\lfloor \frac{a+b+c}{2} \rfloor\). 我是sb B 这些数与大小无关,我们直接统计有多少个奇数

Codeforces Round #575 (Div. 3)

本蒟蒻已经掉到灰名了(菜到落泪),希望这次打完能重回绿名吧...... 这次赛中A了三题 下面是本蒟蒻的题解 A.Three Piles of Candies 这题没啥好说的,相加除2就完事了 #include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll q; scanf("%lld",&q); while(q--) { ll a,b,c; scanf("

Codeforces Round #140 (Div. 1) Naughty Stone Piles 贪心

#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; const int maxn = 1000010; __int64 sum[maxn] ; __int64 num[maxn]; __int64 ans[maxn]; __int64 vis[maxn] ; __int64 qu

【Codeforces Round #575 (Div. 3) 】 RGB Substring (hard version) ( FFT)

D2. RGB Substring (hard version) time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The only difference between easy and hard versions is the size of the input. You are given a string ss cons

Codeforces Round #575 (Div. 3) C. Robot Breakout (模拟,实现)

C. Robot Breakout time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output n robots have escaped from your laboratory! You have to find them as soon as possible, because these robots are experimental,

Codeforces Round #575 (Div. 3) B. Odd Sum Segments (构造,数学)

B. Odd Sum Segments time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output You are given an array a consisting of n integers a1,a2,-,an. You want to split it into exactly k non-empty non-intersecting

Codeforces Round #575 (Div. 3) D2. RGB Substring (hard version)

传送门 题意: 给你一个长为n的仅由'R','G','B'构成的字符串s,你需要在其中找出来一个子串.使得这个子串在“RGBRGBRGBRGB........(以RGB为循环节,我们称这个串为str)”里面也是一个子串,这个子串的长度是k 可是有可能s字符串中找不到,那么这个时候就可以改变s字符串中某些位置的字母来完成任务.问最少需要改变多少个字母 题解: 主要看暴力的姿势对不对.在上一道的D1上面,我是对s字符串的每一个位置进行‘R’,‘G’,‘B’的枚举,因为如果这个子串也是str的子串的话

Codeforces Round #426 (Div. 1) A.The Meaningless Game (二分+数学)

题目链接: http://codeforces.com/problemset/problem/833/A 题意: 给你 \(a\) 和 \(b\),两个人初始化为 \(1\).两个人其中一方乘以 \(k^2\),另一方就乘以 \(k\).问你能不能达到 \((a,b)\) 这个最终状态. 题解: 设 \(X\), \(P\) 表示两个乘积的集合. 那么,显然: \(S^{2}*P=a\) ------ 1 \(S*P^{2}=b\) ------ 2 所以:\(a*b = S^{3}*P^3\)