Walking Robot
生活随笔
收集整理的這篇文章主要介紹了
Walking Robot
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
https://codeforces.com/contest/1154/problem/D
題意:有個機(jī)器人在0位置處,現(xiàn)在要走到位置n。機(jī)器人現(xiàn)在有一個電池容量為a,還有一個蓄電池容量為b(一開始都是滿的)。數(shù)組的值代表此處有沒有光照。走一格耗1電量,如果機(jī)器人使用電池行走并在太陽下時,蓄電池電量+1.(不能超過容量),求最遠(yuǎn)的行走距離
題解:思維+模擬
有些翻譯問題;在這里我們認(rèn)為,電池是不能充電,蓄電池是可以充電的
1、一般情況下、遇到0,先用蓄電池,蓄電池沒有電再用電池;(可再生資源和不可再生資源的問題)
2、si==1的是一般情況下、用電池通過,蓄電池充電;
3、si==1并且蓄電池滿的情況下,蓄電池通過,因為你電池通過,蓄電池也不能充電,還不如用掉,為后面的充電留出空間;
/* *@Author: STZG *@Language: C++ */ #include <bits/stdc++.h> #include<iostream> #include<algorithm> #include<cstdlib> #include<cstring> #include<cstdio> #include<string> #include<vector> #include<bitset> #include<queue> #include<deque> #include<stack> #include<cmath> #include<list> #include<map> #include<set> //#define DEBUG #define RI register int #define endl "\n" using namespace std; typedef long long ll; //typedef __int128 lll; const int N=200000+10; const int M=100000+10; const int MOD=1e9+7; const double PI = acos(-1.0); const double EXP = 1E-8; const int INF = 0x3f3f3f3f; int t,n,m,k,p,l,r,u,v; int ans,cnt,flag,temp,sum; int a,b,s[N]; char str; struct node{}; int main() { #ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout); #endif//ios::sync_with_stdio(false);//cin.tie(0);//cout.tie(0);//scanf("%d",&t);//while(t--){scanf("%d%d%d",&n,&b,&a);int A=a,B=b;for(int i=1;i<=n;i++){scanf("%d",&s[i]);}for(int i=1;i<=n;i++){if(s[i]){if(A==a){A--;}else if(B){B--;A=min(A+1,a);}else if (A) {A--;}else{cout<<i-1<<endl;return 0;}}else{if(A||B){if(A)A--;else B--;}else{cout<<i-1<<endl;return 0;}}//cout<<B<<A<<endl;}cout<<n<<endl;//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC); #endif//cout << "Hello world!" << endl;return 0; }?
總結(jié)
以上是生活随笔為你收集整理的Walking Robot的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Gourmet Cat
- 下一篇: Two Teams