zoukankan      html  css  js  c++  java
  • 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 HPATK and 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;
    }
    View Code

    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;
    }
    View Code
  • 相关阅读:
    JavaScript 各种遍历方式详解
    使用TortoiseGit操作分支的创建与合并
    前端实现图片压缩上传
    改变input的value值,同时在HTML中将value进行改变
    HTML中字体单位px pt em之间的转换
    解决PHP无法接收post超过1000个字段的问题
    解决微信不能扫描下载的问题
    实现类似于百度实时搜索将结果在下拉框中显示的功能
    Python导入路径含特殊字符的包
    大二秋学期记录
  • 原文地址:https://www.cnblogs.com/icodefive/p/4129501.html
Copyright © 2011-2022 走看看