• ZZULIOJ 1898: 985的数字难题 【水题】


    1898: 985的数字难题

    Time Limit: 1 Sec  Memory Limit: 128 MB
    Submit: 243  Solved: 78

    Description

    985有n个数,已知每次操作可以将其中不相同的两个数一个加一、一个减一,操作次数不限。
    问他最多可以得到多少个相同的数。

    Input

    第一行输入一个整数t,代表有t组测试数据。
    每组数据占两行,第一行输入一个n代表元素个数,下面一行输入n个整数a[]。
    注:1 <= t <= 30,1 <= n <= 1e4,1 <= a[] <= 1e3。

    Output

    输出一个整数代表最多可以得到多少个相同的数。

    Sample Input

    2
    3
    1 1 1
    2
    2 3

    Sample Output

    3
    1

    HINT

    Source

    hpu

    我想比赛了好久,郁闷,要是n个数加起来可以被n整除,最大就是n个,要是不行不就要在里面n-1、n-2……必超时无疑。但是郁闷的是好久才想到,要是n个数不能变的相同,任意n-1个数都可以利用第n个数变为相同的。。。。。

    #include <cstdio> 
    #include <cstring> 
    #include <stack> 
    #include <queue> 
    #include <algorithm> 
    #include <cmath> 
    #define MAXN 10005 
    using namespace std; 
    const int INF = 0x3f3f3f3f; 
    const double ESP = 1e-5; 
      
    int main() { 
        int t, n, p; 
        scanf("%d", &t); 
        while (t--) { 
            scanf("%d", &n); int sum = 0; 
            for (int i = 0; i < n; i++) { 
                scanf("%d", &p); sum += p; 
            } 
            if (sum%n == 0) printf("%d
    ", n); 
            else printf("%d
    ", n -1); 
        } 
        return 0; 
    }


  • 相关阅读:
    (一)Ionic 项目搭建(参考)
    MySQL安装及常用命令
    (五)vue.js 集成scss(参考)
    (四)vue.js 外部配置文件(参考)
    (三)vue.js api统一管理(参考)
    好玩的折纸效果
    PropTypes没有定义的问题
    border边框设置为1px
    写了一个好玩的弹性列表效果
    H5中的requestAnimationFrame
  • 原文地址:https://www.cnblogs.com/cniwoq/p/6770868.html
Copyright © 2020-2023  润新知