牛客小白月赛25

牛客小白月赛25

A AOE还是单体?

#include <bits/stdc++.h>

#define int ll
typedef long long ll;
const int INF = 0x3f3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;
const int N = 50;
using namespace std;

int a[maxn];

void solve() {
    int n,x,sum=0;
    cin>>n>>x;
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    int top=n;
    while (top>n-x&&top>0) sum+=a[--top];
    cout<<sum;
}

signed main() {
//    ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
    int _ = 1;
//    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

B k-size字符串

 
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
ll power(ll a,ll b){
    ll res=1;
    while(b){
        if(b&1)res=res*a%mod;
        b>>=1,a=a*a%mod;
    }
    return res;
}
ll inv(ll x){return power(x,mod-2);}
ll C(ll a,ll b){
    ll t=1;
    for(int i=1;i<=b;i++)t=t*(a-i+1)%mod*inv(i)%mod;
    return t;
}
ll f(ll n,ll m){
    if(n<=0||m<0)return 0;
    return C(n+m-1,m);
}
int main(){
    ll n,m,k;
    cin>>n>>m>>k;
    if(k&1)
        cout<<(f(k/2+1,n-k/2-1)*f(k/2,m-k/2)+f(k/2,n-k/2)*f(k/2+1,m-k/2-1))%mod;
    else cout<<2*f(k/2,n-k/2)*f(k/2,m-k/2)%mod;
}

C 白魔法师

#include <bits/stdc++.h>

#define int ll
typedef long long ll;
const int INF = 0x3f3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;
const int N = 50;
using namespace std;

int n,fa[maxn],num[maxn];
char s[maxn];
vector<int >g[maxn];

int findfa(int x){
    return fa[x]==x?x:fa[x]=findfa(fa[x]);
}

void solve() {
    cin>>n>>s+1;
    for(int i=1;i<=n;i++)fa[i]=i,num[i]=1;
    for(int i=1,u,v;i<n;i++){
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
        if (s[v]=='W'&&s[u]=='W'){
            int fx=findfa(u),fy=findfa(v);
            if (fx!=fy) fa[fx]=fy,num[fy]+=num[fx];
        }
    }
    int max_=0;
    for (int i = 1; i< n; ++i) {
        int res=1;
        if (s[i]=='W'){
            res=num[findfa(i)];
        } else{
            for(int j=0;j<g[i].size();j++){
                int v=g[i][j];
                if (s[v]=='W') res+=num[findfa(v)];
            }
        }
        max_=max(res,max_);
    }
    cout<<max_;
}

signed main() {
//    ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
    int _ = 1;
//    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

D 抽卡

#include <bits/stdc++.h>

#define int ll
typedef long long ll;
const int INF = 0x3f3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;
const int N = 50;
using namespace std;

int aa[maxn],bb[maxn];

//逆元
int power(int a,int b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
int inv(int x){return power(x,mod-2);}

void solve() {
    int n,sum=1;
    cin>>n;
    for (int i = 0; i < n; ++i) cin>>aa[i];
    for (int i = 0; i < n; ++i) cin>>bb[i];
    for (int i = 0; i < n; ++i)
        sum=sum*(aa[i]-bb[i])%mod*inv(aa[i])%mod;
    cout<<(mod+1-sum)%mod;
}

signed main() {
//    ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
    int _ = 1;
//    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

E 点击消除

#include <bits/stdc++.h>

#define int ll
typedef long long ll;
const int INF = 0x3f3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 3e5 + 10;
const int N = 50;
using namespace std;

char a[maxn];

void solve() {
    string s;
    cin>>s;
    int top=0;
    a[0]=s[0];
    for (int i = 1; i < s.size(); ++i) a[top]==s[i]?top--:a[++top]=s[i];
    if (top==-1) cout<<0;
    for (int i = 0; i <=top; ++i) cout<<a[i];
}

signed main() {
//    ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
    int _ = 1;
//    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

F 疯狂的自我检索者

#include <bits/stdc++.h>

#define int ll
typedef long long ll;
const int INF = 0x3f3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;
const int N = 50;
using namespace std;

void solve() {
    int n,m,sum=0;
    cin>>n>>m;
    for(int i=0;i<n-m;i++){
        int x;
        cin>>x;
        sum+=x;
    }
     cout<<setiosflags(ios::fixed)<<setprecision(5)<<(sum+m)*1.0/n<<" "<<1.0*(sum+m*5)/n;
}

signed main() {
//    ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
    int _ = 1;
//    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

G 解方程

#include <bits/stdc++.h>

#define int ll
typedef long long ll;
const int INF = 0x3f3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;
const int N = 50;
using namespace std;

void solve() {
    long double a,b,c;
    cin>>a>>b>>c;
    long double l=0,r=1e9,mid;
    while (r-l>1e-8){
        mid=(l+r)/2;
        long  double y=pow(mid,a)+b*log(mid);
        if (y<c) l=mid;
        else r=mid;
    }
    cout<<setprecision(8)<<mid;//设置保留8位小数
}

signed main() {
//    ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
    int _ = 1;
//    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

H 神奇的字母(二)

#include <bits/stdc++.h>

#define int ll
typedef long long ll;
const int INF = 0x3f3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;
const int N = 50;
using namespace std;

int a[30]={0};

void solve() {
    string s;
    while (cin>>s)
        for (int i = 0; i < s.size(); ++i)  
            a[s[i]-'a']++;
    int max_=0;
    for (int i = 0; i < 26; ++i) 
        if (a[max_]<a[i]) 
            max_=i;
    cout<<(char)(max_+'a');
}

signed main() {
//    ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
    int _ = 1;
//    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

I 十字爆破

#include <bits/stdc++.h>

#define int ll
typedef long long ll;
const int INF = 0x3f3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;
const int N = 50;
using namespace std;

vector<int > a[maxn];
int nn[maxn],mm[maxn];

void solve() {
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++) nn[i]=0;
    for(int i=0;i<m;i++) mm[i]=0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <m; ++j) {
            int x;
            cin>>x;
//            a[i][j]=x;
            a[i].push_back(x);
            nn[i]+=x;
            mm[j]+=x;
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cout << nn[i] + mm[j] - a[i][j]<<" ";
        }
        cout << endl;
    }
}

signed main() {
//    ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
    int _ = 1;
//    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

J 异或和之和

#include <bits/stdc++.h>

#define int ll
typedef long long ll;
const int INF = 0x3f3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 5e5 + 10;
const int N = 50;
using namespace std;

int on[70]={0};
int n,sum=0;

int c(int a){
    if (a<2||n<3) return 0;
    return ((n-a>1?(n-a)*a*(n-a-1)/2:0)%mod+(a>2?a*(a-1)*(a-2)/6:0)%mod)%mod;
}

void solve() {
    cin>>n;
    for (int i = 0,x,b; i < n; ++i) {
        cin>>x,b=0;
        while (x) x&1?on[b]++:0,b++,x>>=1;
    }
    for (int i = 0,k=1; i < 64; ++i,k*=2)
        sum+=k%mod*c(on[i]),sum%=mod;
    cout<<sum;
}

signed main() {
    ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
    int _ = 1;
//    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值