Codeforces Round #567 (Div. 2)

A

Sign (code not posted)

PS: After cf div2A (and sometimes B) and atcoder <= 200 points (sometimes <= 300) of the subject is no longer posted code, but probably did not record a few matches.

B

Precision, enumerated shortest possible number of bits, then the two can be calculated.

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+7;
struct node{int n,a[N];}ans,a,b;
int n,mn;
vector<int>G;
char s[N];
bool check(node a,node b)
{
    if(a.n!=b.n)return a.n<b.n;
    for(int i=a.n;i;i--)
    if(a.a[i]<b.a[i])return 1;
    else if(a.a[i]>b.a[i])return 0;
    return 0;
}
node operator+(node a,node b)
{
    if(a.n<b.n)swap(a,b);
    for(int i=1;i<=a.n;i++)
    {
        a.a[i]+=b.a[i];
        if(a.a[i]>=10)a.a[i]-=10,a.a[i+1]++;
    }
    if(a.a[a.n+1])a.n++;
    return a;
}
void split(int p)
{
    a.n=p;
    for(int i=1;i<=p;i++)a.a[p-i+1]=s[i]-'0';
    for(int i=p+1;i<N;i++)a.a[i]=0;
    b.n=n-p;
    for(int i=p+1;i<=n;i++)b.a[n-i+1]=s[i]-'0';
    for(int i=n-p+1;i<N;i++)b.a[i]=0;
    a=a+b;
    if(check(a,ans))ans=a;
}
int main ()
{
    scanf("%d",&n);
    if(n==2){cin>>n,cout<<n/10+n%10;return 0;}
    scanf("%s",s+1);
    mn=n+2,ans.n=n+2;
    for(int i=1;i<n;i++)
    if(s[i+1]!='0')
    {
        int len=max(i,n-i);
        if(len<mn)mn=len,G.clear(),G.push_back(i);
        else if(len==mn)G.push_back(i);
    }
    for(int i=0;i<G.size();i++)split(G[i]);
    for(int i=ans.n;i;i--)printf("%d",ans.a[i]);
}
View Code

C

It too hard, just to be engaged in a self-closing, WA 3 fat, mainly too much detail. It is actually a simple O (nm) DP, f [i] [j] expressed as (i, j) is the number of the lower right corner of the flag, then u [i] [j] denotes the distance of the same color is going up, attention from the first stage is> = rear ends, rather than =, the second WA made here. A first length of hair is not only allowed the determination color. The third issue is the length by default to a 1. Seriously affect the mentality to do problems.

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1007;
int n,m,u[N][N];
ll ans,f[N][N];
char a[N][N];
int check(int i,int j)
{
    you len = and [i] [j];
    i-=u[i][j];
    if(u[i][j]!=len)return 0;
    i-=u[i][j];
    return len*(u[i][j]>=len);
}
int main ()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)scanf("%s",a[i]+1);
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
    if(i==1||a[i][j]!=a[i-1][j])u[i][j]=1;
    else u[i][j]=u[i-1][j]+1;
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
    {
        int v=check(i,j);
        if(!v)continue;
        f[i][j]=1;
        if(j>1&&v==check(i,j-1)&&a[i][j]==a[i][j-1]&&a[i-v][j]==a[i-v][j-1]&&a[i-2*v][j]==a[i-2*v][j-1])f[i][j]+=f[i][j-1];
        years + = f [i] [j];
    }
    cout << years;
}
View Code

D

Offline is clearly, to ask from small to large, then sweep sweep to record when the first layers (if the sentence is completely filled with special moment, very simple qwq), for the rest of the number, you can do a weights tree line.

In fact, this problem can really reinforce and strengthen the law n is set to 1e5, and then force online (really say this is my first thought, but more difficult to write).

#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
typedef long long ll;
const int N=5e5+7;
struct node{ll x;int id;}q[N];
int n,m,Q,mx,ans[N],sum[N<<2],sz[N];
ll s[N];
vector<int>G[N];
bool cmp(node a,node b){return a.x<b.x;}
void update(int k,int l,int r,int rt)
{
    if(l==r){sum[rt]=1;return;}
    int mid=l+r>>1;
    if(k<=mid)update(k,lson);else update(k,rson);
    sum[rt]=sum[rt<<1]+sum[rt<<1|1];
}
int query ( int v, int s, int r, int rt)
{
    if(l==r)return l;
    int mid=l+r>>1;
    if(v>sum[rt<<1])return query(v-sum[rt<<1],rson);
    return query(v,lson);
}
int main ()
{
    scanf("%d%d%d",&n,&m,&Q);
    for(int i=1,x;i<=n;i++)scanf("%d",&x),s[x]++,mx=max(mx,(int)s[x]);
    for(int i=1;i<=m;i++)G[s[i]].push_back(i);
    for(int i=1;i<=Q;i++)scanf("%I64d",&q[i].x),q[i].id=i,q[i].x-=n;
    sort(q+1,q+Q+1,cmp);
    for(int i=0;i<=mx;i++)sort(G[i].begin(),G[i].end()),s[i]=0;
    sz[0]=G[0].size();for(int i=1;i<=mx;i++)sz[i]=sz[i-1]+G[i].size();
    s[0]=sz[0];for(int i=1;i<=mx;i++)s[i]=s[i-1]+sz[i];
    for(int i=0;i<G[0].size();i++)update(G[0][i],1,m,1);
    for(int i=1,p=0;i<=Q;i++)
    if(s[mx]<q[i].x)ans[q[i].id]=(q[i].x-s[mx]-1)%m+1;
    else{
        while(p<=mx&&s[p]<q[i].x)
        {
            p++;
            for(int i=0;i<G[p].size();i++)update(G[p][i],1,m,1);
        }
        if(p)q[i].x-=s[p-1];
        ans[q[i].id]=query(q[i].x,1,m,1);
    }
    for(int i=1;i<=Q;i++)printf("%d\n",ans[i]);
}
View Code

E

Goo.

result: rank37 rating + = 157, after all, this is my first four numbers ......

Guess you like

Origin www.cnblogs.com/hfctf0210/p/11037203.html