Codeforces Round #451 (Div. 2)
来源:互联网 发布:一般约束的最优化问题 编辑:程序博客网 时间:2024/06/15 18:46
题意:
让这些数平均分成2堆,一堆平方数,一堆不是。输出最小的变化。
POINT:
【平方数】变【不是平方数】,除了0,都知道+1就行。0要+2,特殊考虑。
【不是平方数】变【平方数】,上下比较取小。
然后换一换就行。
唯一的坑点是long long。作为E题也太简单了。
#include <iostream>#include <stdio.h>#include <math.h>#include <algorithm>using namespace std;#define LL long longconst LL maxn = 200000+444;LL besq[maxn];int main(){LL n;scanf("%lld",&n);n=n/2;LL zero=0;LL cnt=0;LL sq=0;LL fsq=0;for(LL i=1;i<=2*n;i++){LL a;scanf("%lld",&a);LL b=(LL)(sqrt(a));if(b*b==a){sq++;}else{LL now=min(a-b*b,(b+1)*(b+1)-a);besq[++cnt]=now;fsq++;}if(a==0){zero++;}}if(sq<n){sort(besq+1,besq+1+cnt);LL ans=0;for(LL i=1;i<=n-sq;i++){ans+=besq[i];}printf("%lld\n",ans);}else if(sq==n){printf("0\n");}else{LL now=sq-zero;if(sq-n<now){printf("%lld\n",sq-n);}else{printf("%lld\n",now+(sq-n-now)*2);}}return 0;}
阅读全文
0 0
- Codeforces Round #451 (Div. 2)
- Codeforces Round #451 (Div. 2)
- Codeforces Round #451 (Div. 2)
- Codeforces Round #451 (Div. 2)
- Codeforces Round #451 (Div. 2)
- Codeforces Round #451 (Div. 2)
- Codeforces Round #451 (Div. 2)
- Codeforces Round #451 (Div. 2)
- Codeforces Round #451 (Div. 2) A. Rounding
- codeforces Round #451 (Div. 2) Phone Numbers
- Codeforces Round #451 (Div. 2) a
- Codeforces Round #451 (Div. 2) A-B
- Codeforces Round #451 (Div. 2)题解
- Codeforces Round #451 (Div. 2) C
- Codeforces Round #451 (Div. 2) E
- Codeforces Round #451 (Div. 2) D
- Codeforces Round #451 (Div. 2) C
- Codeforces Round #451 (Div. 2) B
- 梯度下降算法数据的标准化预处理
- Java序列化的作用和反序列化
- JAVA的Date类
- HTTP 协议的理解
- bzoj 2744: [HEOI2012]朋友圈 最大团
- Codeforces Round #451 (Div. 2)
- 代码规范 : 高质量的子程序设计(函数)
- IT风投及其在中国发展情况
- 2017-12-21 作业3
- JSONP
- Java 8 Optional的正确姿势
- Samba服务的username map script的漏洞相关信息
- Java中hashCode的作用
- 开闭原则