Dwango Programming Contest V 翻车记

  A:签到。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 110
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,int m){return m==0?n:gcd(m,n%m);}
int read()
{
    int x=0,f=1;char c=getchar();
    while (c<‘0‘||c>‘9‘) {if (c==‘-‘) f=-1;c=getchar();}
    while (c>=‘0‘&&c<=‘9‘) x=(x<<1)+(x<<3)+(c^48),c=getchar();
    return x*f;
}
int n,a[N],s,ans=0;
int calc(int k){return abs(s-a[k]*n);}
int main()
{
/*#ifndef ONLINE_JUDGE
    freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);
    const char LL[]="%I64d\n";
#else
    const char LL[]="%lld\n";
#endif*/
    n=read();
    for (int i=1;i<=n;i++) s+=a[i]=read();
    for (int i=2;i<=n;i++)
    if (calc(i)<calc(ans+1)) ans=i-1;
    cout<<ans;
    return 0;
}

  B:按位从高到低贪心,对当前位数一下有多少个子区间和该位为1,如果能满足要求就将其统计入答案并删掉所有该位为0的子区间和。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 1010
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,int m){return m==0?n:gcd(m,n%m);}
int read()
{
    int x=0,f=1;char c=getchar();
    while (c<‘0‘||c>‘9‘) {if (c==‘-‘) f=-1;c=getchar();}
    while (c>=‘0‘&&c<=‘9‘) x=(x<<1)+(x<<3)+(c^48),c=getchar();
    return x*f;
}
int n,m,b[N],cnt=0;
ll a[N*N],c[N*N],ans;
int main()
{
/*#ifndef ONLINE_JUDGE
    freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);
    const char LL[]="%I64d\n";
#else
    const char LL[]="%lld\n";
#endif*/
    n=read(),m=read();
    for (int i=1;i<=n;i++) b[i]=read();
    for (int i=1;i<=n;i++)
    {
        a[++cnt]=b[i];
        for (int j=i+1;j<=n;j++)
        cnt++,a[cnt]=a[cnt-1]+b[j];
    }
    n=cnt;
    for (int j=40;~j;j--)
    {
        int s=0;
        for (int i=1;i<=n;i++)
        if (a[i]&(1ll<<j)) c[++s]=a[i];
        if (s>=m)
        {
            ans+=1ll<<j;n=s;
            for (int i=1;i<=s;i++) a[i]=c[i];
        }
    }
    cout<<ans;
    return 0;
}

  C:指针从左到右扫一遍,两个队列分别维护指针左方D的出现位置和右方C的出现位置,并记录跨过当前位置的合法D~C区间有多少个。如果指针扫到M就更新答案,扫到D将其加入左边队列并统计以该位置为左端点的合法D~C区间数量,扫到C将其弹出右边队列并统计以该位置为右端点的合法D~C区间数量,拿两个指针记录两个队列中能产生贡献的边界位置即可做到线性。为啥atcoder不define ONLINE_JUDGE啊白交了一发。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 1000010
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,int m){return m==0?n:gcd(m,n%m);}
int read()
{
    int x=0,f=1;char c=getchar();
    while (c<‘0‘||c>‘9‘) {if (c==‘-‘) f=-1;c=getchar();}
    while (c>=‘0‘&&c<=‘9‘) x=(x<<1)+(x<<3)+(c^48),c=getchar();
    return x*f;
}
int n,q,m,a[N],b[N],c[N];
char s[N];
int main()
{
    n=read();scanf("%s",s+1);
    for (int i=1;i<=n;i++)
    if (s[i]==‘D‘) a[i]=0;
    else if (s[i]==‘M‘) a[i]=1;
    else if (s[i]==‘C‘) a[i]=2;
    else a[i]=-1;
    q=read();
    while (q--)
    {
        m=read();
        int hb=1,tb=0,hc=1,t=0,tc=0;ll ans=0,cur=0;
        for (int i=1;i<=n;i++) if (a[i]==2) b[++tb]=i;
        for (int i=1;i<=n;i++)
        if (a[i]==1) ans+=cur;
        else if (a[i]==0)
        {
            c[++tc]=i;
            while (t<tb&&b[t+1]-i+1<=m) t++;
            cur+=t-hb+1;
        }
        else if (a[i]==2)
        {
            while (hc<=tc&&i-c[hc]+1>m) hc++;
            cur-=tc-hc+1;
            hb++;
        }
        cout<<ans<<endl;
    }
    return 0;
}

  D:好像还不太会啊。

  E:没看。

  感觉atcoder赛制不是非常友好啊。result:rank 185 rating +352

原文地址:https://www.cnblogs.com/Gloid/p/10013769.html

时间: 2024-10-08 21:50:36

Dwango Programming Contest V 翻车记的相关文章

【AtCoder】Dwango Programming Contest V题解

A - Thumbnail 根据题意写代码 #include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define pdi pair<db,int> #define mp make_pair #define pb push_back #define enter putchar('\n') #define space putchar(' ') #define

NIKKEI Programming Contest 2019 翻车记

A:签到. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> using namespace std; int gcd(int n,int m){return m==0?n:gcd(m,n%m);} int read() { int x=0,f=1;char c=getc

Dwango Programming Contest 6th C

Cookie Distribution 题意概述 : 有 \(N\) 个孩子,用 \(K\) 天给孩子们发糖果 第 \(i\) 天有 \(a_i\) 个糖果,等概率地发给这 \(n\) 个孩子(每一天每个孩子最多可以获得一个糖果),设 \(K\) 天后第 \(i\) 个孩子获得的糖果为 \(c_i\) 求 \(\prod_{i = 1}^n c_i\) 的期望乘上 \(\prod_{i = 1}^n \binom N {a_i}\) ,答案对 \(10^9 + 7\) 取模.. \(N \le

Dwango Programming Contest 6th Task C. Cookie Distribution

The answer is number of N-tuples (d[1], d[2], ..., d[N]) in all outcomes, where d[i] means on which day the i-th child get a cookie. Now consider in how many outcomes is there a particular N-tuple (d[1], d[2], ..., d[N]) as described. The answer turn

Dwango Programming Contest 6th -B

期望 按每个空隙计算 对于第$i$个空隙 对于第$j$个跨过这段的概率是$\frac{1}{i-j+1}$ 因为跨过当且仅当$[j+1,i]$之间都不先于$j$合并 求一个逆元前缀和即可 #include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5, P = 1e9 + 7; int n; int x[maxn], inv[maxn]; int main() { ios::sync_with_stdio(false

[Dwango Programming Contest 6th C] Cookie Distribution

传送门 组合意义,妙啊(弱菜 swk 不会数数实锤了 考虑 \(\prod c_i\) 的组合意义,它代表每个孩子在他得到的饼干中选择一个拿出来,最终的方案数. 因此得到了一个几乎显然的 dp: 设 \(f_{i, j}\) 为前 \(i\) 天,有 \(j\) 个孩子已经 "选择了" 他的饼干的方案数.转移时枚举新增了 \(u\) 个孩子,则转移系数是一系列组合数,详见代码. #include <bits/stdc++.h> #define R register #def

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 建筑 你哥哥在最近的建筑问题突破大会上获得了一个奖项 并获得了千载难逢的重新设计城市中心的机会 他最喜欢的城市奈梅根.由于城市布局中最引人注目的部分是天际线, 你的兄弟已经开始为他想要北方和东方的天际线画一些想法

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, JUST Collegiate Programming Contest (2018)

ACM International Collegiate Programming Contest, JUST Collegiate Programming Contest (2018) B. New Assignment 有n个人(1?≤?n?≤?104),有男有女,每个人都有一个id,现在这n个人分成学习互助小组,有三种组队模式,一个男人一组,一个女人一组,一男一女一组,如果要一男一女一组,那么这两人id的gcd要>1.保证任意三个人的gcd=1.求小组的组数最少是多少? 看起来是一个很裸的二