首页 > 其他分享 >Educational Codeforces Round 126 (Rated for Div. 2) C. Water the Trees (从答案方向思考)

Educational Codeforces Round 126 (Rated for Div. 2) C. Water the Trees (从答案方向思考)

时间:2023-01-31 18:14:45浏览次数:76  
标签:Educational Rated return int res Codeforces cnt2 cnt1 const

题目

代码

#include<bits/stdc++.h>
#define debug1(a) cout<<#a<<'='<< a << endl;
#define debug2(a,b) cout<<#a<<" = "<<a<<"  "<<#b<<" = "<<b<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<a<<"  "<<#b<<" = "<<b<<"  "<<#c<<" = "<<c<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<a<<"  "<<#b<<" = "<<b<<"  "<<#c<<" = "<<c<<"  "<<#d<<" = "<<d<<endl;
#define debug5(a,b,c,d,e) cout<<#a<<" = "<<a<<"  "<<#b<<" = "<<b<<"  "<<#c<<" = "<<c<<"  "<<#d<<" = "<<d<<"  "<<#e<<" = "<<e<<endl;
#define endl "\n"
#define fi first
#define se second

#define int long long
//#define int __int128
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;

//#pragma GCC optimize(3,"Ofast","inline")
//#pragma GCC optimize(2)

//常数定义
const double eps = 1e-4;
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int N = 3e5+100;
int a[N];
int n;

int work(int u)
{
    int cnt1 = 0,cnt2 = 0;
    for(int i = 1;i <= n;i ++)
    {
        cnt1 += (u - a[i])&1;
        cnt2 += (u - a[i])>>1;
    }
    if(cnt1 > cnt2)return cnt1*2-1;
    else if(cnt1 == cnt2)return cnt2*2;
    else{
        int res = cnt1*2;
        cnt2 -= cnt1;
        res += cnt2*2/3*2 + ((cnt2*2) % 3);
        return res;
    }
}

void solve() 
{
    cin >> n;
    for(int i = 1;i <= n;i ++)cin >> a[i];

    int mx = *max_element(a+1,a+n+1);
    //debug1(mx);
    cout << min(work(mx),work(mx+1)) << endl;
}

signed main()
{
    
    /*
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    */
    int T = 1;cin >> T;

    while(T--){
        //puts(solve()?"YES":"NO");
        solve();
    }
    return 0;

}
/*

*/

标签:Educational,Rated,return,int,res,Codeforces,cnt2,cnt1,const
From: https://www.cnblogs.com/cfddfc/p/17080100.html

相关文章

  • CodeForces 1762D GCD Queries
    Preface比较神仙的交互题,居然自己胡出来了。不是很建议拿到题直接往题解区冲,这种题做一道少一道。Solution下面简称\(\gcd(p_i,p_j)\)为\(\text{zyf}(i,j)\)。这个......
  • Codeforces Round #847 (Div. 3) E. Vlad and a Pair of Numbers(位运算)
    https://codeforces.com/contest/1790/problem/E题目大意:两个正数a和b(a,b>0)。a⊕b=(a+b)/2,a⊕b==x。找到任何合适的a和b,或者不存在"-1"。inputCopy62510......
  • Codeforces Round #846 (Div. 2) 解题报告
    前情提要:我是沙币比赛链接A.Hayatoand贪心,不大想讲代码写的很丑voidsolve(){ vector<int>a; intn,x; cin>>n; a.push_back(0); for(inti=1;i<=n;++i)......
  • TypeDB Forces 2023 (Div. 1 + Div. 2, Rated, Prizes!)(持续更新)
    Preface猜结论场,很久没打比赛了然后赛前和ztc吹牛说每次隔一段时间来打CF就会有强运加持结果好家伙BCE全部秒出结论(而且我比赛时都证不来),而且写的A~E都是一发入魂凭借这......
  • Codeforces Global Round 2
    A  题解:枚举每个颜色的头和尾然后最大化另一端upd:赛时麻烦了,显然答案的一端为头或者尾,枚举另一端即可。#include<bits/stdc++.h>usingnamespacestd;typed......
  • 1.30 vp Codeforces Round #846 (Div. 2)
    A-HayatoandSchool、题意给出长度为n的序列a,要求判断是否存在三个数之和为奇数,若有则输出YES且输出这三个数的下标,否则输出NO思路数字和为奇数的情况只有奇+偶,......
  • CF1787H Codeforces Scoreboard 题解
    鬼知道怎么会撞题的,甚至是没听过的OJ。首先不考虑对\(a_i\)取\(\max\),显然直接按照\(k\)降序排序最优。接下来考虑\(a_i\)的限制,如果取到了\(a_i\)一定放在最......
  • 1.29 vp Educational Codeforces Round 142 (Rated for Div. 2)
    A-GamingForces题意有n只怪兽,每个怪的血量是\(a_i\),有两种操作:1.直接消灭这只怪2.消灭两只血量为1的怪问最少需要多少次操作可以将怪全部杀死思路可以想到,操作二......
  • Codeforces Round #844 (Div. 1 + Div. 2, based on VK Cup 2022 - Elimination Roun
    CodeforcesRound#844(Div.1+Div.2,basedonVKCup2022-EliminationRound)[A-D]AParallelProjectionstandardinput/output1s,512MBBGoingt......
  • Codeforces Round #846 (Div. 2) B. GCD Partition
    B.GCDPartition参考题解链接:CodeforcesRound#846(Div.2)—Tutorial-Codeforces题意:给一个长度为n的序列,并将其分成连续的k块(k>1),得到序列......