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

题意:给定n个数a[i],分别表示长度为2i-1的木条的数量,问使用这些木条最多能构成多少三角形。

思路:简单分析后可以发现能构成三角形的组合只能是(i,j,j) (i<=j)。利用贪心的思想,从j=0到n-1依次处理,处理j时,优先考虑(i,j,j) (i<j)的情况,然后考虑(j,j,j)的情况。

AC代码:

 #include<bits/stdc++.h>
using namespace std; typedef long long LL;
int n;
LL pre,nw,ans; int main(){
scanf("%d",&n);
for(int i=;i<n;++i){
scanf("%lld",&nw);
LL t=min(pre,nw>>);
nw-=t<<;
pre-=t;
ans+=t;
ans+=(nw/);
nw%=;
pre+=nw;
}
printf("%lld\n",ans);
return ;
}

cf-Global Round2-E. Pavel and Triangles的更多相关文章

  1. Codeforces 1119E Pavel and Triangles (贪心)

    Codeforces Global Round 2 题目链接: E. Pavel and Triangles Pavel has several sticks with lengths equal t ...

  2. E. Pavel and Triangles dp+问题转化

    E. Pavel and Triangles dp+问题转化 题意 给出n种线段,每种线段给出一定数量,其中每个线段都是 \(2^k\) 问最多能组成多少个三角形 思路 因为每个是\(2^k\)所以能 ...

  3. Codeforces Global Round 2 E. Pavel and Triangles(思维+DP)

    题目链接:https://codeforces.com/contest/1119/problem/E 题意:有n种长度的棍子,有a_i根2^i长度的棍子,问最多可以组成多少个三角形 题解:dp[i]表 ...

  4. [题解向] CF#Global Round 1の题解(A $\to$ G)

    这里是总链接\(Link\). \(A\) 题意:求\(\sum_{i=1}^{k} a_i\times b^{k-i}\)的奇偶性, \(k = \Theta(n \log n)\) --其实很容易 ...

  5. 【CF1119E】Pavel and Triangles

    题目大意:有 N 种长度的边,第 i 种长度为 \(2^i\),给定一些数量的这些边,问最多可以组合出多少种三角形. 题解:应该是用贪心求解,不过选择什么样的贪心策略很关键. 首先分析可知,两个较大边 ...

  6. CF Global Round 21 题解 (CDEG)

    C 把 \(a,b\) 全拆开然后比较即可(因为分裂和合并是互逆的) 注意开 long long . using namespace std; typedef long long ll; typede ...

  7. Codeforces Global Round 2 题解

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

  8. 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-> ...

  9. CF1119 Global Round 2

    CF1119A Ilya and a Colorful Walk 这题二分是假的.. \(1,2,1,2,1\) 有间隔为 \(3\) 的,但没有间隔为 \(2\) 的.开始被 \(hack\) 了一 ...

随机推荐

  1. PowerDesigner 把Comment写到name中 和把name写到Comment中 pd7以后版本可用

    在使用PowerDesigner对数据库进行概念模型和物理模型设计时,一般在NAME或Comment中写中文,在Code中写英文.Name用来显 示,Code在代码中使用,但Comment中的文字会保 ...

  2. VirtualBox配置

    安装增强工具:http://mikemainguy.blogspot.jp/2015/03/installing-virtualbox-guest-additions.html 安装ssh:https ...

  3. css样式表2

    <head> <style type="text/css"> .main { height:42px; width:100%; text-align:cen ...

  4. NSTimer内存泄漏

    用NSTimer调用 timer = [NSTimer scheduledTimerWithTimeInterval:timerInterval target:self selector:@selec ...

  5. 1047B_Cover Points

    B. Cover Points time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  6. jvm问题

     问题: 1. 一台服务器,部署多个服务,请问,这多个服务,对应的是一个jvm,还是多个jvm? 2. 一个线程,从controller 到 service,到DAO,会调用多个方法,请问是 对应一个 ...

  7. Seaweed-FS综合使用测试(转)

    2016-03-16 12:17:48   Seaweed-FS综合使用测试 参考信息 https://github.com/chrislusf/seaweedfs/ https://bintray. ...

  8. ZEOSDBO-7安装

    zeosdbo是一套免费开源的Delphi数据库连接组件,可连接mssql.mysql.sybase.oracle.firebird.sqlite.postgresql等多种数据库.调用方法简单. 连 ...

  9. 【动态规划】最大子段和问题,最大子矩阵和问题,最大m子段和问题

    http://blog.csdn.net/liufeng_king/article/details/8632430 1.最大子段和问题      问题定义:对于给定序列a1,a2,a3……an,寻找它 ...

  10. php面向对象 封装继承多态 接口、重载、抽象类、最终类总结

    1.面向对象 封装继承多态  接口.重载.抽象类.最终类 面向对象 封装继承多态  首先,在解释面向对象之前先解释下什么是面向对象? [面向对象]1.什么是类? 具有相同属性(特征)和方法(行为)的一 ...