cf-Global Round2-E. Pavel and Triangles
题目链接: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的更多相关文章
- Codeforces 1119E Pavel and Triangles (贪心)
Codeforces Global Round 2 题目链接: E. Pavel and Triangles Pavel has several sticks with lengths equal t ...
- E. Pavel and Triangles dp+问题转化
E. Pavel and Triangles dp+问题转化 题意 给出n种线段,每种线段给出一定数量,其中每个线段都是 \(2^k\) 问最多能组成多少个三角形 思路 因为每个是\(2^k\)所以能 ...
- Codeforces Global Round 2 E. Pavel and Triangles(思维+DP)
题目链接:https://codeforces.com/contest/1119/problem/E 题意:有n种长度的棍子,有a_i根2^i长度的棍子,问最多可以组成多少个三角形 题解:dp[i]表 ...
- [题解向] CF#Global Round 1の题解(A $\to$ G)
这里是总链接\(Link\). \(A\) 题意:求\(\sum_{i=1}^{k} a_i\times b^{k-i}\)的奇偶性, \(k = \Theta(n \log n)\) --其实很容易 ...
- 【CF1119E】Pavel and Triangles
题目大意:有 N 种长度的边,第 i 种长度为 \(2^i\),给定一些数量的这些边,问最多可以组合出多少种三角形. 题解:应该是用贪心求解,不过选择什么样的贪心策略很关键. 首先分析可知,两个较大边 ...
- CF Global Round 21 题解 (CDEG)
C 把 \(a,b\) 全拆开然后比较即可(因为分裂和合并是互逆的) 注意开 long long . using namespace std; typedef long long ll; typede ...
- Codeforces Global Round 2 题解
Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...
- 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-> ...
- CF1119 Global Round 2
CF1119A Ilya and a Colorful Walk 这题二分是假的.. \(1,2,1,2,1\) 有间隔为 \(3\) 的,但没有间隔为 \(2\) 的.开始被 \(hack\) 了一 ...
随机推荐
- golang 的 mysql 操作
goLang的mysql操作,大致可分为三个步骤: 1.下载mysql驱动:go get github.com/go-sql-driver/mysql 2.建立连接:sql.Open("my ...
- Mp4 to Img
# -*- coding: utf-8 -*- """ Created on Thu May 3 16:51:50 2018 """ # 录 ...
- Spring boot 日志
修改spring boot 默认日志的配置 #logging.path= # 不指定路径在当前项目下生成springboot.log日志 # 可以指定完整的路径: #logging.file=G:/s ...
- 回溯法 leetcode题解 Combination Sum 递归法
题目大意:给出一个数组,用这些数组里的元素去凑一个target.元素可以重复取用. 感觉对这种题目还是生疏的.脑子里有想法,但是不知道怎么表达出来. 先记录下自己的递归法.应该还可以用循环实现. 回溯 ...
- class 方法
实例对象调用class方法时返回这个实例对象的isa指针,也就是对应的类对象: 类对象调用class方法时返回这个类对象本身. (注:如果想一直获得一个类的类对象,也就是isa指针,可以调用runti ...
- iOS设计标注处理方法
如果设计只给3x的设计图 在做2x适配时有几种处理方法: 按逻辑像素,大小不变,比如3x手机上一张图的逻辑像素设为24x24point,那么2x手机上这张图的大小也设为24x24point,一般适用于 ...
- vue.js 组件引用之初级 之二
1. template 标签也可以实现替换,这样可以省去script标签了 <!DOCTYPE html> <html lang="en"> <hea ...
- jquery接触初级-----ajax 之:jquery_ajax 方法
1. $.get() 方法: 格式:$.get( url,[,data],[,callback],[,type] ); data: 采用键值对的方式存储于对象中; callback: 载入成功时(当 ...
- javascript:查看一个图片是否加载完成
查看一个图片是否加载完成:<img id="img1" src="http://pic1.xxx.com/wall/f/51c3bb99a21ea.jpg" ...
- SecureCRT使用本地公钥 SSH 免密码登录Linux
其原理与Linux系统之间的SSH通道原理是一样的 下文中如果创建公钥的格式是:标准公钥和VanDyke私钥格式,需要用ssh-keygen -i -f 转换.如果是OpenSSH密钥格式可直接修改文 ...