题目链接:https://codeforces.com/contest/1119/problem/E

题意:有n种长度的棍子,有a_i根2^i长度的棍子,问最多可以组成多少个三角形

题解:dp[i]表示前 i 种棍子可以组成的最大三角形数量,f[i]表示没有用到的棍子数量,三角形的形状只有两种(2 ^ i, 2 ^ i, 2 ^ i)或者(2 ^ i, 2 ^ i, 2 ^ j),显然先用之前剩下的来组三角形最优,然后就可以转移了。

 #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pi acos(-1)
#define pii pair<int,int>
#define pb push_back
#define lowbit(x) ((x)&(-x))
const int INF = 0x3f3f3f3f;
const double eps = 1e-;
const int maxn = 3e5 + ;
const int maxm = 1e6 + ;
const ll mod = ; int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
int n;
cin >> n;
ll res = , ans = ;
for(int i = ; i < n; i++) {
ll a;
cin >> a;
ll mn = min(res, a / );
res -= mn, a -= * mn;
ans += mn + a / ;
a %= ;
res += a;
}
cout << ans << endl;
return ;
}

Codeforces Global Round 2 E. Pavel and Triangles(思维+DP)的更多相关文章

  1. Codeforces Global Round 2 题解

    Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...

  2. CodeForces Global Round 1

    CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...

  3. Codeforces Global Round 1 - D. Jongmah(动态规划)

    Problem   Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...

  4. Codeforces Global Round 1 (A-E题解)

    Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...

  5. Codeforces Global Round 3

    Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...

  6. Codeforces Global Round 1 (CF1110) (未完结,只有 A-F)

    Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补 ...

  7. 【手抖康复训练1 】Codeforces Global Round 6

    [手抖康复训练1 ]Codeforces Global Round 6 总结:不想复习随意打的一场,比赛开始就是熟悉的N分钟进不去时间,2333,太久没写题的后果就是:A 题手抖过不了样例 B题秒出思 ...

  8. Codeforces Global Round 11 个人题解(B题)

    Codeforces Global Round 11 1427A. Avoiding Zero 题目链接:click here 待补 1427B. Chess Cheater 题目链接:click h ...

  9. Codeforces Global Round 2 Solution

    这场题目设置有点问题啊,难度:Div.2 A->Div.2 B->Div.2 D->Div.2 C->Div.2 D->Div.1 D-> Div.1 E-> ...

随机推荐

  1. LeetCode 70. 爬楼梯(Climbing Stairs)

    70. 爬楼梯 70. Climbing Stairs 题目描述 假设你正在爬楼梯.需要 n 阶你才能到达楼顶. 每次你可以爬 1 或 2 个台阶.你有多少种不同的方法可以爬到楼顶呢? 注意: 给定 ...

  2. GraphHopper-初识

    GraphHopper  GraphHopper is a fast and Open Source road routing engine.   Is fast and memory efficie ...

  3. 在CentOS7 安装 Redis数据库

    环境说明: 名称 版本 CentOS CentOS Linux release 7.4.1708 (Core) VMware Fusion 专业版 10.1.1 (7520154) SSH Shell ...

  4. 简单实现SpringBoot启动

    一.准备: IDEA 使用简单手写导包实现spring boot,未使用idea自带的spring创建方法 可以更加简单理解springboot启动过程 二.开始 1.打开idea创建project ...

  5. Python27之集合

    集合说:“在我的世界里,你就是唯一” 一.集合的概念和使用 集合的概念和数学里数学里集合的概念是一致的,都是一组元素的集,且元素之间不能重复.元素必须是不可变的数据类型,例如元组也可以作为其中的一个元 ...

  6. 第五章 模块之random 、hashlib、time /datetime

    5.2 random 返回随机生成的一个实数 random.randint() 返回随机生成的一个实数 import random #调用模块​def get_random_code(length=6 ...

  7. python + pyinstaller 实现将python程序打包成exe文件直接运行

    pyinstaller 我们在平常学习使用python的时候经常会自己编写一些小程序来使用,虽然python是跨平台的语言,但是如果我们想要在一个没有python以及很多库环境的电脑上使用我们的小程序 ...

  8. golang 切片使用注意事项

    // list 默认值为nil,可以直接append值,有值后json后为数组对象,但如果没有初始化空间的话,json编码后为null var list []*Pepole // list 初始化空间 ...

  9. 数据备份 及 Python 操作 Mysql

    一 MySQL数据备份 #1. 物理备份: 直接复制数据库文件,适用于大型数据库环境.但不能恢复到异构系统中如Windows. #2. 逻辑备份: 备份的是建表.建库.插入等操作所执行SQL语句,适用 ...

  10. Java构建器(多个构造器参数)

    今天看netty权威指南,第一次听说构建器,百度了几个博客,但是并没有通俗易懂一点儿的,综合别人的博客,总结如下: 1. 构建器是什么? 当创建对象需要传入多个参数的时候我们通常会根据参数的数量写不同 ...