Gym 100269E-Energy Tycoon
来源:互联网 发布:蓝海文交软件下载 编辑:程序博客网 时间:2024/05/18 09:43
Input file: energy.in
Output file: energy.out
Time limit: 2 seconds
Memory limit: 256 megabytes
Little Vasya is playing a new computer game — turn-based strategy “Energy Tycoon”.
The rules of the game are quite simple:
• The board contains n slots arranged in a line.
• There are power plants, one power plant occupies one or two consecutive slots, and produces one
unit of energy.
• Each turn the game allows you to build one new power plant, you can put it on the board if you
wish. If there is no place for the new power plant, you can remove some older power plants.
• After each turn, the computer counts the amount of energy produced by the power plants on the
board and adds it to the total score.
Vasya already knows the types of power plant he will be able to build each turn. Now he wants to know,
what the maximum possible score he can get is. Can you help him?
Input
The first line of the input contains one integer n (1 ≤ n ≤ 100 000) — the number of slots on the board.
The second line contains the string s. The i-th character of the string is 1 if you can build one-slot power
plant at the i-th turn and the character is 2 if you can build two-slot power plant at the i-th turn. The
number of turns does not exceed 100 000.
Output
The output should contain a single integer — the maximal score that can be achieved.
Examples
题意:给你格子的数目和每一次能放的小格子的大小,每放一个都能得到1分,每次可以拿掉某个小格子放上新的格子,问能得到的最高分。
可以知道大小为1时是最划算的,所以放不下的时候,如果有大小为2的格子就拿掉它。
代码:
#include <cstdio>#include <algorithm>#include <cstring>#include <iostream>#include <string>using namespace std;int main (void){ freopen("energy.in","r",stdin); freopen("energy.out","w",stdout); string s; int n; cin>>n; cin>>s; long long ans=0,a1=0,a2=0; for(int i=0;i<s.size();i++) { if(s[i]=='1') { if(a1+a2*2+1<=n) a1++; else if(a2) { a2--; a1++; } } if(s[i]=='2') { if(a1+a2*2+2<=n) a2++; } ans+=(a1+a2); } printf("%lld\n",ans); return 0;}
- Gym 100269E-Energy Tycoon
- HNU 12848 Energy Tycoon (贪心)
- Gym-101612E E
- Gym 100935E Pairs
- CodeForces Gym 100735E
- Codeforces gym 100685 E
- Gym 100712E 贪心
- codeforces [Gym-100814E]
- Codeforces gym 101243 E
- Gym 101161 E
- Gym 101243.E
- Teams Gym-101028E
- Energy
- Gym 100187E - Two Labyrinths
- Gym 100499E (树DP)
- Gym - 100338E Numbers 贪心
- Gym-100712E-Epic Professor
- Gym 100712E Epic Professor
- Android利用canvas画各种图形(点、直线、弧、圆、椭圆、文字、矩形、多边形、曲线、圆角矩形)
- 用栈代替递归-汉诺塔问题(算法基础 第3周)
- oracle中的CURRVAL和NEXTVAL用法
- IE6 BUG的解决方法
- c++上机实验7-项目3:特殊三位数
- Gym 100269E-Energy Tycoon
- c++作业七
- 清除浮动的几种方式,各自的优缺点
- 自定义view实现水波纹效果
- c++作业7
- hibernate使用带有sum()的hql语句出错的问题
- 总结几个实用的js/jq代码片段
- EasyCamera配置文件
- 数据结构自学之路---单链表