| #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; |
| } |
| #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; |
| } |
| #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; |
| } |
用背包的思想,f数组记录到达 f[i] 有几种方法,g数组记录当前这一步从哪里转移。
(感谢lyt倾情讲解orz
| #include <bits/stdc++.h> |
| #define int long long |
| using namespace std; |
| |
| const int inf = 1000000000; |
| int n, m, maxx = inf, num; |
| int a[2000], f[50000], g[50000]; |
| |
| void print(int i){ |
| cout<<i<<' '<<f[i]<<endl; |
| vector<int> v; |
| for (int j = i; j; j = g[j]){ |
| v.push_back(j); |
| } |
| int sum = 0, cnt = 1; |
| while (!v.empty()){ |
| |
| int now = v.back() - sum;v.pop_back(); |
| while (a[cnt] != now) ++cnt; |
| cout<<cnt<<' ';sum += now; |
| } |
| cout<<endl; |
| } |
| |
| signed main(){ |
| cin>>n>>m; |
| for (int i = 1; i <= n; ++i){ |
| cin>>a[i]; |
| if (a[i] < m) continue; |
| if (a[i] == maxx) ++num; |
| if (a[i] < maxx) num = 1, maxx = a[i]; |
| } |
| f[0] = 1; |
| for (int i = 1; i <= n; ++i){ |
| for (int j = m * 2 - 1; j >= a[i]; --j){ |
| if (f[j - a[i]]){ |
| f[j] += f[j - a[i]]; |
| g[j] = j - a[i]; |
| } |
| } |
| } |
| for (int i = m; i < m * 2; ++i){ |
| if (f[i]){ |
| if (f[i] == 1) print(i); |
| else cout<<i<<' '<<f[i]<<endl; |
| return 0; |
| } |
| } |
| if (num == inf) cout<<0<<endl; |
| else cout<<num<<endl; |
| return 0; |
| } |
| #include <cstdio> |
| #include<iostream> |
| #include<algorithm> |
| using namespace std; |
| |
| int a[200000]; |
| |
| int main(){ |
| int T;cin>>T;while(T--){ |
| int n, k, cnt = 1, b = 0;cin>>n>>k; |
| for(int i = 1;i <= n;++i){ |
| cin>>a[i]; |
| } |
| sort(a + 1, a + n + 1); |
| for(int i = n - 1; i >= 1; --i){ |
| if (k >= a[n] - a[i]){ |
| k -= a[n] - a[i]; |
| ++cnt; |
| } |
| else{ |
| cout<<cnt<<endl; |
| b = 1;break; |
| } |
| } |
| if(!b) cout<<n<<endl; |
| } |
| return 0; |
| } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效