D. Berserk And Fireball(模拟)

36 篇文章 0 订阅
4 篇文章 0 订阅

题意:
n个战士排成一排,分别有个武力值ai。你有两种法术,一个是火球(花费x个法力,消灭连续k个战士),一个是激怒(花费y个法力,选择相邻两个战士,武力值大的会消灭武力值小的)。求最后留下的战士排列成bi需要的最小法力花费

思路:
因为每个数都不同,所以肯定是划分成多个区间,对每个区间进行操作。
1 ) 1) 1) 如果当前区间的长度 l e n < k len < k len<k
①区间最大值大于左右端点,那么无解。因为无法消去最大值。
②区间最大值小于等于左右端点,消费就是 l e n ∗ y len*y leny
2 ) 2) 2) 如果当前区间的长度 l e n ≥ k len ≥ k lenk
①区间最大值大于左右端点,那么必须花费一个 x x x ,来把最大值消掉。如果火球更优,那么答案就是 l e n / k ∗ x + ( l e n % k ) ∗ y len/k*x + (len\%k)*y len/kx+(len%k)y。可以用最大值把 l e n % k len\%k len%k 个战士消掉,然后用火球消去连续的 k 。一定有解。如果激怒更优,那么答案就是 x + ( l e n − k ) ∗ y x + (len-k)*y x+(lenk)y
②区间最大值小于左右端点,不是必须花费 x x x ,则就直接判断哪种方式更优,同上。

代码有点细节

code

#include<bits/stdc++.h>
using namespace std;
const int man = 2e5+10;
#define ll long long
int a[man],b[man];

signed main() {
    int n,m;scanf("%d%d",&n,&m);
    int x,k,y;scanf("%d%d%d",&x,&k,&y);
    for(int i = 1;i <= n;++i)scanf("%d",a+i);
    for(int i = 1;i <= m;++i)scanf("%d",b+i);
    a[n+1] = b[m+1] = -1;
    ll ans = 0;
    for(int i = 1,j = 0;i <= m+1;++i){
        int l = j+1,r = j+1,len = 0,maxx =-1;
        while(r<=n+1&&a[r]!=b[i])maxx = max(maxx,a[r]),r++;
        if(r>n+1){ans = -1;break;}
        len = r - l;
        if(len<k){
            if(maxx>max(a[l-1],a[r])){ans = -1;break;}
            else ans += 1ll*y*len;
        }else{
            if(maxx>max(a[l-1],a[r])){
                ans += 1ll*x;
                len -= k;
                if(x<1ll*k*y)ans += 1ll*(len/k)*x + 1ll*(len%k)*y;
                else ans += 1ll*y*len;
            }else{
                if(x<1ll*k*y)ans += 1ll*(len/k)*x + 1ll*(len%k)*y;
                else ans += 1ll*y*len;
            }
        }
        if(a[r]!=b[i])j = r + 1;
        else j = r;
    }
    printf("%lld\n",ans);
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
以下是截至2021年10月的全球动漫评分排行榜前100名: 1.《Fullmetal Alchemist: Brotherhood》 2.《Steins;Gate》 3.《Your Lie in April》 4.《Hunter x Hunter (2011)》 5.《Gintama》 6.《Haikyuu!!》 7.《Attack on Titan》 8.《Code Geass: Lelouch of the Rebellion》 9.《Clannad: After Story》 10.《Death Note》 11.《One Punch Man》 12.《Jojo's Bizarre Adventure》 13.《Cowboy Bebop》 14.《Baccano!》 15.《Neon Genesis Evangelion》 16.《Spirited Away》 17.《Monogatari Series》 18.《Shigatsu wa Kimi no Uso》 19.《Toradora!》 20.《Tengen Toppa Gurren Lagann》 21.《K-On!》 22.《The Melancholy of Haruhi Suzumiya》 23.《Fate/Zero》 24.《One Piece》 25.《Rurouni Kenshin: Trust and Betrayal》 26.《Dragon Ball Z》 27.《Legend of the Galactic Heroes》 28.《Hajime no Ippo》 29.《Ghost in the Shell: Stand Alone Complex》 30.《Nana》 31.《Samurai Champloo》 32.《Great Teacher Onizuka》 33.《Anohana: The Flower We Saw That Day》 34.《Kimi no Na wa.》 35.《Kara no Kyoukai》 36.《Psycho-Pass》 37.《Bakemonogatari》 38.《No Game No Life》 39.《Nichijou》 40.《Usagi Drop》 41.《Kill la Kill》 42.《Akira》 43.《Durarara!!》 44.《Tatami Galaxy》 45.《Katanagatari》 46.《Berserk》 47.《Princess Mononoke》 48.《Higurashi no Naku Koro ni》 49.《Soul Eater》 50.《Black Lagoon》 51.《Naruto》 52.《Fairy Tail》 53.《Kimi ni Todoke》 54.《Serial Experiments Lain》 55.《Kuroko no Basket》 56.《Chihayafuru》 57.《Hyouka》 58.《Bleach》 59.《Sakamichi no Apollon》 60.《Golden Time》 61.《Love Live! School Idol Project》 62.《Cardcaptor Sakura》 63.《Gekkan Shoujo Nozaki-kun》 64.《Full Metal Panic!》 65.《Mobile Suit Gundam: Iron-Blooded Orphans》 66.《K-On! Movie》 67.《Kizumonogatari》 68.《Re:Zero kara Hajimeru Isekai Seikatsu》 69.《Shirobako》 70.《Yahari Ore no Seishun Love Comedy wa Machigatteiru.》 71.《Darker than Black》 72.《Honey and Clover》 73.《Zankyou no Terror》 74.《Usagi Drop Specials》 75.《Mahou Shoujo Madoka★Magica》 76.《Bungou Stray Dogs》 77.《Kara no Kyoukai 5: Mujun Rasen》 78.《K-On! 2》 79.《Toaru Kagaku no Railgun》 80.《Kimi ga Nozomu Eien》 81.《Grisaia no Kajitsu》 82.《Gochuumon wa Usagi Desu ka?》 83.《Shinsekai yori》 84.《Nodame Cantabile》 85.《Bungou Stray Dogs 2nd Season》 86.《Made in Abyss》 87.《Gin no Saji》 88.《Ranma ½》 89.《K-On!!》 90.《Sword Art Online》 91.《Hibike! Euphonium》 92.《Nisekoi》 93.《K-On!: Live House!》 94.《K-On!: Keikaku!》 95.《D-Frag!》 96.《K-On!: Ura-ON!》 97.《K-On!: College》 98.《K-On!: Fude Pen - Boru Pen》 99.《K-On!: Plan!》 100.《K-On!: Movie - Wonderful♪》

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值