牛客训练赛41

A
因为Bob可以换翻一个硬币,除了n=m时的情况,都能弄出有正面的硬币情况

#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t;
    cin >> t;
    while(t--) {
        int n, m;
        cin >> n >> m;
        if(n == m) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

C
因为每个点形成的是单向边,所以最后会形成不同的联通块,用并查集维护联通块内权值

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
typedef long long ll;
int a[maxn];
int fa[maxn], tot;
ll ans[maxn], v[maxn];
int find(int x) {
    return x == fa[x] ? x : fa[x] = find(fa[x]);
}
bool cmp(ll a, ll b) {
    return a > b;
}
int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; ++i) {
        fa[i] = i;
        scanf("%d", &a[i]);
    }
    for(int u = 1; u <= n; ++u) {
        int v;
        scanf("%d", &v);
        int fau = find(u), fav = find(v);
        if(fau == fav) continue;
        fa[min(fau, fav)] = max(fau, fav);
    }
    for(int i = 1; i <= n; ++i)
        v[find(i)] += a[i];
    for(int i = 1; i <= n; ++i)
        if(v[i]) ans[tot++] = v[i];
    sort(ans, ans + tot, cmp);
    ll res = 0;
    for(int i = 0; i < min(m, tot); ++i) {
        res += ans[i];
    }
    cout << res << endl;
}

E
球冠的体积

#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);

struct ball{
    double x,y,z,r;
    ball(double x=0,double y=0,double z=0,double r=0):x(x),y(y),z(z),r(r){}
    double dist(ball a){
        return sqrt((x-a.x)*(x-a.x)+(y-a.y)*(y-a.y)+(z-a.z)*(z-a.z));
    }
    double v(){
        return pi*r*r*r*4/3;
    }
}a,b;

double solve(){
    double d = a.dist(b);
    if(d-a.r-b.r>0)return a.v()+b.v();
    double r1=a.r,r2=b.r;
    if(d + r1 < r2 || d + r2 < r1) return max(a.v(), b.v());
    double v1=pi/3*(r1-(r1*r1-r2*r2+d*d)/(2*d))*(r1-(r1*r1-r2*r2+d*d)/(2*d));
    v1 *= 3*r1- (r1-(r1*r1-r2*r2+d*d)/(2*d));
    double v2=pi/3*(r2-(r2*r2-r1*r1+d*d)/(2*d))*(r2-(r2*r2-r1*r1+d*d)/(2*d));
    v2 *= 3*r2- (r2-(r2*r2-r1*r1+d*d)/(2*d));
    return a.v()+b.v()-(v1+v2);
}
int main(){

    scanf("%lf%lf%lf%lf",&a.x,&a.y,&a.z,&a.r);
    scanf("%lf%lf%lf%lf",&b.x,&b.y,&b.z,&b.r);
    printf("%.7f\n",solve());
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值