Codeforces 478D Red-Green Towers】的更多相关文章

http://codeforces.com/problemset/problem/478/D 思路:dp:f[i][j]代表当前第i层,用了j个绿色方块的方案数,用滚动数组,还有,数组清零的时候一定要用memset,不然for的常数太大.. #include<cstdio> #include<cmath> #include<algorithm> #include<cstring> #include<iostream> ; ],f[][]; int…
题目链接:http://codeforces.com/problemset/problem/478/D 题意: 给你r个红方块和g个绿方块,让你用这些方块堆一个塔. 最高层有1个方块,每往下一层块数+1,同时要保证每层中的方块都是同一种颜色. 如图: 问你在塔的高度最高的前提下,堆出塔的方案数. 题解: 假设塔最高能堆d层,则: d*(d+1)/2 <= r+g 解得: d = floor((-1+sqrt(1+8*(r+g)))/2) 并且d最大不超过900. 表示状态: dp[i][j] =…
题意:给定 n 块红砖,m 块绿砖,问有多少种方式可以建造成最高的塔,每一层颜色必须一样. 析:首先要确定最高是多少层h,大约应该是用 h * (h+1) <= (m+n) * 2,然后dp[i][j] 表示 前 i 层用 j 块红砖,dp[i][j] += dp[i-1][j-i], 但是这个空间复杂度受不了,那么就变成滚动数组就好,dp[j] += dp[j-i],一个较简单的DP. 代码如下: #pragma comment(linker, "/STACK:1024000000,10…
题目链接:http://codeforces.com/problemset/problem/399/B 题目意思:给出 n 个只由 R 和 B 组成的字符串(由上到下排列,相当于栈),问最多可以操作多少轮.一轮包括三个步骤:(1)如果栈顶的球为 red,则弹出(注意可以弹出多个),直到遇到栈顶的球为blue  (2)将这个blue球替换为red球(只操作一次)  (3)在替换完red 球上面添加blue球,直到有 n 个球为止.当然一轮中不一定3个步骤都执行.当 n 个球都为red时,就不能再操…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Innokentiy likes tea very much and today he wants to drink exactly n cups of tea. He would be happy to drink more but he had exactly n tea bags,…
http://codeforces.com/contest/746/problem/D 题意:有n杯茶,a杯绿茶,b杯红茶,问怎么摆放才可以让不超过k杯茶连续摆放,如果不能就输出NO. 思路:首先,设x = min(a,b),y = max(a,b),然后如果(y + x)/(x + 1) > k,那么就输出NO.即把 y 平均分成 x + 1 份,向上取整.然后开始搞... 搞的时候我直接对于 y 每一次都输出最大的份数了,导致后面的 x 过多,还自以为是平均的. 所以应该处理一下,如果有剩余…
Alyona and towers 这个题写起来真的要人命... 我们发现一个区间被加上一个d的时候, 内部的结构是不变的, 改变的只是左端点右端点的值, 这样就能区间合并了. 如果用差分的话会简单一些, 就变成了求前一段是负数,后一段是正数的最长段多长. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<…
题目链接:http://codeforces.com/problemset/problem/478/D 题意:给出红色方块r个,绿色方块g个,问最高能叠几层等腰三角形,而且每一层的颜色必须相同. 题解:一道简单的背包问题,设dp[i]表示放了i个红方块一共有几种方案. #include <iostream> #include <string> #include <cstring> #include <cstdio> #include <cmath>…
Codeforces 题目传送门 & 洛谷题目传送门 可能有人会问我为什么为这道 *2500 的 D1C 写题解,我觉得大概是想要在写题解数量上 dd ycx 吧,因为 ycx 到目前为止写了 143 篇题解,而这也是我的第 143 篇题解((( 大概和 CF1149C Tree Generator 比较像?做过那题这题基本可以一眼秒了( 线段树.每个区间维护以下八个值: 区间第一个元素的值 \(fst\) 区间最后一个元素的值 \(lst\) 区间长度 \(len\) 以左端点为开头的最长下降…
题意 给你n,m,如果 n个2的倍数和m个3的倍数,这n+m个数各不相同,那么求最大的数的最小值. 分析 方法1:枚举最大值为i,直到 i/2+i/3-i/6(不重复的2或3的倍数)≥n+m,并且要i/2(2的倍数)≥n,i/3(3的倍数)≥m. 方法2:枚举重复的数字i,i最小为6,每次增加6,设置两个结尾初始值为2*n,3*m,当两个结尾都比i大时,那就是还有重复.然后加在比较短的结尾.直到不再有重复. 代码 方法1 #include<cstdio> #include<algorit…
Table Decorations Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 478C Description You have r red, g green and b blue balloons. To decorate a single table for the banquet you need exactl…
B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Catherine has a deck of n cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can…
题目链接:http://codeforces.com/problemset/problem/1108/D time limit per test 1 secondmemory limit per test 256 megabytesinput standard inputoutput standard output You have a garland consisting of n lamps. Each lamp is colored red, green or blue. The colo…
http://codeforces.com/contest/478/problem/C C. Table Decorations time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have r red, g green and b blue balloons. To decorate a single table for…
链接: https://codeforces.com/contest/1263/problem/A 题意: You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are r candies in it, the second pile contains only green candies and there are g ca…
Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have three piles of candies: red, green and blue candies: the first pile…
B. Ciel and Flowers time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Fox Ciel has some flowers: r red flowers, g green flowers and b blue flowers. She wants to use these flowers to make seve…
C. Table Decorations time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have r red, g green and b blue balloons. To decorate a single table for the banquet you need exactly three balloons.…
A. Petya and Origamitime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya is having a party soon, and he has decided to invite his n friends. He wants to make invitations in the form of origami. Fo…
C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ii-th lamp is sisi ('R',…
D. Diverse Garland time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ii-th lamp is sisi ('…
You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ii-th lamp is sisi ('R', 'G' and 'B' — colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means chang…
You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ii-th lamp is sisi ('R', 'G' and 'B' — colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means chang…
You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ii-th lamp is sisi ('R', 'G' and 'B' — colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means chang…
A. Colorful Stones (Simplified Edition) time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You a…
  B. Cards   time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Catherine has a deck of n cards, each of which is either red, green, or blue. As long as there are at least two cards left, she…
C. Table Decorations time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have r red, g green and b blue balloons. To decorate a single table for the banquet you need exactly three balloons.…
A. Initial Bet time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are five people playing a game called "Generosity". Each person gives some non-zero number of coins b as an initial…
C. Table Decorations time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have r red, g green and b blue balloons. To decorate a single table for the banquet you need exactly three balloons.…
C. Table Decorations   You have r red, g green and b blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number t of tables can b…