ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

牛客小白月赛36

2021-07-16 23:58:01  阅读:338  来源: 互联网

标签:const int ll 36 牛客 小白月赛 return include mod


C-杨辉三角

题目
在这里插入图片描述
杨辉三角第n行第i个元素为 C n − 1 i − 1 , 由 二 项 式 定 理 有 ( 1 + x ) n = ∑ C n i ∗ x i , 对 两 边 求 导 , n ( 1 + x ) n − 1 = ∑ i ∗ C n i ∗ x i − 1 , 继 续 求 导 , n ( n − 1 ) ( 1 + x ) n − 2 = ∑ ( i 2 − i ) ∗ C n i ∗ x i − 2 , 令 x = 1 , n ( n − 1 ) ∗ 2 n − 2 = ∑ i 2 C n i − ∑ i C n i , 易 证 ∑ C n i = n ( n − 1 ) ∗ 2 n − 3 C_{n-1}^{i-1},由二项式定理有(1+x)^n=\sum{C_{n}^{i}*x^i},对两边求导,n(1+x)^{n-1}=\sum{i*C_n^i*x^{i-1}},继续求导,n(n-1)(1+x)^{n-2}=\sum{(i^2-i)*C_n^i*x^{i-2}},令x=1,n(n-1)*2^{n-2}=\sum{i^2C_n^i}-\sum{iC_n^i},易证\sum{C_n^i}=n(n-1)*2^{n-3} Cn−1i−1​,由二项式定理有(1+x)n=∑Cni​∗xi,对两边求导,n(1+x)n−1=∑i∗Cni​∗xi−1,继续求导,n(n−1)(1+x)n−2=∑(i2−i)∗Cni​∗xi−2,令x=1,n(n−1)∗2n−2=∑i2Cni​−∑iCni​,易证∑Cni​=n(n−1)∗2n−3,用快速幂求解即可。

#include <iostream>
#include <cstring>
#include <cmath>
#include <bitset>
#include <queue>
#include <vector>
#include <cstdio>
#include <queue>
#include <sstream>
#include <string>
#include <algorithm>
#include <map>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define reps(i, a, b) for (int i = a; i >= b; i--)
#define mk make_pair
using namespace std;
const int N = 1e5 + 7;
const int M = 1e4+ 7;
const int inf = 0x3f3f3f3f;
const int mod = 99824353;
typedef long long ll;
ll power(ll a,ll b)
{
    ll ans=1;
    while(b)
    {
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}
int main()
{
    ll n;
    scanf("%lld",&n);
    if(n>=3)
    printf("%lld\n",(n%mod*((n-1)%mod))%mod*power(2,n-3)%mod);
    else{
        printf("%lld\n",n-1);
    }
    return 0;
}

E-皇城PK

题目
在这里插入图片描述
要可能成为冠军就不能输过,所以入度为0。

#include <iostream>
#include <cstring>
#include <cmath>
#include <bitset>
#include <queue>
#include <vector>
#include <cstdio>
#include <queue>
#include <sstream>
#include <string>
#include <algorithm>
#include <map>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define reps(i, a, b) for (int i = a; i >= b; i--)
#define mk make_pair
using namespace std;
const int N = 1e5 + 7;
const int M = 1e4+ 7;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
typedef long long ll;
int in[N];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    rep(i, 1, m){
        int u,v;
        scanf("%d%d",&u,&v);
        in[v]++;
    }
    int ans=0;
    rep(i, 1, n)if(!in[i])ans++;
    printf("%d\n",ans);
    return 0;
}

F-象棋

题目
在这里插入图片描述
显然每列最后只能剩下两个,然后这两个可以到后面的列里,重复让每列剩下两个然后到后面列,直到没有第三列可以攻击,即只剩2列,而每列又只有2个,所以最少4个,特判一下少于行或列只有1的情况

#include <iostream>
#include <cstring>
#include <cmath>
#include <bitset>
#include <queue>
#include <vector>
#include <cstdio>
#include <queue>
#include <sstream>
#include <string>
#include <algorithm>
#include <map>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define reps(i, a, b) for (int i = a; i >= b; i--)
#define mk make_pair
using namespace std;
const int N = 1e5 + 7;
const int M = 1e4+ 7;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
typedef long long ll;
int main()
{
    int t;
    scanf("%d",&t);
    ll n,m;
    while(t--){
        scanf("%lld%lld",&n,&m);
        if(n==1&&m==1)puts("1");
        else if(n>=2&&m>=2)puts("4");
        else puts("2");
        
    }
    return 0;
}

H-卷王之王

题目

在这里插入图片描述
线段树模板题(
刚开始觉得要区间线段树,然后感觉麻烦没写,然后大佬说单点就能过,然后就真的过了

#include <iostream>
#include <cstring>
#include <cmath>
#include <bitset>
#include <queue>
#include <vector>
#include <cstdio>
#include <queue>
#include <sstream>
#include <string>
#include <algorithm>
#include <map>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define reps(i, a, b) for (int i = a; i >= b; i--)
#define mk make_pair
using namespace std;
const int N = 1e5 + 7;
const int M = 1e3+ 7;
const int inf = 0x3f3f3f3f;
const int mod = 99824353;
typedef long long ll;

ll tree[N<<2];
ll a[N];
void pushup(int j)
{
    tree[j]=min(tree[j<<1],tree[j<<1|1]);
}
void build(int node,int l,int r)
{
    if(l==r){
        tree[node]=a[l];
        return;
    }
    int mid=(l+r)>>1;
    build(node<<1,l,mid);
    build(node<<1|1,mid+1,r);
    pushup(node);
}
void update(int node,int l,int r,int val)
{
    if(tree[node]>val)return;
    if(l==r){
        tree[node]+=val;
        return;
    }
    int mid=(l+r)>>1;
    update(node<<1,l,mid,val);
    update(node<<1|1,mid+1,r,val);
    pushup(node);
}
ll query(int node,int l,int r,int pos)
{
    if(l==r)return tree[node];
    int mid=(l+r)>>1;
    if(pos<=mid)return query(node<<1,l,mid,pos);
    else return query(node<<1|1,mid+1,r,pos);
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    rep(i,1,n)scanf("%lld",&a[i]);
    build(1,1,n);
    rep(i,1,m){
        ll x;
        scanf("%lld",&x);
        if(!x)continue;
        update(1,1,n,x);
    }
    rep(i,1,n){
        printf("%lld ", query(1,1,n,i));
    }
    puts("");
    return 0;
}

标签:const,int,ll,36,牛客,小白月赛,return,include,mod
来源: https://blog.csdn.net/qq_50377393/article/details/118830694

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有