日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

皇室战争

發(fā)布時(shí)間:2023/12/10 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 皇室战争 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題目大意:

初始有E點(diǎn)體力值,每天可以開寶箱消耗k體力值,體力值要保證>0 每次開寶箱可獲得k*a[i]的愉悅度 求最大愉悅度

樣例輸入1
1
5 2 2
2 1
樣例輸出1
12
樣例1解釋
第一天用5體力, 接下來回復(fù)2點(diǎn)體力, 用光。
限制與約定
數(shù)據(jù)編號(hào) cas N E 時(shí)間限制(S)
0 10 10 10 1
1 100 100 100 1
2 100 100 1000 1
3 100 10 10^6 1
4 100 10000 10^6 1
5 100 10000 10^6 1
6 20 100000 10^6 3
7 10 500000 10^6 3
8 10 500000 10^6 3
9 10 500000 10^6 3

?

題解:

調(diào)整操作的貪心, 直接假設(shè)當(dāng)天直接耗完體力值,然后加入單調(diào)棧,每次用i去替換<a[i]的操作.

?

1 #include <algorithm> 2 #include <iostream> 3 #include <cstdlib> 4 #include <cstring> 5 #include <cstdio> 6 #include <cmath> 7 using namespace std; 8 typedef long long ll; 9 const int N=500005; 10 int gi(){ 11 int str=0;char ch=getchar(); 12 while(ch>'9' || ch<'0')ch=getchar(); 13 while(ch>='0' && ch<='9')str=(str<<1)+(str<<3)+ch-48,ch=getchar(); 14 return str; 15 } 16 int q[N],res[N],a[N];ll ans=0; 17 void work(){ 18 int n,m,e; 19 m=gi();e=gi();n=gi(); 20 e=min(e,m); 21 for(int i=1;i<=n;i++)a[i]=gi(); 22 int r=1;q[1]=1;res[1]=m;ans=(ll)m*a[1]; 23 for(int i=2;i<=n;i++){ 24 res[i]=e; 25 while(r && a[i]>a[q[r]]){ 26 if(res[i]+res[q[r]]>m)ans-=(ll)(m-res[i])*a[q[r]],res[i]=m; 27 else ans-=(ll)a[q[r]]*res[q[r]],res[i]+=res[q[r]]; 28 r--; 29 } 30 q[++r]=i;ans+=(ll)res[i]*a[i]; 31 } 32 printf("%lld\n",ans); 33 } 34 int main() 35 { 36 freopen("power.in","r",stdin); 37 freopen("power.out","w",stdout); 38 int T=gi(); 39 while(T--) 40 work(); 41 return 0; 42 }

?

轉(zhuǎn)載于:https://www.cnblogs.com/Yuzao/p/7202292.html

總結(jié)

以上是生活随笔為你收集整理的皇室战争的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。