9.11总结

· · 个人记录

9.11总结

成绩

「MSOI R1」回响 [ECNA 2024] Oooh I See [PacNW 2025] Training, Round 4 [入门赛 #50] 数论对称差 [ICPC 2017 Hong Kong R] Card collection 得分 排名
100 100 0 0 0 200 6

[PacNW 2025] Training

题目传送门 ::::error[错误代码]

无

::::error[错误思路] 无 ::::

::::success[正确思路] 维护 l,r(两⽅向已达标⾼度)、cnt(剩余免费升级数)、 ans(初始等级和),初 值取第 1 题的两个难度且 cnt=1;⾃第 2 题起逐题处理:若新难度⾼于对应前缀最⼤值,先⽤ 池⼦补⻬,补不上的部分累⼊ ans ;本题处理完后 cnt+=1。 ::::

::::success[正确代码]

#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,c[55],t[55],ans,a,b,cnt=1;
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)cin>>c[i]>>t[i];
    a=c[1],b=t[1];
    ans=a+b;
    for(int i=2;i<=n;i++){
        if(c[i]>a)
        {
            if(c[i]-a<=cnt)cnt-=(c[i]-a),a=c[i];
            else a+=cnt,cnt=0,ans+=c[i]-a,a=c[i];
        }
        if(t[i]>b){
            if(t[i]-b<=cnt)cnt-=(t[i]-b),b=t[i];
            else b+=cnt,cnt=0,ans+=t[i]-b,b=t[i];
        }
        cnt++;
    }
    cout<<ans;
    return 0;
}

::::

[入门赛 #50] 数论对称差

题目传送门 ::::error[错误代码]

#include<bits/stdc++.h>
using namespace std;
int T;
void solve()
{
    int n,m,f=0;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(n%i==0 and n%j!=0 and m%i!=0 and m%j==0 and f==0)
            {
                cout<<i*j<<'\n';
                f=1;
            }
        }
        if(f==1)
        {
            break;
        }
    }
    if(f==0)
    {
        cout<<1<<'\n';
    }
}
int main()
{
    cin>>T;
    while(T--)
    {
        solve();
    }
    return 0;
}

::::

::::error[错误思路] 想了一下,只能暴力 ::::

::::success[正确思路] 预处理出 cnt[v]=rad(u) (u\le10^7);每组查询令a=cnt[x]、b=cnt[y]、g=gcd(a,b),输出(a/g) ⋅ (b/g)。 ::::

::::success[正确代码]

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e7+10;
int cnt[N],vis[N];
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    for(int i=1;i<=1e7;i++)
    {
        cnt[i]=1;
    }
    for(int i=2;i<=1e7;i++)
    {
        if(vis[i]==0)
        {
            for(int j=i;j<=1e7;j+=i)
            {
                vis[j]=1;
                cnt[j]*=i; 
            }
        }
    }
    int t;
    cin>>t;
    while(t--)
    {
        int x,y;
        cin>>x>>y;
        x=cnt[x];
        y=cnt[y];
        cout<<x*y/__gcd(x,y)/__gcd(x,y)<<'\n'; 
    }
    return 0;
}

::::