BNUOJ 26223 CosmoCraft

CosmoCraft

Time Limit: 1000ms

Memory Limit: 32768KB

This problem will be judged on HDU. Original ID: 4257
64-bit integer IO format: %I64d      Java class name: Main

In the two-player game CosmoCraft you manage an economy in the hopes of producing an army capable of defeating your opponent. You manage the construction of workers, production facilities, and army units; the game revolves around balancing the resources you allocate to each. The game progresses in turns.
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

There will be several test cases in the input. Each test case will begin with a line with three integers: 
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.

Hint

Huge input, please ues c++.

Output

For each test case output a single integer indicating the maximum number of armies you could have at the end of the game. Output -1 if it is impossible to survive. Output each integer on its own line, with no spaces, and do not print any blank lines between answers. While it is possible for some inputs to generate unreasonably large answers, all judge inputs yield answers which will fit in a signed 64-bit integer.

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

The University of Chicago Invitational Programming Contest 2012

解题:转自他人

题目大意

  介绍一款名叫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回合所需士兵数)。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <algorithm>
 6 #include <climits>
 7 #include <vector>
 8 #include <queue>
 9 #include <cstdlib>
10 #include <string>
11 #include <set>
12 #include <stack>
13 #define LL long long
14 #define pii pair<int,int>
15 #define INF 0x3f3f3f3f
16 using namespace std;
17 const int maxn = 100100;
18 LL d[maxn],n,k,t,u,theMin;
19 int main() {
20     int i,j;
21     bool flag;
22     while(scanf("%I64d %I64d %I64d",&n,&k,&t),n||k||t){
23         for(i = 1; i < t; i++) scanf("%I64d",d+i);
24         d[t] = 0;
25         if(min(n,k) < d[1]){puts("-1");continue;}
26         u = d[1];
27         flag = false;
28         for(i = 1; i < t; i++){
29             if(n + min(n,k) - u < d[i+1]) {flag = true;break;}//利用上次剩余的
30             //造一些 还不够去死
31             theMin = min(n,k);//利用n个人和k个军营最多造的人数
32             k += n - theMin;//当n > k时,剩余的钱造军营
33             n += theMin - u;//造了theMin个人,然后去打仗,死了一些,最后剩余
34             if(d[i+1] > k){//下一轮进攻军营不够用
35                 n -= d[i+1]-k;//用一些工人去换d[i+1]-k个人,
36                 u = k;//已经死了这么多个,还要死k个才行
37             }else u = d[i+1];
38         }
39         if(flag) {puts("-1");continue;}
40         if(t == 1) printf("%I64d\n",u < k ? u:k);
41         else printf("%I64d\n",n);
42     }
43     return 0;
44 }

BNUOJ 26223 CosmoCraft,布布扣,bubuko.com

时间: 2024-10-30 01:36:55

BNUOJ 26223 CosmoCraft的相关文章

bnuoj 17184 代数

bnuoj 17184 代数 题意: 现有N个未知数A[1],A[2],-A[N],以及M个方程,每个方程都是形如A[s]+A[s+1]+A[s+2]+-A[t-1]+A[t]=c.现在求解这个方程组. 限制: 1 <= n,m <= 1e5; 1 <= s,t <= N; 0 <= c < 1e9 思路: 带权并查集. 这道题想了好久没想通,最后才知道还可以用并查集做,涨知识了. 感谢http://blog.csdn.net/balloons2012/article/

BNUOJ 1206 A Plug for UNIX

A Plug for UNIX Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 108764-bit integer IO format: %lld      Java class name: Main You are in charge of setting up the press room for the inaugural meeting of the Un

BNUOJ 17286 Dollars

Dollars Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVA. Original ID: 14764-bit integer IO format: %lld      Java class name: Main New Zealand currency consists of $100, $50, $20, $10, and $5 notes and $2, $1, 50c, 20c, 1

BNUOJ 34025 -Poor Warehouse Keeper(贪心)

题目:BNUOJ 34025 -Poor Warehouse Keeper(贪心) 题目大意:有一个商品的信息表,上面是数量,下面是总价,然后旁边各有一个按钮.上面的数量按钮按一下数量就加1,然后价格对应的也要在加上一个当前的单价.下面的按钮按一下的话,就对应的总价加1.初始状态是 1 1,然后给出终点状态,问能否得到.可以的话输出最少要按几次按钮,否则输出-1:总价每次输出都是下取整. 解题思路:如果想要尽快的得到总点状态的值,那么就应该按总价的按钮,因为只有总价变大了,商品对因的单价就上升了

BNUOJ 52325 Increasing or Decreasing 数位dp

传送门:BNUOJ 52325 Increasing or Decreasing题意:求[l,r]非递增和非递减序列的个数思路:数位dp,dp[pos][pre][status] pos:处理到第几位 pre:前一位是什么 status:是否有前导零 递增递减差不多思路,不过他们计算的过程中像5555,444 这样的重复串会多算,所以要剪掉.个数是(pos-1)*9+digit[最高位],比如一位重复子串是:1,2,3,4...9,9个,二位重复子串:11,22,33,44,...,99,9个:

BNUOJ 1260 Brackets Sequence

Brackets Sequence Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 114164-bit integer IO format: %lld      Java class name: Main Special Judge Let us define a regular brackets sequence in the following way: 1.

BNUOJ 5997 Fibonacci again and again

Fibonacci again and again Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 184864-bit integer IO format: %I64d      Java class name: Main 任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样定义的:F(1)=1;F(2)=2;F(n)=F(n

BNUOJ 5227 Max Sum

Max Sum Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 100364-bit integer IO format: %I64d      Java class name: Main Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-

BNUOJ 34985 Elegant String 2014北京邀请赛E题 动态规划 矩阵快速幂

Elegant String Time Limit: 1000msMemory Limit: 65536KB 64-bit integer IO format: %lld      Java class name: Main We define a kind of strings as elegant string: among all the substrings of an elegant string, none of them is a permutation of "0, 1,-, k