暑假-S组-第六场总结

· · 个人记录

T1

  1. 这题我们可以用因式拆分求出公式。
  2. 再特判c>n为-1,即可。
    #include<bits/stdc++.h>
    using namespace std;
    int main(){
     ios::sync_with_stdio(0);
     cin.tie(0);
     cout.tie(0);
     long long c,n;
     cin>>c>>n;
     if(c>n){
         cout<<-1;
         return 0;
     }else{
         long long s=n/c;
         cout<<max(s,1ll)*c*max((s-1),1ll)*c;
     }
     return 0;
    }

    T2

  3. 我们可以通过观察样例知道将"ABC"中的A移到最后,所以我们直接统计"A"和""B"的个数即可。
  4. 错因:只找了"A"的个数。
    
    #include<bits/stdc++.h>
    using namespace std;
    #define int long long
    string s;
    signed main(){
     ios::sync_with_stdio(0);
     cin.tie(0);
     cout.tie(0);
     int n;
     cin>>s;
     n=s.size();
     int cnt=0,sum=0;
     for(int i=0;i<s.size();i++){
         if(s[i]=='A'){
             sum++;
         }else if(s[i]=='B'){
             if(i+1<n&&s[i+1]=='C'){
                 cnt+=sum;
                 i++;
             }else{
                 sum=0;
             }
         }else{
             sum=0;
         }
     }
     cout<<cnt;
     return 0;
    }
# [T3](https://www.luogu.com.cn/problem/U388936)
1. 这题分为40分的暴力和60分的二分。
2. 通过数据范围,我们可以知道结果最多三位,针对于每一个x,因为 b要尽可能的大,越大的b进制,此时转化的十进制数字就越大,所及具有单调性,可以考虑二分,check 否得到之前的y。
3. 错因:写暴力去了。
```cpp
#include <bits/stdc++.h>
using namespace std;
#define int long long
int ww(int x, int k){
    int now, temp;
    now = 0, temp = 1;  
    while (x){
        if (x % k >= 10){
            return -1;
        }
        now += temp * (x % k);
        x /= k;
        temp *= 10; 
    }
    return now;
}
int check(int x, int k){
    return x % 10 + (x / 10 % 10) * k + (x / 100) * k * k;
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int x, y, i, ans, l, r, mid;
    ans = 10;
    cin >> x >> y;
    for (i = y; i <= 999; i++){
        l = 1e6 - 1, r = (int)(1e18 + 1);  
        if (i >= 100){
            r = 1e9 + 1;
        }
        while (l + 1 < r){
            mid = (l + r) / 2;
            if (check(i, mid) >= x){
                r = mid;
            }else{
                l = mid;
            }
        }
        if (check(i, r) == x){
            ans = max(ans, r);
        }
    }
    for (i = 1000000; i >= ans; i--){
        if (ww(x, i) >= y){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}