【Codeforces 1038D】Slime
【链接】 我是链接,点我呀:)
【题意】
题意
【题解】
相当于让你确定每个数字前面的系数是-1还是+1
有个结论是这样每次和相邻的减的话,
任何出除了全"-1"和全"+1"之外的其他系数组合都能得到。
分初始的时候每个数字的正负贪心地取一下就好
【代码】
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5;int n;
int a[N+10],mi;
int cntz = 0,cntf = 0;int main(){ios::sync_with_stdio(0),cin.tie(0);cin >> n;for (int i = 1;i <= n;i++){cin >> a[i];if (a[i]>=0) cntz++;else cntf++;}mi = abs(a[1]);for (int i = 1;i <= n;i++){mi = min(abs(a[i]),mi);}if (cntz==n || cntf == n){long long ans = 0;if (n==1){ans = a[1];}else{for (int i = 1;i <= n;i++){ans = ans + abs(a[i]);}ans = ans - mi*2;}cout<<ans<<endl;}else{long long ans = 0;for (int i = 1;i <= n;i++){ans = ans + abs(a[i]);}cout<<ans<<endl;}return 0;
}
转载于:https://www.cnblogs.com/AWCXV/p/10591964.html
【Codeforces 1038D】Slime相关推荐
- 【CodeForces - 618A】Slime Combining(二进制,思维)
题干: Your friend recently gave you some slimes for your birthday. You have n slimes all initially wit ...
- 【CodeForces - 144C】Anagram Search(尺取,滑窗问题,处理字符串计数)
题干: A string t is called an anagram of the string s, if it is possible to rearrange letters in t so ...
- 【CodeForces - 574B】Bear and Three Musketeers (枚举边,思维,优秀暴力)
题干: Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Ri ...
- 【CodeForces - 608C】Chain Reaction (二分 或 dp ,思维)
题干: 题目大意: 题意是在一条直线上坐落着不同位置的灯塔,每一个灯塔有自己的power level,当作是射程范围.现在从最右边的灯塔开始激发,如果左边的灯塔在这个灯塔的范围之内,那么将会被毁灭.否 ...
- 「一题多解」【CodeForces 85D】Sum of Medians(线段树 / 分块)
题目链接 [CodeForces 85D]Sum of Medians 题目大意 实现一个setsetset,支持插入,删除,求∑a5k+3∑a5k+3\sum a_{5k+3}.注意,setsets ...
- 【CodeForces 997C】Sky Full of Stars(组合计数)
题目链接:[CodeForces 997C]Sky Full of Stars 官方题解:Codeforces Round #493 - Editorial 题目大意:有一个n×nn×nn\times ...
- 【codeforces 812C】Sagheer and Nubian Market
[题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...
- 【codeforces 508B】Anton and currency you all know
[题目链接]:http://codeforces.com/contest/508/problem/B [题意] 给你一个奇数; 让你交换一次数字; 使得这个数字变成偶数; 要求偶数要最大; [题解] ...
- 【codeforces 711B】Chris and Magic Square
[题目链接]:http://codeforces.com/contest/711/problem/B [题意] 让你在矩阵中一个空白的地方填上一个正数; 使得这个矩阵两个对角线上的和; 每一行的和,每 ...
最新文章
- 程序员致富的若干方法探讨
- ajax被token拦截,vue中封装ajax请求,并且拦截请求在请求头中添加token
- 【深度学生】使用深度学习阅读和分类扫描文档
- TQ210 —— s5pv210 Linux内核结构
- 2499元起!vivo首款旗舰级平板正式发布 全系标配8GB运行内存
- 2018: 跑图(深搜)
- latex 箭头_Pandoc上手以及如何使得latex文件转换为Docx文件(MAC)
- 排查Linux机器是否已经被入侵
- DevOps实践教程 华为云 系列教程2021 合集
- u盘加密truecrypt_Mac OS X上的TrueCrypt驱动器加密入门
- 什么是ActiveX控件?
- Java-对象转型(casting)
- uva-1600 巡逻机器人
- skipping incompatible xxxx.a when searching for -lxxx问题的解决
- android 友盟统计功能,在Android工程中集成友盟统计
- 图片文字识别,手机里的图片转文字的方法
- macOS10.13如何升级到macOS10.15
- python tokenize_model_python-AttributeError:“令牌生成器”对象在Keras中没有属性“ oov_token”...
- 商业模式新生代_商业模式设计方法视觉化思考——《商业模式新生代》笔记之九...
- 洛谷 P5858 「SWTR-03」Golden Sword