A LCM Problem standard input/output 2 s, 256 MB Submit x14222
看了一下,发现最小的LCM x,y 应该有一个是L, 当连续两个数 则 LCM为 L*(L+1) 如果是L 2L 那么LCM为2L,明显是最小的 如果 L 2L 不在 L R中那么无解, 否则输出 L 2L即可
B Array Walk standard input/output 2 s, 256 MB Submit x4503
相当于 每次不往左走的话,能直接从 a1 走到 ak+1, 然后当a1到 ak+1 如果有两个连续的值和大于 ak+ak+1的话就用最大的和替换掉 ak+ak+1,
然后因为替换了 多走了两步, 所以最多只能走到ak-2 以此类推
因为总数小于3e5 所以可以直接枚举
两种方法枚举,
第一种 枚举向左走的步数0-z,每次能到的位置为 k-2*z+1 然后记录下所有走过的步值总和 和 最大的相邻两步之和,向左的两步都走最大和 O(zk)
第二种 枚举步数0-k 然后每次记录每次能向左走的步数 储存最大值 O(k)
还可以用dp, dp[i][j] 走到第 i 处,向左走了 j 步 O(kz)
状态转移方程为 dp[i][j] = max(dp[i][j], dp[i-1][j]+a[i]); 向左走一步
if(i!=0 and j+1!=z) dp[i-1][j+1] = max(dp[i-1][j+1], dp[i][j]+a[i-1]); 从向右走一步
C Good String standard input/output 2 s, 256 MB Submit x5918
变换一下, 会发现 一个good string 是这样的 s2s3s4s5s6s7……sns1 == sns1s2s3s4s5s6s7……sn-1, 对应一下也就是 s1 == s3 == sn-1 == s5 == s7
s2 == s4 == s6 == sn, good string 就是一个循环节<=2 的字符串, 然后字符串的字符为 0-9 那么我们可以直接暴力枚举所有的循环节情况 一共 (10*10) 100种, 然后找到最长的good string, 总长度减去最长的good string即可, 代码如下 O(100*|s|) |s| <= 2e5
D Segment Intersections standard input/output 2 s, 256 MB Submit x1044 不想补。。。
#include<bits/stdc++.h> using namespace std; #define ll long long #define _for(i,a,b) for(int i = (a); i < (b); i++) #define _rep(i,a,b) for(int i = (a); i <= (b); i++)
void taskA() { ios::sync_with_stdio(false), cin.tie(nullptr); int t; cin >> t; while(t--) { int l, r; cin >> l >> r; if(l*2 <= r) cout << l << " " << 2*l << " "; else cout << "-1 -1 "; } return; }
void taskB1() { int t; cin >> t; while(t--) { int n,k,z; cin >> n >> k >> z; vector<int> a(n+1); _rep(i,1,n) cin >> a[i]; int ans = 0; _rep(z1,0,z) { int x = 1, x1 = 0; int y = k+1-2*z1, ma = 0, s = 0; if(y < 1) continue; _for(i,1,y+1) { ma = max(ma, a[i]+a[i+1]), s += a[i]; } ans = max(ans, s+ma*z1); } //ans += a[y]; cout << ans << " "; } return; }
void taskB2() { int t; cin >> t; while(t--) { int n,k,z; cin >> n >> k >> z; vector<int> a(n, 0); _for(i,0,n) cin >> a[i]; int s = 0, mx = 0, ans = 0; _rep(i,0,k) { if(i<n-1) mx = max(mx, a[i]+a[i+1]); s += a[i]; if(i%2 == k%2) { int tmp = (k-i)/2; if(tmp <= z) ans = max(ans, s+mx*tmp); } } cout << ans << " "; } return; }
void taskB3() { int t; cin >> t; while(t--) { int n,k,z; cin >> n >> k >> z; int dp[k+1][z+1] = {}; vector<int> a(n); _for(i,0,n) cin >> a[i]; _for(i,0,z) dp[0][i] = 0; _rep(i,1,k) _rep(j,0,z) { int pos = k-i-2*j; if(pos<0 or pos>=n) { dp[i][j] = (-1e9); continue; } dp[i][j] = max(dp[i][j], dp[i-1][j]+a[pos+1]); if(pos!=0 and j!=z) dp[i][j] = max(dp[i][j], dp[i-1][j+1]+a[pos-1]); } int ans = 0; _rep(i,0,z) ans = max(ans, dp[k][i]); cout << ans+a[0] << " "; } return; }
void taskB3() { int t; cin >> t; while(t--) { int n,k,z; cin >> n >> k >> z; int dp[k+1][z+1] = {}; vector<int> a(n); _for(i,0,n) cin >> a[i]; _for(i,0,z) dp[0][i] = 0; int ans = 0; _rep(i,1,k) _rep(j,0,z) { dp[i][j] = max(dp[i][j], dp[i-1][j]+a[i]); if(i+2*j == k) ans = max(ans, dp[i][j]); if(j+1 <= z) dp[i-1][j+1] = max(dp[i-1][j+1], dp[i][j]+a[i-1]); if(i-1+2*(j+1) == k) ans = max(ans, dp[i-1][j+1]); } cout << ans+a[0] << " "; } return; }
void taskC() { int t; cin >> t; while(t--) { string s; cin>>s; int n = s.size(), ans = 0; _for(i,0,10) { int ma = 0; _for(j,0,10) { int x = i, y = j, res = 0; for(auto c : s) if(c-'0' == x) res++, swap(x, y);//妙啊 上一个匹配成功换下一个 if(x!=y and res%2==1) res--;// 如果总数有多类似 12121 那么需要-1 ans = max(ans, res); } } cout << n-ans << " "; } return; }
int main() { ios::sync_with_stdio(false), cin.tie(nullptr); // taskB3();
taskC(); return 0; }