BNUOJ 26223 CosmoCraft
CosmoCraft
This problem will be judged on HDU. Original ID: 4257
64-bit integer IO format: %I64d Java class name: Main
1. Workers give you income at the rate of 1 dollar per turn.
2. Production facilities let you produce either an army unit or a worker for the cost of 1 dollar. (only 1 army unit or worker can be produced per turn per facility)
3. It costs 1 dollar to create a production facility.
4. Your army, of course, lets you fight against your opponent.
You start off with n workers and k production facilities. The game progresses in turns – at each turn, you can spend the income you get from your workers on a mixture of workers, army, and creating production facilities. Workers produced this round do not give you income until the next round; likewise, production facilities do not become active until the next round. Any unspent income from the current round carries over to the next.
At the end of a round, you can take the total army you’ve produced and attack your opponent; if you have strictly more units than your opponent, the opponent loses immediately, and you retain the difference of the army sizes. Otherwise, your army is crushed and your opponent is left with the difference of the army sizes. (it would be wise for him to counter-attack after this, but you don’t lose immediately at least). The game ends after t turns, at which point both players will usually attack with the larger army reigning victorious.
You’re playing against your friend, and since you’ve played against him so many times you know exactly what he’s going to spend his money on at every turn, and exactly when he’s going to attack. Knowing this, you’ve decided that the best strategy is to play defensively – you just want to survive every attack, and amass as large an army in the meantime so you can counterattack (and hopefully win) at the end of the game.
What’s the largest army you can have at the end of the game, given that you must survive all your friend’s attacks?
Input
n k t
where n (1≤n≤100) is the number of workers you start with, k (1≤k≤100) is the number of production facilities you have at the start, and t(1≤t≤10,000) is the number of turns. On the next line will be t-1 integers, ai (0≤ai≤Max signed 64-bit integer), separated by single spaces. The ith integer indicates the strength of the attack (that is, the number of army units your opponent is using in that attack) on turn i. The input will end with a line with three 0s.
Huge input, please ues c++.
Output
Sample Input
8 4 6
22 6 10 14 0
4 3 3
0 0
6 9 7
0 0 11 0 7 0
0 0 0
Sample Output
-1
11
101
Source
题目大意
介绍一款名叫CosmoCraft的双人回合制策略游戏(但网上找不到这种游戏),每一回合玩家可以:1。花费1元/个购买工人,2。花费1元/个购买士兵,3。花费1元/个购买兵营。每回合1个工人可以挣1元,但钱会在下一回合给你,每个兵营每一回合只能造一个工人或士兵,同样的每一回合建造的兵营将在下一回合起可用,每一回合造的工人或士兵当前回合起即可使用。游戏初始给你n个工人和k个兵营以及n元,游戏共t回合,前t-1回合每一回合将会有a[i]个敌方士兵回来攻击你,你必须能抵挡住每一回合的进攻,即在每一回合拥有比进攻你的敌方军队更多的士兵,每次战争士兵数多的一方取胜,并剩下双方交战士兵的差值的士兵数,而失败一方则一兵不剩,请你使用最优策略使得你在第t回合的反击中拥有最多的士兵,并输出最大值。
贪心策略:
1。每一回合必须花完所有的钱。
2。一个士兵不可能连续存在两回合以上(超过两回合说明他没有打仗,可以花1元在第一回合造工人,在第二回合用工人赚的钱造兵营,第三回合再用工人赚的钱和造的兵营造士兵)。
3。每回合在保证生存的前提下,先造尽量多的工人,能造多少造多少,剩下的钱再造兵营。
4。根据策略二,第i(1<=i<=t)回合的士兵只能由第i回合或第i-1回合造,若第i回合可以造出d[i]个士兵,就在第i回合造,否则需要第i-1回合的支援,第i-1回合最多支援第i回合k[i-1]-u[i-1]个士兵(在w[i-1]>k[i-1]的情况下)否则不能抵御第i回合的进攻。(k[i]代表第i回合的兵营数,n[i]代表第i回合的工人数,u[i]代表第i回合所需士兵数)。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
LL d[maxn],n,k,t,u,theMin;
int main() {
int i,j;
bool flag;
while(scanf("%I64d %I64d %I64d",&n,&k,&t),n||k||t){
for(i = ; i < t; i++) scanf("%I64d",d+i);
d[t] = ;
if(min(n,k) < d[]){puts("-1");continue;}
u = d[];
flag = false;
for(i = ; i < t; i++){
if(n + min(n,k) - u < d[i+]) {flag = true;break;}//利用上次剩余的
//造一些 还不够去死
theMin = min(n,k);//利用n个人和k个军营最多造的人数
k += n - theMin;//当n > k时,剩余的钱造军营
n += theMin - u;//造了theMin个人,然后去打仗,死了一些,最后剩余
if(d[i+] > k){//下一轮进攻军营不够用
n -= d[i+]-k;//用一些工人去换d[i+1]-k个人,
u = k;//已经死了这么多个,还要死k个才行
}else u = d[i+];
}
if(flag) {puts("-1");continue;}
if(t == ) printf("%I64d\n",u < k ? u:k);
else printf("%I64d\n",n);
}
return ;
}
BNUOJ 26223 CosmoCraft的更多相关文章
- BNUOJ 52325 Increasing or Decreasing 数位dp
传送门:BNUOJ 52325 Increasing or Decreasing题意:求[l,r]非递增和非递减序列的个数思路:数位dp,dp[pos][pre][status] pos:处理到第几位 ...
- bnuoj 24251 Counting Pair
一道简单的规律题,画出二维表将数字分别相加可以发现很明显的对称性 题目链接:http://www.bnuoj.com/v3/problem_show.php?pid=24251 #include< ...
- bnuoj 44359 快来买肉松饼
http://www.bnuoj.com/contest/problem_show.php?pid=44359 快来买肉松饼 Time Limit: 5000 ms Case Time Lim ...
- BNUOJ 1006 Primary Arithmetic
Primary Arithmetic 来源:BNUOJ 1006http://www.bnuoj.com/v3/problem_show.php?pid=1006 当你在小学学习算数的时候,老师会教你 ...
- bnuoj 34985 Elegant String DP+矩阵快速幂
题目链接:http://acm.bnu.edu.cn/bnuoj/problem_show.php?pid=34985 We define a kind of strings as elegant s ...
- bnuoj 25659 A Famous City (单调栈)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=25659 #include <iostream> #include <stdio.h ...
- bnuoj 25662 A Famous Grid (构图+BFS)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=25662 #include <iostream> #include <stdio.h ...
- bnuoj 4207 台风(模拟题)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=4207 [题意]:中文题,略 [题解]:模拟 [code]: #include <iostrea ...
- bnuoj 4208 Bubble sort
http://www.bnuoj.com/bnuoj/problem_show.php?pid=4208 [题意]:如题,求冒泡排序遍历趟数 [题解]:这题开始2B了,先模拟TLE,然后想了一下,能不 ...
随机推荐
- F - Function
Bryce1010模板 先找到数组A中的循环节,再找到数组B中的循环节,如果B中的循环节是A中循环节的循环因子,说明可以配对,结果累积起来. #include<bits/stdc++.h> ...
- Android开发学习——android反编译
第一种: 1.下载下边的三个jar包,对dex2jar和jd-gui进行解压 2.将需要反编译的apk后缀名改为.rar,然后进行解压 3.将解压后生成的classes.dex加入第一步解压后的dex ...
- js类、原型——学习笔记
js 内置有很多类,我们用的,都是从这些类实例化出来的. function Object () {} function Array () {} function String () {} functi ...
- Spring注解驱动开发之扩展原理
前言:现今SpringBoot.SpringCloud技术非常火热,作为Spring之上的框架,他们大量使用到了Spring的一些底层注解.原理,比如@Conditional.@Import.@Ena ...
- 从java toBinaryString() 看计算机数值存储方式(原码、反码、补码)
一.toBinaryString 方法及其含义 1.1 方法说明 该方法位于java.lang.Integer类中 方法签名:public static String toBinaryString(i ...
- [BZOJ1878][SDOI2009]HH的项链 莫队
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1878 不带修改的莫队,用一个桶记录一下当前区间中每种颜色的数量就可以做到$O(1)$更新了 ...
- 掌握Spark机器学习库-07.6-线性回归实现房价预测
数据集 house.csv 数据概览 代码 package org.apache.spark.examples.examplesforml import org.apache.spark.ml.fea ...
- 基于ANGULAR.JS的下一代WEB应用开发-01-yeoman
Angularjs 个人认为这是一款很好的框架!它将我们从AJAX应用的开发中解救了出来!嗯....废话就说道这里下面我们开始把! 首先我们必须了解一些核心的概念: 客户端模版 MVC 数据绑定 依赖 ...
- linux 10201 ASM RAC 安装+升级到10205
准备环境的时 ,要4个对外IP,2个对内IP 不超过2T,,一般都用OCFS 高端存储适合用ASM linux10G安装的时候,安装的机器时间要小于等于(如果是等于要严格等于)第二个机器的时间(只有l ...
- Android APK生成证书并签名方法
Android APK生成证书并签名方法 android cordova keystore android证书签名 阅读:925 时间:2018年09月20日 Android开发者可能对此很熟悉.使用 ...