E. Expenditure Reduction
从左右往右找到包含B字符的最近位置,然后从这个位置有从右到左找回去找到包含完所有B字符的位置,这个区间就是答案
#include <bits/stdc++.h> #define inf 0x3f3f3f3f #define endl '\n' #define int long long using namespace std; const int N = 1e6+10, M = 998244353; //typedef long long ll; typedef pair<int,int> PII; int n,m,t,k; map<int,int> mp; priority_queue<int> QQ; deque<int> Q; int ksm(int a,int b,int mod){ int res = 1; a %= mod; while(b){ if(b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } void solve() { string a,b; cin >> a >> b; int l = 0, r = a.size() - 1, pos = 0; for(int i = 0;i < a.size();i++){ if(a[i] == b[pos]) pos++; if(pos == b.size()){ r = i; break; } } pos --; //cout << pos << endl; for(int i = r;i >= 0;i--){ if(a[i] == b[pos]) pos--; if(pos == -1){ l = i; break; } } //cout << l << ' ' << r << endl; cout << a.substr(l, r - l + 1) << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); int Ke_scholar = 1; cin >> Ke_scholar; while(Ke_scholar--) solve(); return 0; } /* */View Code
G. Gua!
签到题,注意细节.
#include<bits/stdc++.h> //#define int long long #define endl '\n' #define PII pair<int,int> using namespace std; const int N = 2010,mod = 1e9 + 7; int n,s,v,m; void solve() { int b, r, d, s; cin >> b >> r >> d >> s; if (b == 0||r==0) { if (d)cout << "gua!" << endl; else cout << "ok" << endl; return; } int x = (d + b - 1) / b; int y = r * s / 60 + 1; //cout << x << ' ' << y << endl; if (x <= y)cout << "ok" << endl; else cout << "gua!" << endl; } int32_t main() { ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); int Ke_scholar = 1; cin >> Ke_scholar; while(Ke_scholar--)solve(); return 0; }View Code
H. Heirloom Painting
考虑最后一次涂色,必然会形成一个长度不小于
标签:Contest,int,Spring,SMU,pos,long,--,solve,define From: https://www.cnblogs.com/Kescholar/p/17501377.html