Codeforces Round #278 (Div. 1)

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.

暴力攻防

#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
const int maxa = 300;
int dp[maxa][maxa];
int main(){
    int x, y, z;
    int x1, y1, z1;
    int a, b, c;
    cin>>x>>y>>z>>x1>>y1>>z1>>a>>b>>c;
    int guanwujianxue = y -  z1;
    int uu = 0;             //钱
    if(guanwujianxue <= 0){
        uu = b * (-guanwujianxue + 1);
        guanwujianxue = 1;
    }
    int yingxiongjianxue = max(0, y1 - z);
    int mina = 10000000;
    for(int i =guanwujianxue; i < maxa; i++){
        for(int k= yingxiongjianxue; k >= 0; k--){
            int sum = (i - guanwujianxue)*b + (yingxiongjianxue-k)*c;
            int n = x1/i;
            if(x1 % i != 0)n++;
            if(k * n < x)
                mina = min(mina, sum);
            else{
                mina = min(mina, sum + (k*n+1-x)*a);
            }
        }
    }
    cout<<mina+uu<<endl;
}

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.

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

#include<stdio.h>

#include<string.h>
#include<iostream>
#include<set>
using namespace std;
const int maxa = 100005;
int dp[maxa];
int n, s, l;
multiset<int>st, rt;
int a[maxa];
int main(){
    scanf("%d%d%d", &n, &s, &l);
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    for(int i = 0, j = 0; i < n; i++){
        st.insert(a[i]);
        while(*st.rbegin() - *st.begin() > s){
            st.erase(st.find(a[j]));
            if(i - j >= l)
                rt.erase(rt.find(dp[j-1]));
            j++;
        }
        if(i - j+1 >=l)rt.insert(dp[i-l]);
        if(rt.begin() == rt.end())dp[i] = maxa;
            else dp[i] = *rt.begin()+1;
    }
    if(dp[n-1] >= maxa)dp[n-1] = -1;
    cout<<dp[n-1]<<endl;
}

时间: 2024-10-05 04:41:36

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

Codeforces Round #278 (Div. 2) b

/**  *  * @brief Codeforces Round #278 (Div. 2) b  * @file b.c  * @author mianma  * @created 2014/11/24 17:52  * @edited  2014/11/18 17:52  * @type brute  *   * @note   *          declare k >= 0;  *              then   *                  x1 = k  *   

Codeforces Round #278 (Div. 2) d

/**  * @brief Codeforces Round #278 (Div. 2) d  * @file d.c  * @author 面码  * @created 2014/11/26 10:07  * @edited  2014/11/26 10:07  * @type dp   * @note  *      自己的TL了,看了别人代码写的  *      该代码主要是在dp的基础上使用stl来提速  *      dp需辅助提速,但内存又不能爆掉是该题目的卡点 = =  */ #i

Codeforces Round #278 (Div. 2) c

/**  * @brief Codeforces Round #278 (Div. 2) c  * @file c.c  * @author 面码  * @created 2014/11/25 14:15  * @edited  2014/11/25 14:15  * @type brute  *  */ #include <stdio.h> #define max(a, b)  ((a) > (b) ? (a) : (b)) #define min(a, b)  ((a) > (

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

A 这么简单的题直接贴代码好了. 1 #include <cstdio> 2 #include <cmath> 3 using namespace std; 4 5 bool islucky(int a) 6 { 7 a = abs(a); 8 while(a) 9 { 10 if(a % 10 == 8) return true; 11 a /= 10; 12 } 13 return false; 14 } 15 16 int main(void) 17 { 18 int a,

Codeforces Round #278 (Div. 2)

A直接暴力好了. 1 #include<bits/stdc++.h> 2 typedef long long ll; 3 using namespace std; 4 5 int pan(ll x) 6 { 7 while (x) 8 { 9 if (x%10==8) return 1; 10 x/=10; 11 } 12 return 0; 13 } 14 15 int main() 16 { 17 ll n; 18 cin>>n; 19 for (int i=1;i<=1

Codeforces Round #278 (Div. 2) B. Candy Boxes [brute force+constructive algorithms]

哎,最近弱爆了,,,不过这题还是不错滴~~ 要考虑完整各种情况 8795058                 2014-11-22 06:52:58     njczy2010     B - Candy Boxes             GNU C++     Accepted 31 ms 4 KB 8795016                 2014-11-22 06:48:15     njczy2010     B - Candy Boxes             GNU C+

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿