题目链接: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. DataBinding(二):DataBinding的基本用法

    转自:DataBinding系列(二):DataBinding的基本用法 1.在xml中引入一些基础变量Variables data 标签中可以有任意数量的 variable 标签.这些变量可以使Ja ...

  2. koltin语言学习(一)——什么是koltin

    转自:Koltin China (一) 介绍 #Kotlin-for-Android-Dev 1. 什么是Kotlin? Kotlin是JetBrains开发的基于JVM的语言.Kotlin是使用Ja ...

  3. Linux FACL(文件访问控制列表)

    文件有三种权限 属主权限   属组权限  其他权限 现在有这样一个场景,用户 A 想把文件共享给不是同组内用户 B ,而又不想修改其他权限,这时候 FACL 就起作用了 FACL可以给文件添加一个拓展 ...

  4. 讲讲亿级PV的负载均衡架构

    引言 本来没想写这个题材的,为了某某童鞋能够更好的茁壮成长,临时写一篇负载均衡的.负载均衡,大家可能听过什么3层负载均衡.4层负载均衡.7层负载均衡什么的?那这是怎么分的呢,ok,是根据osi七层网络 ...

  5. Redis命令操作详解

    一.key pattern 查询相应的key (1)redis允许模糊查询key 有3个通配符  *.?.[] (2)randomkey:返回随机key (3)type key:返回key存储的类型 ...

  6. SPring cloud (3)A Ribbon 负载均衡 配置初步

    1.引用pom <dependency> <groupId>org.springframework.cloud</groupId> <artifactId&g ...

  7. centos如何安装tomcat

    1 通过 SecureCRT 连接到阿里云 CentOS7 服务器; 2 进入到目录 /usr/local/ 中: cd /usr/local/ 3 创建目录 /usr/local/tools,如果有 ...

  8. sql 日期格式

    select CONVERT(varchar(10), getDate(),121) --不要时间2002-01-01 select CONVERT(varchar(10), getDate(),12 ...

  9. 固定顶部指定div不滑动

    .fixed_div { position:fixed; z-index:100; top: 45px; width:100%; height:45px; } 指定div设置属性position:fi ...

  10. 2018SDIBT_国庆个人第二场

    A.codeforces1038A You are given a string ss of length nn, which consists only of the first kk letter ...