1 条题解

  • 0
    @ 2026-9-30 12:59:26

    C++ :

    
    #include <cstdio>
    #include <algorithm>
    using namespace std;
    static int a[105];
    /* 赢超过一半的州 ⇒ need = m/2+1 个州;每州需超过一半选民 ⇒ v/2+1 人。
       取选民数最少的 need 个州。 */
    int main(){
        int T;
        if(scanf("%d", &T) != 1) return 0;
        while(T--){
            int m;
            if(scanf("%d", &m) != 1) break;
            for(int i = 0; i < m; i++) scanf("%d", &a[i]);
            sort(a, a + m);
            int need = m / 2 + 1;
            long long ans = 0;
            for(int i = 0; i < need; i++) ans += a[i] / 2 + 1;
            printf("%lld\n", ans);
        }
        return 0;
    }
    
    
    • 1

    信息

    ID
    2856
    时间
    1000ms
    内存
    256MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者