Codeforces Round #775 (Div. 2) B. Game of Ball Passing - 思维

 

 

 

【题意】:

  有 n 个队员 , 玩了好久后统计他们传球的次数。 第 i 个队员传了 a【 i 】 次球 。 问 最少应该玩了几轮  。

【思路】:

  记录踢得最多的一个球员。 记录除了这个球员的其他人踢得总和。  

  如果 踢得最多的那个人比其他人加起来都多,那么就要踢 (max-sum)轮 。

  如果 踢得最多的人小于其他人的和 , 那么 其他人相互踢,将和减少到 max 。 就能跟max一起踢 只用玩一轮了。

【代码】:

  

#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <set>

#define ms(a, b) memset(a,b,sizeof(a))
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define rep(i, a, b)  for(ll i=a;i<=b;i++)
#define lep(i, a, b)  for(ll i=a;i>=b;i--)
#define endl '\n'
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi  vector<ll>
#define vpi vector<pii>
#define vpl vector<pll>
#define mi  map<ll,ll>
#define all(a)  (a).begin(),(a).end()
#define gcd __gcd
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound

#define ff first
#define ss second
#define test4(x, y, z, a) cout<<"x is "<<x<<"        y is "<<y<<"        z is "<<z<<"        a is "<<a<<endl;
#define test3(x, y, z) cout<<"x is "<<x<<"        y is "<<y<<"        z is "<<z<<endl;
#define test2(x, y) cout<<"x is "<<x<<"        y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
using namespace std;
const int N = 100010;
const int maxx = 0x3f3f3f;
const int mod = 1e9 + 7;
const int minn = -0x3f3f3f;
const int M = 2 * N;
ll T, n, m;
ll sum;
ll a[N];
void solve() {
    cin>>n;
    sum=0;
    rep(i,1,n){
        cin>>a[i];
        sum+=a[i];
    }
    int f=0;
    rep(i,1,n){
        if ( a[i]!=0)   {f=1;break;}
    }
    if ( f==0 ) {cout<<0<<endl;return ;}
    sort(a+1,a+1+n);
    cout<<max( 1ll , 2*a[n] - sum )<<endl;
}

int main() {
    fast;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}
View Code

 

posted @ 2022-03-16 15:09  Pan_c  阅读(128)  评论(0)    收藏  举报