Slime CodeForces - 1038D

1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 #include<algorithm>
5 #include<bitset>
6 #include<cassert>
7 #include<cctype>
8 #include<cmath>
9 #include<cstdlib>
10 #include<ctime>
11 #include<deque>
12 #include<iomanip>
13 #include<list>
14 #include<map>
15 #include<queue>
16 #include<set>
17 #include<stack>
18 #include<vector>
19 #include <vector>
20 #include <iterator>
21 #include <utility>
22 #include <sstream>
23 #include <limits>
24 #include <numeric>
25 #include <functional>
26 using namespace std;
27 #define gc getchar()
28 #define mem(a) memset(a,0,sizeof(a))
29 //#define sort(a,n,int) sort(a,a+n,less<int>())
30
31 #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
32
33 typedef long long ll;
34 typedef unsigned long long ull;
35 typedef long double ld;
36 typedef pair<int,int> pii;
37 typedef char ch;
38 typedef double db;
39
40 const double PI=acos(-1.0);
41 const double eps=1e-6;
42 const ll mod=1e9+7;
43 const int inf=0x3f3f3f3f;
44 const int maxn=1e5+10;
45 const int maxm=100+10;
46
47
48 bool compare(int a, int b)
49 {
50 return a < b;//升序
51 }
52
53 int num[500000] = {0};
54 int main()
55 {
56 int n = 0;
57 cin >> n;
58 if(n == 1){
59 cin >> num[0];
60 cout<< num[0];
61 return 0;
62 }
63 ll sum = 0;
64 bool flag_n = 0 , flag_p = 0;
65 for(int i = 0;i<n;i++)
66 {
67 cin >> num[i];
68 sum += abs(num[i]);
69 if(num[i] < 0) flag_n = 1;
70 else flag_p = 1;
71 }
72
73 ll ans = 0;
74 if(flag_n && flag_p)
75 {
76 ans = sum;
77 }
78 else
79 {
80 for(int i = 1;i<n;i++)
81 {
82 ans = max(ans , sum - abs(num[i]) - abs(num[i-1]) + abs(num[i]-num[i-1]));
83 }
84 }
85 cout << ans;
86 return 0;
87 }
Slime CodeForces - 1038D的更多相关文章
- Codeforces 1038D - Slime - [思维题][DP]
题目链接:http://codeforces.com/problemset/problem/1038/D 题意: 给出 $n$ 个史莱姆,每个史莱姆有一个价值 $a[i]$,一个史莱姆可以吃掉相邻的史 ...
- 【Codeforces 1038D】Slime
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 相当于让你确定每个数字前面的系数是-1还是+1 有个结论是这样每次和相邻的减的话, 任何出除了全"-1"和全"+ ...
- CodeForces - 1038D (线性DP)
题目:https://codeforces.com/problemset/problem/1038/D 题意:给你n个数字,每个数字可以吃左右两边的数,然后吃完后自己变成 a[i]-a[i+1]或者a ...
- Codeforces Round #508 (Div. 2) D. Slime
D. Slime 题目链接:https://codeforces.com/contest/1038/problem/D 题意: 给出两个数,然后每次可以对相邻的两个数合并,比如x,y,那么合并过后就是 ...
- CodeForces 618A Slime Combining
http://www.codeforces.com/contest/618/problem/A 明明觉得是水题,而我却做了一个小时. 明明觉得代码没有错,而我却错了好几次. 因为我的名字不叫明明,也不 ...
- Codeforces 1038 D. Slime
[传送门] 其实就是这些数字前面能加正负号,在满足正负号均出现的情况下价值最大.那么就可以无脑DP$f[i][j][k]$表示到了第$i$位,正号是否出现($j$.$k$为$0$或$1$)能得到的最大 ...
- [题解] Codeforces 1349 D Slime and Biscuits 概率,推式子,DP,解方程
题目 神题.很多东西都不知道是怎么凑出来的,随意设置几个变量,之间就产生了密切的关系.下次碰到这种题应该还是不会做罢. 令\(E_x\)为最后结束时所有的饼干都在第x个人手中的概率*时间的和.\(an ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
随机推荐
- WebSocket 与 SSE 对比:即时通信的选择(一)
在现代 Web 开发中,实时通信需求越来越多,比如聊天应用.实时通知.直播弹幕.股票行情推送等.实现这些需求的常见技术有 WebSocket 和 SSE(Server-Sent Events),但它们 ...
- 未来已来?vSphere 9 预览版部署体验
最近看到不少技术爱好者开始分享 vSphere 9 的基础体验镜像,作为 VMware 的忠实粉丝,怎么能错过这波"尝鲜"机会呢? 趁着空闲时间,我也动手安装体验了一下.从初步使用 ...
- 「Note」数论方向 - 组合数学
1. 容斥原理 1.1 介绍 解决集合内计数问题. \(S\) 为集合编号集合. \[\left | \bigcup_{i\in S}A_i \right | =\sum_{T\subseteq S\ ...
- Django2.2版本迁移数据库报错问题解决方案
在迁移的时候系统会抛出异常,提示我们安装mysqlclient. 这时候我们可以使用pymysql进行伪装,在项目的__init__.py中添加如下代码即可.(如果是2.2以前的版本) import ...
- 我做了个 AI 高考分数预测器,这次终于能上清华了!
马上高考了,可惜我今年有事情参加不了了,就帮帮广大考生朋友们,送大家一个我自己做的高考神器吧! 铛铛铛铛,就是这个 高考分数预测器! 体验地址:https://gaokao.codefather.cn ...
- java实现linux文件的解压缩(确保md5sum一致)
package com.xlkh.device.utils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java. ...
- 构建基于Serverless架构的向量检索MCP Server
构建基于Serverless架构的向量检索MCP Server 随着LLM与Agent的快速发展,向量检索成为构建高效语义搜索和智能推荐系统的关键技术之一.OpenSearch Service 作为一 ...
- 花150元,我用 AI 做出了千万播放的爆款视频!保姆级教程+完整提示词
大家好,我是程序员鱼皮.这两天正在研究 怎么切显卡,只切贵的,不切对的: 我是怎么做到的呢?下面会分享. 这段时间,网上出现了很多利用 AI 制作 ASMR 视频的博主,其中比较有代表性的一位,几天的 ...
- 计蒜客 A2285 / 2019ICPC徐州 H - Yuuki and a problem
右转学倍增值域分块 直接在神秘数的做法上大力树套树是 naive 的,考虑将值域分块的做法代入优化. 对于一个块 \([2^{k}, 2^{k+1})\) 内最小的数 \(m\),如果当前可以表示出的 ...
- VUE3.0 路由(routes) createWebHistory和createWebHashHistory
createWebHistory路由模式路径不带#号(生产环境下不能直接访问项目,需要nginx转发) http://localhost:8080/#/ const router = createRo ...