A.最长下坡
#include <cstdio>
int a[1000];
int main(){
int n, ans = 0, now = 0;scanf("%d", &n);
for(int i = 1; i <= n; ++i){
int x;scanf("%d", &x);a[i] = a[n + i] = x;
}
for(int i = 2; i <= n * 2; ++i){
if (a[i] < a[i - 1]) ++now;
else{
if (now > ans) ans = now;
now = 0;
}
}
printf("%d\n", ans);
return 0;
}
B.斗地主大师
#include <iostream>
#include <cstdio>
using namespace std;
long long inf = 1000000000;
long long p, q, x, y, ans = inf;
void dfs(long long now, long long cnt){
if (cnt > 52) return;
if (now == p){
ans = min(ans, cnt);
return;
}
if (now % y == 0) dfs(now / y, cnt + 1);
dfs(now + x, cnt + 1);
}
int main(){
cin>>p>>q>>x>>y;
dfs(q, 0);
if (ans == inf) cout<<"Failed"<<endl;
else cout<<ans<<endl;
return 0;
}
C.通配符匹配
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
bool f(string s, string p){
int len = s.length();
for (int i = 0; i < len; ++i){
if (p[i] == s[i]);
else if (p[i] == '?');
else if(p[i] != '*') return false;
else{
int tmp = i;
while (p[tmp] == '*') ++tmp;
for (int j = i; j <= len; ++j)
if (f(s.substr(j, len - j), p.substr(tmp, len - tmp)))
return true;
return false;
}
}
if(p.length() == len) return true;
return false;
}
int main(){
int T;cin>>T;while(T--){
string s, p;cin>>s>>p;
if (f(s, p)) cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
return 0;
}
标签:cnt,include,int,long,期末,2022,ans,now,程设
From: https://www.cnblogs.com/w-official/p/18183030