A

A monster is attacking the Cyberland!

Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (HP), offensive power (ATK) and defensive power (DEF).

During the battle, every second the monster's HP decrease by max(0, ATKY - DEFM), while Yang's HP decreases bymax(0, ATKM - DEFY), where index Y denotes Master Yang and index M denotes monster. Both decreases happen simultaneously Once monster's HP ≤ 0 and the same time Master Yang's HP > 0, Master Yang wins.

Master Yang can buy attributes from the magic shop of Cyberland: h bitcoins per HPa bitcoins per ATK, and d bitcoins per DEF.

Now Master Yang wants to know the minimum number of bitcoins he can spend in order to win.

Input

The first line contains three integers HPY, ATKY, DEFY, separated by a space, denoting the initial HPATK and DEF of Master Yang.

The second line contains three integers HPM, ATKM, DEFM, separated by a space, denoting the HPATK and DEF of the monster.

The third line contains three integers h, a, d, separated by a space, denoting the price of 1 HP, 1 ATK and 1 DEF.

All numbers in input are integer and lie between 1 and 100 inclusively.

Output

The only output line should contain an integer, denoting the minimum bitcoins Master Yang should spend in order to win.

暴力攻防

  1. #include<iostream>
  2. #include<string.h>
  3. #include<stdio.h>
  4. using namespace std;
  5. const int maxa = ;
  6. int dp[maxa][maxa];
  7. int main(){
  8. int x, y, z;
  9. int x1, y1, z1;
  10. int a, b, c;
  11. cin>>x>>y>>z>>x1>>y1>>z1>>a>>b>>c;
  12. int guanwujianxue = y - z1;
  13. int uu = ; //钱
  14. if(guanwujianxue <= ){
  15. uu = b * (-guanwujianxue + );
  16. guanwujianxue = ;
  17. }
  18. int yingxiongjianxue = max(, y1 - z);
  19. int mina = ;
  20. for(int i =guanwujianxue; i < maxa; i++){
  21. for(int k= yingxiongjianxue; k >= ; k--){
  22. int sum = (i - guanwujianxue)*b + (yingxiongjianxue-k)*c;
  23. int n = x1/i;
  24. if(x1 % i != )n++;
  25. if(k * n < x)
  26. mina = min(mina, sum);
  27. else{
  28. mina = min(mina, sum + (k*n+-x)*a);
  29. }
  30. }
  31. }
  32. cout<<mina+uu<<endl;
  33. }

Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right.

Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy:

  • Each piece should contain at least l numbers.
  • The difference between the maximal and the minimal number on the piece should be at most s.

Please help Alexandra to find the minimal number of pieces meeting the condition above.

Input

The first line contains three space-separated integers n, s, l (1 ≤ n ≤ 105, 0 ≤ s ≤ 109, 1 ≤ l ≤ 105).

The second line contains n integers ai separated by spaces ( - 109 ≤ ai ≤ 109).

Output

Output the minimal number of strip pieces.

If there are no ways to split the strip, output -1.

思路就是线性的,看到个牛逼的解法

  1. #include<stdio.h>
  2.  
  3. #include<string.h>
  4. #include<iostream>
  5. #include<set>
  6. using namespace std;
  7. const int maxa = ;
  8. int dp[maxa];
  9. int n, s, l;
  10. multiset<int>st, rt;
  11. int a[maxa];
  12. int main(){
  13. scanf("%d%d%d", &n, &s, &l);
  14. for(int i = ; i < n; i++){
  15. scanf("%d", &a[i]);
  16. }
  17. for(int i = , j = ; i < n; i++){
  18. st.insert(a[i]);
  19. while(*st.rbegin() - *st.begin() > s){
  20. st.erase(st.find(a[j]));
  21. if(i - j >= l)
  22. rt.erase(rt.find(dp[j-]));
  23. j++;
  24. }
  25. if(i - j+ >=l)rt.insert(dp[i-l]);
  26. if(rt.begin() == rt.end())dp[i] = maxa;
  27. else dp[i] = *rt.begin()+;
  28. }
  29. if(dp[n-] >= maxa)dp[n-] = -;
  30. cout<<dp[n-]<<endl;
  31. }

Codeforces Round #278 (Div. 1)的更多相关文章

  1. Codeforces Round #278 (Div. 2)

    题目链接:http://codeforces.com/contest/488 A. Giga Tower Giga Tower is the tallest and deepest building ...

  2. Brute Force - B. Candy Boxes ( Codeforces Round #278 (Div. 2)

    B. Candy Boxes Problem's Link:   http://codeforces.com/contest/488/problem/B Mean: T题目意思很简单,不解释. ana ...

  3. Codeforces Round #278 (Div. 1) B. Strip multiset维护DP

    B. Strip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/487/problem/B De ...

  4. Codeforces Round #278 (Div. 1) A. Fight the Monster 暴力

    A. Fight the Monster Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/487/ ...

  5. CodeForces Round #278 (Div.2) (待续)

    A 这么简单的题直接贴代码好了. #include <cstdio> #include <cmath> using namespace std; bool islucky(in ...

  6. codeforces 487a//Fight the Monster// Codeforces Round #278(Div. 1)

    题意:打怪兽.可增加自己的属性,怎样在能打倒怪兽的情况下花费最少? 这题关键要找好二分的量.一开始我觉得,只要攻击到101,防御到100,就能必胜,于是我对自己的三个属性的和二分(0到201),内部三 ...

  7. Codeforces Round #278 (Div. 2) D. Strip 线段树优化dp

    D. Strip time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  8. Codeforces Round #278 (Div. 1) D - Conveyor Belts 分块+dp

    D - Conveyor Belts 思路:分块dp, 对于修改将对应的块再dp一次. #include<bits/stdc++.h> #define LL long long #defi ...

  9. Codeforces Round #278 (Div. 1) B - Strip dp+st表+单调队列

    B - Strip 思路:简单dp,用st表+单调队列维护一下. #include<bits/stdc++.h> #define LL long long #define fi first ...

随机推荐

  1. Hibernate数据库对象的创建与导出

    Hibernate 与数据库的关系是ORM关系,对象映射数据库. 那么如何通过对象对数据库进行各种对象的ddl与dml操作呢? 数据库对象操作的〈database-object /〉+ SchemaE ...

  2. nodejs定时任务node-schedule

    1:使用npm安装node-schedule模块 npm install node-schedule (1)每隔5分钟执行一次: var schedule = require('node-schedu ...

  3. 使用dom4j生成xml字符串,以及解析xml字符串

    基于dom4j-1.6.1.jar import java.io.IOException; import java.io.StringWriter; import java.util.ArrayLis ...

  4. Android比较字符串是否为空(isEmpty)

    StringUtils.java: package com.yx.equipment_collection.utils; import android.annotation.SuppressLint; ...

  5. Delphi EurekaLog 调试内存泄露方法

    要使用EurekaLog进行内存泄露检测,需要手动开启"EurekaLog Options..."下的"Advanced Options"旁的"Mem ...

  6. HDOJ 1163 Eddy's digital Roots(九余数定理的应用)

    Problem Description The digital root of a positive integer is found by summing the digits of the int ...

  7. 算法导论(第三版)Problems2(归并插入排序、数列逆序计算)

    讨论内容不说明,仅提供相应的程序. 2.1:归并插入排序θ(nlgn) void mergeInsertionSort(int a[], int l, int r, int k) { int m; & ...

  8. hdu-1598

    思路: 首先如果想到了Kruskal算法,那么下一步我们可能马上会想:那我们就从头开始写这个算法吧.然后一写就很容易发现一个问题——如果按照正常的Kruskal算法来做,那么start到end的舒适度 ...

  9. hadoop-2.6.0为分布式安装

    hadoop-2.6.0为分布式安装 伪分布模式集群规划(单节点)------------------------------------------------------------------- ...

  10. SpringMVC 拦截器(interceptors)对样式(css),JavaScript(js),图片(images)链接的拦截

    因为在web.xml配置了 <servlet-mapping> <servlet-name>appServlet</servlet-name> <url-pa ...