广告和题解(穷学生)

米哈游内推https://jobs.mihoyo.com/m/?recommendationCode=NDE3&isRecommendation=true#/campus/position 字节内推https://job.toutiao.com/campus/m/position?external_referral_code=5ECMF2N

A略

B,中学知识,所有3的倍数,均满足每个位的数值之和也是3的倍数 void solve(){ int n; string m; cin>>n; vector num(n); int ans= 0; if0(n){ cin>>m; if0(m.size()){ ans += m[i]-'0'; } } if(ans%3==0) cout<<"YES"<<endl; else cout<<"NO"<<endl;

} c,这是这套题中我觉得最对我最有提升的题目,下面是gpt教我的,要使得误差小于1e-6,就至少要保留6位小数。

在C++中,默认情况下,使用std::cout输出double类型的数值时,显示的有效数字位数通常是6位。这意味着无论小数点前后各有多少位,std::cout会显示6位有效数字

其次解答就是分类讨论

void solve(){
    int x,y,t,a,b,c;
    cin>>x>>y>>t>>a>>b>>c;
    //直接充电
    double ans1 = (100-x)*1./b;
    //边玩边冲
    double ans2 = (100-x)*1./a;
    //先降低至t
    double ans3 = (x-t)*1./y;
    ans3 = max(0.,ans3);
    ans3 += (100- min(x,t))*1./c;
    double ans = min(ans1,min(ans2,ans3));
    cout<<fixed<<setprecision(6)<<ans<<endl;
}

a

D

考点,高精度除法,如何快速计算大数的gcd,这里考虑其中有一个数比较小,那么以它为突破点,将b分解成质因子,然后用a去尝试做除法,查看模数是否为0,

/*
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
typedef  pair<int,int> pi ;
#define if1(x) for(int i =1 ;i<=x;i++)
#define if0(x) for(int i = 0;i<x;i++)
#define jf0(x) for(int j = 0;j<x;j++)
#define jf1(x) for(int j = 1;j<=x;j++)
#define pb push_back
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int N = 2e5+10;

// A / b = C ... r, A >= 0, b > 0
vector<int> div(vector<int> &A, int b, int &r)//高精度除法模板,建议留存?我反正是翻资料的
{
    vector<int> C;
    r = 0;
    for (int i = A.size() - 1; i >= 0; i -- )
    {
        r = r * 10 + A[i];
        C.push_back(r / b);
        r %= b;
    }
    reverse(C.begin(), C.end());
    while (C.size() > 1 && C.back() == 0) C.pop_back();
    return C;
}

void solve(){
    int m,n;
    string a;
    int b;
    cin>>a>>b;
    vector<int> aa;//存大数
    for(int i = a.size() - 1; i >= 0; i--)
        aa.push_back(a[i]-'0');
    vector<pi> yz;//(因子,次数)
    
    for(int i = 2;i <=b;i++){
        if(b%i == 0) {
            int cnt = 0;
            while(b%i == 0)b/=i,cnt++;
            yz.push_back({i,cnt});
        }
    }//将b分解位若干个质数之积
    vector<int> yyz;//a和b的公共因子
    int ans = 1;
    for(auto j:yz){
        int r;
        auto t = div(aa,j.first,r);
        int cnt=0;
        while(r == 0&&cnt < j.second){//不断计算a,b的公共因子数,这里是用相除余数是0,并且这个质数还得是b的因子
            ans*=j.first;
            aa = t;
            t = div(aa,j.first,r);
            cnt++;//这个质数的个数
        }
    }
    cout<<ans<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr); 
    int t=1;
    // cin>>t;
    // cout<<12345678%6<<endl;
    while (t--)
    {
        solve();
    }
    
    return 0;
}

E,二分+bfs,比较典,如果做不出来,可能就是做少了,好像还有许多其他做法,

/*
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
typedef  pair<int,int> pi ;
#define if1(x) for(int i =1 ;i<=x;i++)
#define if0(x) for(int i = 0;i<x;i++)
#define jf0(x) for(int j = 0;j<x;j++)
#define jf1(x) for(int j = 1;j<=x;j++)
#define pb push_back
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int N = 500+10;
int mp[N][N];
bool vis[N][N];
int m,n;
int x[4] = {1,0,-1,0},y[4] = {0,1,0,-1};
bool check(int u)
{
    if(mp[1][1] > u) return 0;
    queue<pi> mq;
    if1(n)jf1(n) vis[i][j] = 0;
    vis[1][1] = 1;
    mq.push({1,1});
    while(!mq.empty()){
        auto [a,b] = mq.front();
        mq.pop();
        if0(4){
            int aa = a+x[i];
            int bb = b +y[i];
            if(aa>0&&bb>0&&aa<=n&&bb<=n&&!vis[aa][bb]&&mp[aa][bb]<=u){
                mq.push({aa,bb});
                vis[aa][bb] = 1;
                if(aa ==n&&bb == n)return 1;
            }
        }
        
    }
    return 0;

}
void solve(){
    cin>>n;
    if1(n)jf1(n)cin>>mp[i][j];
    int l = 1,r = 1e9+10;
    while(l<r){
        int mid = l+r>>1;
        if(check(mid)){
            r =mid;
        }
        else l = mid+1;
    }
    cout<<l<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr); 
    int t=1;
    // cin>>t;
    while (t--)
    {
        solve();
    }
    
    return 0;
}