CF - 246 - B. Increase and Decrease(贪心)
来源:互联网 发布:setscale java 编辑:程序博客网 时间:2024/05/22 02:00
题意:一个长为 n (1 ≤ n ≤ 10^5)的序列(元素(|ai| ≤ 10^4) ),可以取其中的两个数,一个数 + 1,另一个数就 - 1,可以这样操作无数次,问最后最多能有多少个数是一样的。
题目链接:http://codeforces.com/problemset/problem/246/B
——>>我觉得非常不错的题目,至少我被坑得团团转。。
第一种惯性思维:尽量地往平均数靠,答案为 n - 余数。。可惜,是错的。。
第二种惯性改进思维:尽量地往平均数靠,答案为 max(n - 余数, 余数)。。可惜,还是错的。。
贪心正解:无论数有多大,我都可以让 n - 1 个数变成 1,让第 n 个数独树一帜。。所以,答案的最小值为 n - 1。。
当总和能被 n 整除,可以平分 n 数时,答案为 n 。。
#include <cstdio>int main(){ int n, a; while (scanf("%d", &n) == 1) { int sum = 0; for (int i = 1; i <= n; ++i) { scanf("%d", &a); sum += a; } sum % n == 0 ? printf("%d\n", n) : printf("%d\n", n - 1); } return 0;}
1 0
- CF - 246 - B. Increase and Decrease(贪心)
- B. Increase and Decrease
- CodeForces - 246B Increase and Decrease (模拟)水
- Increase and Decrease--codeForces 246B
- CodeForces 246B: Increase and Decrease【水】
- Codeforces 246B Increase and Decrease 【数学】
- Codeforces 246B-Increase and Decrease【模拟】
- CodeForces 246B Increase and Decrease
- Codeforces 246B Increase and Decrease
- 【Codeforces 246B Increase and Decrease 】
- CodeForces 246BB. Increase and Decrease【思维】
- Increase and Decrease
- Increase and Decrease
- CUIT ACM Personal Training 11.27(FM)G - Increase and Decrease
- CF - 389 - B. Fox and Cross(贪心)
- cf 342B - Xenia and Spies(贪心)
- CF 557B(Pasha and Tea-贪心)
- CF#321-B - Kefa and Company-贪心-
- 欧拉环、欧拉路径的判定和求法
- HomeHttp 是一个免费的网站反向代理服务
- accept是又产生一个Socket端口吗?
- 树形DP 2013多校8(Terrorist’s destroy HDU4679)
- 浅析Buffer Cache
- CF - 246 - B. Increase and Decrease(贪心)
- Poj 3254 Corn Fields(状态压缩)
- 卡片式UI的总结 android
- 第十一周项目6 (4)输入一个数,输出这个数以内的所有回文素数
- 第一天
- 不确定水平滚动条的循环滚动的实现。
- HDU1824-Let's go home(2-SAT)
- Mac 10.10 安装nginx
- android开发规范