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 = ;
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 = ; //钱
if(guanwujianxue <= ){
uu = b * (-guanwujianxue + );
guanwujianxue = ;
}
int yingxiongjianxue = max(, y1 - z);
int mina = ;
for(int i =guanwujianxue; i < maxa; i++){
for(int k= yingxiongjianxue; k >= ; k--){
int sum = (i - guanwujianxue)*b + (yingxiongjianxue-k)*c;
int n = x1/i;
if(x1 % i != )n++;
if(k * n < x)
mina = min(mina, sum);
else{
mina = min(mina, sum + (k*n+-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 = ;
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 = ; i < n; i++){
scanf("%d", &a[i]);
}
for(int i = , j = ; 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-]));
j++;
}
if(i - j+ >=l)rt.insert(dp[i-l]);
if(rt.begin() == rt.end())dp[i] = maxa;
else dp[i] = *rt.begin()+;
}
if(dp[n-] >= maxa)dp[n-] = -;
cout<<dp[n-]<<endl;
}

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. UBUNTU 下设置全局 path变量

    全局的对所有用户都可以的使用的PATH: 可以通过修改配置文件: /etc/bashrc 和 /etc/profile 来时配置, 全局的PATH; 例如: vi /etc/profile 在最后后加 ...

  2. C#泛型理解(转)

    [译]C# 理解泛型  PDF 浏览:http://www.tracefact.net/document/generics-in-csharp.pdf源码下载:http://www.tracefact ...

  3. Matlab与外部接口:MAT文件基础

    MAT 文件MAT文件是MATLAB使用的一种特有的二进制数据文件.MAT文件可以包含一个或者多个MATLAB 变量.MATLAB通常采用MAT文件把工作空间的变量存储在磁盘里,在MAT文件中不仅保存 ...

  4. Centos+nginx+uwsgi+Python多站点环境搭建

    前言 新公司的第一个项目,服务器端打算用python作为restful api.所以需要在Centos上搭建nginx+fastcgi+python的开发环境,但后面网上很多言论都说uwsgi比fas ...

  5. EDIT编辑框

    编辑框 编辑框的主要作用是让用户输入文本,例如要求用户在编辑框中输入密码的文本. .基础知识 编辑框里的文本可以是单行,也可以是多行,后者的风格取值为 ES_MULTILINE.一般对于多行文本编辑框 ...

  6. Swift—下标-备

    看下面的示例代码是不是使用过: var studentList: String[]  = ["张三","李四","王五"] studentL ...

  7. AtomicInteger小小的理解

    这里仅仅是验证多线程环境下,AtomicInteger的安全性. 通过源码不难发现两点: 1.value属性是volatile修饰 2.使用了unsafe的CAS操作 通过上述两点,实现非阻塞同步(乐 ...

  8. FMX手机app,如何下载网站图片而不卡界面

    你用的版本? 你应该关注下delphi 更新说明第一方法: 可以用线程.第二方法: TNetHTTPClient 已经支持异步 TThread.CreateAnonymousThread( proce ...

  9. google官方提供的下拉刷新控件SwipeRefreshLayout

    摘自:http://www.stormzhang.com/android/2014/03/29/android-swiperefreshlayout/ SwipeRefreshLayout Swipe ...

  10. Ubuntu 14.04 64位安装Android Studio 和 genymotion (下)

    接上一篇,上回书说到,我们可以进android studio的编辑器了.感觉不错.挺好的,先不说genymotion,先看看你的android项目有没有r文件,项目有没有错误? 如果没有问题的话,下面 ...