2018.09.23 atcoder Boxes and Candies(贪心)
传送门
一道挺有意思的贪心。
从1到n依次满足条件。
注意要特判第一个数已经大于x的情况。
但是如何贪心吃呢?
如果靠左的数没有越界,我们吃靠右的数。
原因是下一次靠右的数就会成为靠左的数,相当于多贡献了一次。
然后貌似要开long long
代码:
#include<bits/stdc++.h>
#define N 100005
#define ll long long
using namespace std;
ll a[N],x,ans=0;
int n;
inline ll read(){
ll ans=0;
char ch=getchar();
while(!isdigit(ch))ch=getchar();
while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
return ans;
}
int main(){
n=read(),x=read();
for(int i=1;i<=n;++i)a[i]=read();
for(int i=2;i<=n;++i){
if(a[i-1]+a[i]<=x)continue;
if(a[i-1]>=x)ans+=a[i-1]-x+a[i],a[i]=0;
else ans+=a[i]-(x-a[i-1]),a[i]=(x-a[i-1]);
}
cout<<ans;
return 0;
}
2018.09.23 atcoder Boxes and Candies(贪心)的更多相关文章
- 2018.09.16 atcoder Garbage Collector(贪心)
传送门 昨晚打比赛的时候不是很机智啊. 这道题贪心就能过了. 我们可以发现一个明显的结论,每次选的垃圾的距离从大到小排序之后,每个距离对答案的贡献的系数是5,5,7,9,11-也就是最远的是5,其余都 ...
- Boxes and Candies(贪心)
Boxes and Candies Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement Ther ...
- 2018.09.21 atcoder An Invisible Hand(贪心)
传送门 简单贪心啊. 这题显然跟t并没有关系,取差量最大的几组买入卖出就行了. 于是我们统计一下有几组差量是最大的就行了. 代码: #include<bits/stdc++.h> #def ...
- 2018.09.19 atcoder AtCoDeer and Rock-Paper(贪心)
传送门 sb贪心啊. 显然能选帕子就选帕子. 首先假设第一个人全出石头. 考虑把一些石头修改成帕子. 这样贡献只增不减,加起来就是答案. 代码: #include<bits/stdc++.h&g ...
- 2018.09.19 atcoder AtCoDeer and Election Report(贪心)
传送门 很有意思的一道贪心. 就是每次翻最小的倍数来满足条件. 代码: #include<bits/stdc++.h> #define ll long long using namespa ...
- 2018.09.17 atcoder Tak and Hotels(贪心+分块)
传送门 一道有意思的题. 一开始想错了,以为一直lowerlowerlower_boundboundbound就可以解决询问,结果交上去TLE了之后才发现时间复杂度是错的. 但是贪心思想一定是对的,每 ...
- 2018.09.23 bzoj3143: [Hnoi2013]游走(dp+高斯消元)
传送门 显然只需要求出所有边被经过的期望次数,然后贪心把边权小的边定城大的编号. 所以如何求出所有边被经过的期望次数? 显然这只跟边连接的两个点有关. 于是我们只需要求出两个点被经过的期望次数. 对于 ...
- 2018.09.08 AtCoder Beginner Contest 109简要题解
比赛传送门 水题大赛? 全是水题啊!!! T1 ABC333 就是判断是不是两个数都是奇数就行了. 代码: #include<bits/stdc++.h> using namespace ...
- 2018.09.08 NOIP模拟eat(贪心)
签到水题啊... 这题完全跟图论没有关系. 显然如果确定了哪些点会被选之后顺序已经不重要了.于是我们给点按权值排序贪心从大向小选. 我们要求的显然就是∑i(a[i]−(n−i))" role ...
随机推荐
- vue之回车触发表单提交
vue之回车触发表单提交 操作: 在From标签中添加: @keyup.enter.native="handleSubmit" 注意: 1.若添加在Input标签上,只有聚焦在该i ...
- leetcode100
/** * Definition for a binary tree node. * public class TreeNode { * public int val; * public TreeNo ...
- plsql 粘贴
plsql 粘贴
- 调用css文件,进行调色
Title 小米 <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...
- something about facebook token
There are two method origin token , you can use any one of them, first one may be easier. Origin fro ...
- SpringBoot application.yml文件不生效
yml格式对缩进有严格的要求,检查你的yml配置文件是否有不合格的缩进项. 正确的格式如下: server: port: 8881 port前必须有空格, port后的冒号 后面也需要有空格
- Apache Hive 存储方式、压缩格式
简介: Apache hive 存储方式跟压缩格式! 1.Text File hive> create external table tab_textfile ( host string com ...
- linux文件格式转换:<U+FEFF> character showing up in files. How to remove them?
You can easily remove them using vim, here are the steps: 1) In your terminal, open the file using v ...
- 分享 - 27 个机器学习、数学、Python 速查表
转载自:伯乐在线 - iPytLab,原文链接,侵删 机器学习涉及到的方面非常多.当我开始准备复习这些内容的时候,我找到了许多不同的”速查表”, 这些速查表针对某一主题都罗列出了所有我需要知道的知 ...
- Delphi笔记-自定义提示窗口
unit pbHint; interface uses Windows, Controls, Forms, Graphics; type TPBHint=class(THintWindow) //要自 ...