Loading

ABC460

A

按照题意模拟即可。

// Author: heffo_hard
#include <bits/stdc++.h>
#define up(a,b,c) for(int (a)=(b);(a)<=(c);(a)=-~(a))
#define dn(a,b,c) for(int (a)=(b);(a)>=(c);(a)=~-(a))
#define fst first
#define sed second
#define pref static inline
#define gc() p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++
using namespace std;
using hint = __int128;
using pii = pair<int, int>;
using us = unsigned short;
using ldb = long double;
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using pll = pair<ll, ll>;
using pil = pair<int, ll>;
using vpil = vector<pil>;
using vl = vector<ll>;
using pli = pair<ll, int>;
using vpli = vector<pli>;
using vi = vector<int>;
using vpi = vector<pii>;
using vpl = vector<pll>;
using db = double;
int n,m;
namespace mystl {
    char buf[1 << 20],*p1 = buf,*p2 = buf, sr[1 << 23], z[23], nc;
    int C =-1, Z = 0;
    template<typename T>pref void read(T & x){
        bool flag = false;
        while (nc = gc(), (nc<48 || nc> 57) && nc !=-1) flag |= (nc == 45); 
        x = nc - 48;
        while (nc = gc(), 47 < nc && nc < 58) x = (x << 3) + (x << 1) + (nc ^ 48); 
        if (flag) x = -x;
    }
    pref void read(char* s) {
        char ch = gc();
        while(ch <= 32) ch = gc();
        int i = 0;
        while(ch > 32) {
            s[i++] = ch;
            ch = gc();
        }
        s[i] = '\0';
    }
    pref void read(string &s) {
        s.clear();
        char ch = gc();
        while(ch <= 32) ch = gc();
        while(ch > 32) {
            s += ch;
            ch = gc();
        }
    }
    pref void read(char &ch) {
        ch = gc();
        while(ch <= 32) ch = gc();
    }
    
    template<typename T, typename ... Args_Arrays_Typename_heffo_hard>
    void read(T & x, Args_Arrays_Typename_heffo_hard & ...a){read(x); read(a...);}
    
    pref void ot(){fwrite(sr, 1, C + 1, stdout ); C = -1;}
    pref void flush(){if (C > 1 << 22) ot();} 
    template<typename T>pref void write(T x) {
        if constexpr (is_same<T, char>::value) {
            sr[++C] = x;
        } else if constexpr (is_same<T, const char*>::value || is_same<T, char*>::value) {
            for(int i = 0; x[i]; ++i) sr[++C] = x[i];
        } else if constexpr (is_same<T, string>::value) {
            for(char c : x) sr[++C] = c;
        } else {
            int y = 0;
            if (x < 0) y = 1, x = -x;
            Z = 0;
            do {
                z[++Z] = x % 10 + 48;
                x /= 10;
            } while (x);
            if (y) z[++Z] = '-';
            while (Z) sr[++C] = z[Z--];
        }
        flush();
    }
    
    template<typename T>pref void write(T x, char t) {
        write(x);
        sr[++C] = t;
        flush();
    }
    
    pref void write(const char* s) {
        for(int i = 0; s[i]; ++i) sr[++C] = s[i];
        flush();
    }
    
    pref void write(string s) {
        for(char c : s) sr[++C] = c;
        flush();
    }
    
    pref ll qpow(ll a, ll b, ll p){
        if (a == 0) return 0;
        ll c = 1ll;
        while (b){
            if (b & 1) c = a * c % p; 
            a = a * a % p; 
            b >>= 1;
        } 
        return c;
    }
    
    pref ll lcm(ll x, ll y){
        return x / std:: __gcd(x, y) * y;
    }
};
using namespace mystl;
namespace my {
    constexpr int P = static_cast<int>(998244353);
    pref void madd(int & x, int y){x = (x + y >= P) ? (x + y - P) : (x + y);}
    pref int fmadd(int x, int y){return (x + y >= P) ? (x + y - P) : (x + y);}
    pref void msub(int & x, int y){x = (x < y) ? (x - y + P) : (x - y);}
    pref int fmsub(int x, int y){return (x < y) ? (x - y + P) : (x - y);}
    pref void mmul(int & x, int y){x = (int)(1ll * x * y % P);}
    pref int fmmul(int x, int y){return (int)(1ll * x * y % P);}
    
    template<typename T>pref T min(T x, T y){return (x < y) ? (x) : (y);}
    template<typename T>pref T max(T x, T y){return (x > y) ? (x) : (y);}
    template<typename T>pref T abs(T x){return (x < 0) ? (-x) : (x);}
    
    constexpr int N = static_cast<int>(0), inf = static_cast<int>(0x3f3f3f3f3f);

    pref void solve(){
        int ans=0;
        while(m){
            m=n%m;
            ans++;
        }
        write(ans);
    }
}
int main(){
    //  freopen("","r",stdin);
    //  freopen("","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    read(n,m);
    my::solve();
    ot();
    return 0;
}
/*

*/

B

这是一道不错的数学题。
怎么判断两个圆是否相交呢?先来画个图。

容易发现,他们圆心距小于两个圆的半径之和。
可以等于半径之和吗?没有问题,此时长这样。

但是这样就结束了吗?没有。还有可能长这样。

同样考虑能否取等,发现可以,长这样。

因为要排除这种情况,所以圆心距应该要大于半径之差的绝对值。
首先求出圆心距 \(dis=\sqrt{(x1-x2)^2+(y1-y2)^2}\)
然后判断 \(dis\) 的范围即可。

// Author: heffo_hard
#include <bits/stdc++.h>
#define up(a,b,c) for(int (a)=(b);(a)<=(c);(a)=-~(a))
#define dn(a,b,c) for(int (a)=(b);(a)>=(c);(a)=~-(a))
#define fst first
#define sed second
#define pref static inline
#define gc() p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++
using namespace std;
using hint = __int128;
using pii = pair<int, int>;
using us = unsigned short;
using ldb = long double;
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using pll = pair<ll, ll>;
using pil = pair<int, ll>;
using vpil = vector<pil>;
using vl = vector<ll>;
using pli = pair<ll, int>;
using vpli = vector<pli>;
using vi = vector<int>;
using vpi = vector<pii>;
using vpl = vector<pll>;
using db = double;
ll t,x,y,x2,y2,r1,r2;
namespace mystl {
    char buf[1 << 20],*p1 = buf,*p2 = buf, sr[1 << 23], z[23], nc;
    int C =-1, Z = 0;
    template<typename T>pref void read(T & x){
        bool flag = false;
        while (nc = gc(), (nc<48 || nc> 57) && nc !=-1) flag |= (nc == 45); 
        x = nc - 48;
        while (nc = gc(), 47 < nc && nc < 58) x = (x << 3) + (x << 1) + (nc ^ 48); 
        if (flag) x = -x;
    }
    pref void read(char* s) {
        char ch = gc();
        while(ch <= 32) ch = gc();
        int i = 0;
        while(ch > 32) {
            s[i++] = ch;
            ch = gc();
        }
        s[i] = '\0';
    }
    pref void read(string &s) {
        s.clear();
        char ch = gc();
        while(ch <= 32) ch = gc();
        while(ch > 32) {
            s += ch;
            ch = gc();
        }
    }
    pref void read(char &ch) {
        ch = gc();
        while(ch <= 32) ch = gc();
    }
    
    template<typename T, typename ... Args_Arrays_Typename_heffo_hard>
    void read(T & x, Args_Arrays_Typename_heffo_hard & ...a){read(x); read(a...);}
    
    pref void ot(){fwrite(sr, 1, C + 1, stdout ); C = -1;}
    pref void flush(){if (C > 1 << 22) ot();} 
    template<typename T>pref void write(T x) {
        if constexpr (is_same<T, char>::value) {
            sr[++C] = x;
        } else if constexpr (is_same<T, const char*>::value || is_same<T, char*>::value) {
            for(int i = 0; x[i]; ++i) sr[++C] = x[i];
        } else if constexpr (is_same<T, string>::value) {
            for(char c : x) sr[++C] = c;
        } else {
            int y = 0;
            if (x < 0) y = 1, x = -x;
            Z = 0;
            do {
                z[++Z] = x % 10 + 48;
                x /= 10;
            } while (x);
            if (y) z[++Z] = '-';
            while (Z) sr[++C] = z[Z--];
        }
        flush();
    }
    
    template<typename T>pref void write(T x, char t) {
        write(x);
        sr[++C] = t;
        flush();
    }
    
    pref void write(const char* s) {
        for(int i = 0; s[i]; ++i) sr[++C] = s[i];
        flush();
    }
    
    pref void write(string s) {
        for(char c : s) sr[++C] = c;
        flush();
    }
    
    pref ll qpow(ll a, ll b, ll p){
        if (a == 0) return 0;
        ll c = 1ll;
        while (b){
            if (b & 1) c = a * c % p; 
            a = a * a % p; 
            b >>= 1;
        } 
        return c;
    }
    
    pref ll lcm(ll x, ll y){
        return x / std:: __gcd(x, y) * y;
    }
};
using namespace mystl;
namespace my {
    constexpr int P = static_cast<int>(998244353);
    pref void madd(int & x, int y){x = (x + y >= P) ? (x + y - P) : (x + y);}
    pref int fmadd(int x, int y){return (x + y >= P) ? (x + y - P) : (x + y);}
    pref void msub(int & x, int y){x = (x < y) ? (x - y + P) : (x - y);}
    pref int fmsub(int x, int y){return (x < y) ? (x - y + P) : (x - y);}
    pref void mmul(int & x, int y){x = (int)(1ll * x * y % P);}
    pref int fmmul(int x, int y){return (int)(1ll * x * y % P);}
    
    template<typename T>pref T min(T x, T y){return (x < y) ? (x) : (y);}
    template<typename T>pref T max(T x, T y){return (x > y) ? (x) : (y);}
    template<typename T>pref T abs(T x){return (x < 0) ? (-x) : (x);}
    
    constexpr int N = static_cast<int>(0), inf = static_cast<int>(0x3f3f3f3f3f);
	pref ll dis(ll x,ll y,ll x2,ll y2){
            return (x-x2)*(x-x2)+(y-y2)*(y-y2);
	}
    pref void solve(){
        while(t--){
            read(x,y,r1,x2,y2,r2);
        if(dis(x,y,x2,y2)<=(r1+r2)*(r1+r2)&&dis(x,y,x2,y2)>=(r2-r1)*(r2-r1))//由于double有精度误差,所以我把平方挪到了右边,同时解决了绝对值的问题
            puts("Yes");
            else puts("No");
        }
    }
}
int main(){
    //  freopen("","r",stdin);
    //  freopen("","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    read(t);
    my::solve();
    ot();
    return 0;
}
/*

*/

C

考虑贪心。
把权值按从小到大排序,然后枚举每个 shari,找到合适的 neta,如果找不到就直接结束,因为往后枚举依然会找不到合适的 neta。

// Author: heffo_hard
#include <bits/stdc++.h>
#define up(a,b,c) for(int (a)=(b);(a)<=(c);(a)=-~(a))
#define dn(a,b,c) for(int (a)=(b);(a)>=(c);(a)=~-(a))
#define fst first
#define sed second
#define pref static inline
#define gc() p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++
using namespace std;
using hint = __int128;
using pii = pair<int, int>;
using us = unsigned short;
using ldb = long double;
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using pll = pair<ll, ll>;
using pil = pair<int, ll>;
using vpil = vector<pil>;
using vl = vector<ll>;
using pli = pair<ll, int>;
using vpli = vector<pli>;
using vi = vector<int>;
using vpi = vector<pii>;
using vpl = vector<pll>;
using db = double;
const ll MAXN=2E5+5;
ll n,m,a[MAXN],b[MAXN];
namespace mystl {
    char buf[1 << 20],*p1 = buf,*p2 = buf, sr[1 << 23], z[23], nc;
    int C =-1, Z = 0;
    template<typename T>pref void read(T & x){
        bool flag = false;
        while (nc = gc(), (nc<48 || nc> 57) && nc !=-1) flag |= (nc == 45); 
        x = nc - 48;
        while (nc = gc(), 47 < nc && nc < 58) x = (x << 3) + (x << 1) + (nc ^ 48); 
        if (flag) x = -x;
    }
    pref void read(char* s) {
        char ch = gc();
        while(ch <= 32) ch = gc();
        int i = 0;
        while(ch > 32) {
            s[i++] = ch;
            ch = gc();
        }
        s[i] = '\0';
    }
    pref void read(string &s) {
        s.clear();
        char ch = gc();
        while(ch <= 32) ch = gc();
        while(ch > 32) {
            s += ch;
            ch = gc();
        }
    }
    pref void read(char &ch) {
        ch = gc();
        while(ch <= 32) ch = gc();
    }
    
    template<typename T, typename ... Args_Arrays_Typename_heffo_hard>
    void read(T & x, Args_Arrays_Typename_heffo_hard & ...a){read(x); read(a...);}
    
    pref void ot(){fwrite(sr, 1, C + 1, stdout ); C = -1;}
    pref void flush(){if (C > 1 << 22) ot();} 
    template<typename T>pref void write(T x) {
        if constexpr (is_same<T, char>::value) {
            sr[++C] = x;
        } else if constexpr (is_same<T, const char*>::value || is_same<T, char*>::value) {
            for(int i = 0; x[i]; ++i) sr[++C] = x[i];
        } else if constexpr (is_same<T, string>::value) {
            for(char c : x) sr[++C] = c;
        } else {
            int y = 0;
            if (x < 0) y = 1, x = -x;
            Z = 0;
            do {
                z[++Z] = x % 10 + 48;
                x /= 10;
            } while (x);
            if (y) z[++Z] = '-';
            while (Z) sr[++C] = z[Z--];
        }
        flush();
    }
    
    template<typename T>pref void write(T x, char t) {
        write(x);
        sr[++C] = t;
        flush();
    }
    
    pref void write(const char* s) {
        for(int i = 0; s[i]; ++i) sr[++C] = s[i];
        flush();
    }
    
    pref void write(string s) {
        for(char c : s) sr[++C] = c;
        flush();
    }
    
    pref ll qpow(ll a, ll b, ll p){
        if (a == 0) return 0;
        ll c = 1ll;
        while (b){
            if (b & 1) c = a * c % p; 
            a = a * a % p; 
            b >>= 1;
        } 
        return c;
    }
    
    pref ll lcm(ll x, ll y){
        return x / std:: __gcd(x, y) * y;
    }
};
using namespace mystl;
namespace my {
    constexpr int P = static_cast<int>(998244353);
    pref void madd(int & x, int y){x = (x + y >= P) ? (x + y - P) : (x + y);}
    pref int fmadd(int x, int y){return (x + y >= P) ? (x + y - P) : (x + y);}
    pref void msub(int & x, int y){x = (x < y) ? (x - y + P) : (x - y);}
    pref int fmsub(int x, int y){return (x < y) ? (x - y + P) : (x - y);}
    pref void mmul(int & x, int y){x = (int)(1ll * x * y % P);}
    pref int fmmul(int x, int y){return (int)(1ll * x * y % P);}
    
    template<typename T>pref T min(T x, T y){return (x < y) ? (x) : (y);}
    template<typename T>pref T max(T x, T y){return (x > y) ? (x) : (y);}
    template<typename T>pref T abs(T x){return (x < 0) ? (-x) : (x);}
    
    constexpr int N = static_cast<int>(0), inf = static_cast<int>(0x3f3f3f3f3f);

    pref void solve(){
        up(i,1,n)read(a[i]);
        up(i,1,m)read(b[i]);
        sort(a+1,a+1+n);
        sort(b+1,b+1+m);
        ll j=1,ans=0,ans1=0;
        up(i,1,n){//为每个shari找到合适的neta
            ll t=2*a[i];
            if(t<b[j]){
                continue;
            }else{
                ans++;
                j++;
                if(j==m+1)break;
            }
        }
        ll i=1;
        up(j,1,m){//这部分可以不写,赛时为了保险写的
            db t=b[j]*1.0/2;
            if(t>a[i])continue;
            else{
                ans1++;
                i++;
                if(i==n+1)break;
            }
        }
        write(max(ans,ans1));
    }
}
int main(){
    //  freopen("","r",stdin);
    //  freopen("","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    read(n,m);
    my::solve();
    ot();
    return 0;
}
/*
贪心的正确性:从小到大排序,对于每个shari,都寻找最小且满足条件的neta,这样最节省,尽量要当前的shari,因为如果不要,那么这个shari相当于白白浪费了,如果当前权值太大,那么往后考虑依然会更大,所以直接结束
*/
posted @ 2026-05-31 17:22  heffo_hard  阅读(30)  评论(0)    收藏  举报