diverta 2019 Programming Contest

AB

签到(A是a-b problem就不放code了)

#include<bits/stdc++.h>
using namespace std;
int r,g,b,n,ans;
int main()
{
    cin>>r>>g>>b>>n;
    for(int i=0;i*r<=n;i++)
    for(int j=0;i*r+j*g<=n;j++)
    if((n-i*r-j*g)%b==0)ans++;
    cout<<ans<<endl;
}

C

签到,首先把所有字符串内部的AB加上,然后记录3种字符串的个数:仅头是B,仅尾是A,头是B且尾是A,然后把第3种顺次连接,其余加上取个min

#include<bits/stdc++.h>
using namespace std;
int n,ans,s1,s2,s3;
char s[15];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%s",s+1);
        int len=strlen(s+1);
        for(int i=1;i<len;i++)if(s[i]==‘A‘&&s[i+1]==‘B‘)ans++;
        if(s[1]==‘B‘&&s[len]==‘A‘)s3++;
        else if(s[1]==‘B‘)s1++;
        else if(s[len]==‘A‘)s2++;
    }
    if(s3)
    {
        ans+=s3-1;
        if(s1)s1--,ans++;
        if(s2)s2--,ans++;
    }
    cout<<ans+min(s1,s2)<<endl;
}

D

知道n=[n/m]*m+n%m这道题就是签到题了,设[n/m]=n%m=x,然后n=x(m+1),O(√n)枚举因数即可

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,ans;
void judge(ll m,ll x)
{
    if(!m)return;
    if(n/m==x&&n%m==x)ans+=m;
}
int main()
{
    cin>>n;
    for(ll i=1;i*i<=n;i++)
    if(n%i==0)
    {
        judge(i-1,n/i);
        if(i*i<n)judge(n/i-1,i);
    }
    cout<<ans;
}

E

要使每一段异或起来相等,实际上就等价于每一段每一位为1的个数的奇偶性相同。设a[i]为前i个数的异或和。然后如果a[n]!=0,显然只能分成奇数段,然后a[n]为0的位,每一段该位偶数个,a[n]不为0的位,每一段该位奇数个1,然后取断点的值,发现就是a[n] 0 a[n] 0…a[n],然后建两颗线段树,分奇偶讨论一下即可。a[n]=0,可奇可偶,奇数段的话,每一个断点a[i]都要为0,偶数段则是交替x 0 x 0…x 0,然后考虑断开处x=0的情况,可以统计a[i]=0(1<=i<n)的个数x,答案是2x,若x!=0,把x分类,DP一下,遇到0总方案加上前面f[i]的和即可,比较麻烦,细节见code。

#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N=5e5+7,M=1048600,mod=1e9+7;
struct tree{
    int sum[N<<2];
    void build(int l,int r,int rt)
    {
        if(l==r){sum[rt]=(l==0);return;}
        int mid=l+r>>1;
        build(lson),build(rson);
        sum[rt]=(sum[rt<<1]+sum[rt<<1|1])%mod;
    }
    void update(int k,int v,int l,int r,int rt)
    {
        if(l==r){sum[rt]=v;return;}
        int mid=l+r>>1;
        if(k<=mid)update(k,v,lson);else update(k,v,rson);
        sum[rt]=(sum[rt<<1]+sum[rt<<1|1])%mod;
    }
    int query(int L,int R,int l,int r,int rt)
    {
        if(L<=l&&r<=R)return sum[rt];
        int ret=0,mid=l+r>>1;
        if(L<=mid)ret=(ret+query(L,R,lson))%mod;
        if(R>mid)ret=(ret+query(L,R,rson))%mod;
        return ret;
    }
}tr[2];
int n,ans,psum,tot,a[N],s[20][N],sum[N],pw[N],f[N];
vector<int>G[M];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    for(int i=0;i<20;i++)for(int j=1;j<=n;j++)s[i][j]=(s[i][j-1]+((a[j]>>i)&1))%2;
    int flag=0;
    for(int i=0;i<20;i++)if(s[i][n])flag=1;
    if(!flag)
    {
        int n0=1,lst=0;
        for(int i=1;i<=n;i++)a[i]^=a[i-1];
        for(int i=1;i<n;i++)
        if(!a[i])n0=2ll*n0%mod,sum[i]=sum[i-1]+1;else G[a[i]].push_back(i),sum[i]=sum[i-1];
        for(int v=1;v<(1<<20);v++)
        if(G[v].size())
        {
            int sz=G[v].size(),pre=0;
            for(int i=0;i<sz;i++)f[i]=0;
            f[0]=1,ans=(ans+1)%mod;
            for(int i=1;i<sz;i++)
            {
                int s0=sum[G[v][i]-1]-sum[G[v][i-1]];
                pre=(pre+1ll*f[i-1]*s0)%mod;
                ans=(ans+pre+1)%mod;
                f[i]=(f[i-1]+pre+1)%mod;
            }
        }
        ans=(ans+n0)%mod;
        printf("%d\n",ans);
        return 0;
    }
    tr[0].build(0,n,1);
    tr[1].build(0,n,1);
    tr[1].update(0,0,0,n,1);
    for(int i=1;i<=n;i++)
    {
        int s1=0,dif=0,add;
        for(int j=0;j<20;j++)
        {
            if(s[j][i])s1++;
            if(s[j][i]!=s[j][n])dif++;
        }
        if(!s1)add=tr[1].query(0,i-1,0,n,1),tr[0].update(i,add,0,n,1);
        if(!dif)add=tr[0].query(0,i-1,0,n,1),tr[1].update(i,add,0,n,1);
    }
    ans=tr[1].query(n,n,0,n,1);
    printf("%d\n",ans);
}

F

只有IOI2017 rank1会做,咕了。

result:rank67(?)网卡了等结果出了再更。

原文地址:https://www.cnblogs.com/hfctf0210/p/10850419.html

时间: 2024-11-09 05:46:42

diverta 2019 Programming Contest的相关文章

【AtCoder】diverta 2019 Programming Contest

diverta 2019 Programming Contest 因为评测机的缘故--它unrated了.. A - Consecutive Integers #include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define

diverta 2019 Programming Contest 2自闭记

A 签到(a-b problem不用贴了吧,以后atcoder小于300分题均不贴代码) B 发现选择的p,q一定是其中两点间的距离,于是可以O(n2)枚举两点,再O(n2)判断,其实可以做到O(n3)不过O(n4)就够了. #include<bits/stdc++.h> using namespace std; typedef long long ll; int n,ans; ll x[52],y[52]; int main() { scanf("%d",&n);

diverta 2019 Programming Contest 2

A:签到. #include<bits/stdc++.h> using namespace std; #define ll long long #define inf 1000000010 char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;} int gcd(int n

[AtCoder] NIKKEI Programming Contest 2019 (暂缺F)

[AtCoder] NIKKEI Programming Contest 2019 ??本来看见这一场的排名的画风比较正常就来补一下题,但是完全没有发现后两题的AC人数远少于我补的上一份AtCoder. A - Subscribers ??首先始终 \(max = \min(A, B)\) ,\(min\) 的话如果 \(A + B \leq N\) ,那么就是 \(0\) ,否则就是 \(A + B - N\) . int n, a, b; int main() { read(n), read

2020-3-14 acm训练联盟周赛Preliminaries for Benelux Algorithm Programming Contest 2019 解题报告+补题报告

2020-3-15比赛解题报告+2020-3-8—2020-3-15的补题报告 2020-3-15比赛题解 训练联盟周赛Preliminaries for Benelux Algorithm Programming Contest 2019  A建筑(模拟) 耗时:3ms 244KB 建筑 你哥哥在最近的建筑问题突破大会上获得了一个奖项 并获得了千载难逢的重新设计城市中心的机会 他最喜欢的城市奈梅根.由于城市布局中最引人注目的部分是天际线, 你的兄弟已经开始为他想要北方和东方的天际线画一些想法

ZOJ 3703 Happy Programming Contest(0-1背包)

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3703 Happy Programming Contest Time Limit: 2 Seconds      Memory Limit: 65536 KB In Zhejiang University Programming Contest, a team is called "couple team" if it consists of only two s

Happy Programming Contest zoj3703 dp

Description In Zhejiang University Programming Contest, a team is called "couple team" if it consists of only two students loving each other. In the contest, the team will get a lovely balloon with unique color for each problem they solved. Sinc

ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syria, Lattakia, Tishreen University, April, 30, 2018

ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syria, Lattakia, Tishreen University, April, 30, 2018 Problem A. Can Shahhoud Solve it? Problem B. Defeat the Monsters Problem C. UCL Game Night Problem

The 2018 ACM-ICPC China JiangSu Provincial Programming Contest快速幂取模及求逆元

题目来源 The 2018 ACM-ICPC China JiangSu Provincial Programming Contest 35.4% 1000ms 65536K Persona5 Persona5 is a famous video game. In the game, you are going to build relationship with your friends. You have N friends and each friends have his upper b