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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

1489 蜥蜴和地下室

發布時間:2024/9/5 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 1489 蜥蜴和地下室 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

思路:先把最左和最右的干掉,剩下的再一起dfs。dfs的時候注意當第cur-1個死了之后(而第cur個不要求必須死)才向后面搜索第cur+1個。

當前的第cur個可以被扔在自己身上的火球,也可被扔在第cur+1個的火球干掉。

1 #include <iostream> 2 #include <queue> 3 #include <stack> 4 #include <cstdio> 5 #include <vector> 6 #include <map> 7 #include <set> 8 #include <bitset> 9 #include <algorithm> 10 #include <cmath> 11 #include <cstring> 12 #include <cstdlib> 13 #include <string> 14 #include <sstream> 15 #include <time.h> 16 #define x first 17 #define y second 18 #define pb push_back 19 #define mp make_pair 20 #define lson l,m,rt*2 21 #define rson m+1,r,rt*2+1 22 #define mt(A,B) memset(A,B,sizeof(A)) 23 #define mod 1000000007 24 using namespace std; 25 typedef long long LL; 26 const int N=2e5+10; 27 const int inf = 0x3f3f3f3f; 28 const LL INF=0x3f3f3f3f3f3f3f3fLL; 29 int x[N]; 30 int n,a,b,ans,res_2=inf; 31 32 33 void dfs(int cur,int num) 34 { 35 int p=0,q; 36 if(cur==n-1) 37 { 38 ans=min(ans,num); 39 return; 40 } 41 if(x[cur-1]<0)dfs(cur+1,num); 42 43 if(x[cur-1]>=0) 44 { 45 p=x[cur-1]/b+1; 46 x[cur-1]-=p*b; 47 x[cur]-=p*a; 48 x[cur+1]-=p*b; 49 dfs(cur+1,num+p); 50 x[cur-1]+=p*b; 51 x[cur]+=p*a; 52 x[cur+1]+=p*b; 53 } 54 q=x[cur]/a+1; 55 if(x[cur]>=0&&q>p) 56 { 57 for(int i=p+1;i<=q;i++) 58 { 59 x[cur-1]-=i*b; 60 x[cur]-=i*a; 61 x[cur+1]-=i*b; 62 dfs(cur+1,num+i); 63 x[cur]+=i*a; 64 x[cur+1]+=i*b; 65 x[cur-1]+=i*b; 66 } 67 } 68 } 69 int main() 70 { 71 #ifdef Local 72 freopen("data.txt","r",stdin); 73 #endif 74 int p=0,q=0; 75 cin>>n>>a>>b; 76 ans=inf; 77 for(int i=0; i<n; i++)scanf("%d",&x[i]); 78 p=x[0]/b+1; 79 x[0]-=p*b;; 80 x[1]-=p*a; 81 x[2]-=p*b; 82 if(x[n-1]>=0) 83 { 84 q=x[n-1]/b+1; 85 x[n-2]-=q*a; 86 x[n-3]-=q*b; 87 x[n-1]-=q*b; 88 } 89 dfs(1,0); 90 if(ans==inf)ans=0; 91 cout<<ans+p+q<<endl; 92 #ifdef Local 93 cerr << "time: " << (LL) clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl; 94 #endif 95 } View Code

?

轉載于:https://www.cnblogs.com/27sx/p/6266128.html

總結

以上是生活随笔為你收集整理的1489 蜥蜴和地下室的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。