Hello 2019(有待更新)

题目链接:http://codeforces.com/contest/1097

第一题:

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

#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long

#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))

#define pii pair<ll,ll>
#define mk(x,y) make_pair(x,y)

const int  maxn =5e5+5;
const int mod=998244353;
const int ub=1e6;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

string s,a[5];

int main()
{
    cin>>s;
    int flag=0;
    for(int i=0;i<5;i++)
    {
        cin>>a[i];
        if(a[i][0]==s[0]||a[i][1]==s[1]) flag=1;
    }
    if(flag) puts("YES");
    else puts("NO");
    return 0;
}

第二题:

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

#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long

#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))

#define pii pair<ll,ll>
#define mk(x,y) make_pair(x,y)

const int  maxn =5e5+5;
const int mod=998244353;
const int ub=1e6;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

int dp[360],tmp[360],x;

int main()
{
    int n;cin>>n;
    mst(dp,0),dp[0]=1;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        mst(tmp,0);
        for(int j=0;j<360;j++)
        {
            if(dp[j]) tmp[(j-x+360)%360]=1,tmp[(j+x+360)%360]=1;
        }
        memcpy(dp,tmp,sizeof(dp));
    }
    if(dp[0]) puts("YES");
    else puts("NO");

    return 0;
}

第三题:

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

#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long

#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))

#define pii pair<ll,ll>
#define mk(x,y) make_pair(x,y)

const int  maxn =5e5+5;
const int mod=998244353;
const int ub=1e6;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

char s[maxn];
int tmp1[maxn],tmp2[maxn],res,tmp;
int main()
{
    int n;cin>>n;
    for(int i=0;i<n;i++)
    {
        scanf("%s",s);///
        int l=0,r=0,len=strlen(s);
        int flag=0;
        for(int j=0;j<len;j++)
        {
            if(s[j]=='(')
            {
                flag--;
                r++;
            }
            else
            {
                if(flag>=0) l++;
                else r--,flag++;
            }
        }
        if(!l||!r)
        {
            if(l) tmp1[l]++;
            if(r) tmp2[r]++;
        }
        if(l==0&&r==0) tmp++;
    }
    tmp>>=1;
    for(int i=0;i<maxn;i++)  res+=min(tmp2[i],tmp1[i]);
    cout<<res+tmp<<endl;

    return 0;
}

第四题:(积性函数+DP)

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

#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll unsigned long long

#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<ll,ll>
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=2e4+9;
const int ub=1e6;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
ll n,k;
ll dp[maxn][80];
int main(){
    cin>>n>>k;
    ll ans=1LL;
    mst(dp,0);
    for(ll i=2;i*i<=n;i++) if(n%i==0){
        int cnt=0;
        while(n%i==0) n/=i,cnt++;
        dp[0][0]=1LL;rep(j,1,cnt+1) dp[0][j]=dp[0][j-1]*i%mod;
        rep(j,1,cnt+1) dp[0][j]=(dp[0][j]+dp[0][j-1])%mod;
        rep(j,1,k+1){
            dp[j][0]=dp[j-1][0]%mod;
            rep(p,1,cnt+1) dp[j][p]=dp[j-1][p]*powmod(p+1,mod-2)%mod;
            if(j!=k) rep(p,1,cnt+1) dp[j][p]=(dp[j][p]+dp[j][p-1])%mod;
        }
        ans=ans*dp[k][cnt]%mod;
    }
   /// cout<<ans<<endl;
    if(n>1){
        ll inv=powmod(2LL,mod-2);
        inv=powmod(inv,k);
        n=(n-1)%mod;
        inv=inv*n%mod;
        inv=(inv+1)%mod;
        ans=ans*inv%mod;
    }
    cout<<ans<<endl;
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值