Codeforces Round # 568 (Div. 2) elected to do

Construction ...... G to be filled pit, AB did not see estimates will not make up ^ _ ^.

Somehow it seems, in addition to the G looks a bit should not make it difficult or div3 ......

C. Exam in BerSU

The meaning of problems

To give you a length \ (n-\) sequence \ (a_i \) . For each \ (i \ in [1, N] \) seeking \ ([1, i-1 ] \) at least satisfy the remaining omitted by how many \ ([1, i] \ ) number and less than \ (M \) .

\ (n \ 2 \ cdot 10 ^ 5, M \ 2 \ cdot 10 ^ 7, a_i \ 100 \) .

Solution

See range \ (\ Le 100 \) , appears directly in buckets remember how many times each number, then scan again descending violence barrel finished it. . .

code

#include<bits/stdc++.h>
using namespace std;
priority_queue<int> q;
const int N=2e5+5;
int a[N],t[233],n,m,sum;
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i) scanf("%d",&a[i]);
    for(int i=1;i<=n;++i)
    {
        sum+=a[i];
        if(sum<=m)
        {
            ++t[a[i]];
            printf("0 ");
            continue;
        }
        int ans=0,tmp=sum;
        for(int j=100;j&&tmp>m;--j)
        {
            if(tmp-t[j]*j<=m)
            {
                printf("%d ",ans+(tmp-m-1)/j+1);
                break;
            }
            else tmp-=t[j]*j,ans+=t[j];
        }
        ++t[a[i]];
    }
}

D. Extra Element

The meaning of problems

To a length \ (n-\) is the number of columns, by deleting a number such that the number of columns of the original rearrangement of arithmetic sequence.

Solution

...... I do not know what to say, if the difference ranging from a deleted directly on the line. The first three special number may be sentenced to it.

code

#include<cstdio>
#include<algorithm>
using namespace std;
const int N=2e5+5;
int a[N],id[N];
bool cmp(int x, int y) {
    return a[x]<a[y];
}
int main()
{
    int n; scanf("%d",&n);
    for(int i=1;i<=n;++i) scanf("%d",&a[i]),id[i]=i;
    sort(id+1,id+1+n,cmp);
    sort(a+1,a+1+n);
    if(n<=3)
    {
        puts("1");
        return 0;
    }
    int del=0,cha;
    if(a[3]-a[2]!=a[2]-a[1])
    {
        if(a[3]-a[2]==a[4]-a[3])
        {
            del=1;
            cha=a[3]-a[2];
        }
        else if(a[3]-a[1]==a[4]-a[3])
        {
            del=2;
            cha=a[3]-a[1];
        }
        else if(a[2]-a[1]==a[4]-a[2])
        {
            del=3;
            cha=a[2]-a[1];
        }
        else
        {
            puts("-1");
            return 0;
        }
    }
    else cha=a[2]-a[1];
    for(int i=del?4:3;i<=n;++i)
    {
        int l=(del==i-1?i-2:i-1);
        if(a[i]-a[l]!=cha)
        {
            if(del)
            {
                puts("-1");
                return 0;
            }
            del=i;
        }
    }
    printf("%d",!del?id[1]:id[del]);
}

E. Polycarp and snakes

The meaning of problems

...... redundancy complex topic, or to directly see the original title face it ......

Solution

I do not know what to say, according to the meaning of the questions you can direct simulation. Note that some of the details.

#include<cstdio>
#include<algorithm>
using namespace std;
const int N=2005;
char s[N][N];
int x1[N],x2[N],y1[N],y2[N];
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n,m,mx=0;
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;++i) scanf("%s",s[i]+1);
        bool flag=true;
        for(int a=0;flag&&a<26;++a)
        {
            for(int i=1;i<=n;++i)
                for(int j=1;j<=m;++j)
                {
                    if(s[i][j]!=a+'a') continue;
                    if(!x1[a]&&!y1[a]) x1[a]=x2[a]=i,y1[a]=y2[a]=j;
                    else
                    {
                        x1[a]=min(x1[a],i),x2[a]=max(x2[a],i);
                        y1[a]=min(y1[a],j),y2[a]=max(y2[a],j);
                    }
                }
            if(x1[a]!=x2[a]&&y1[a]!=y2[a])
            {
                flag=false;
                break;
            }
            if(x1[a]) mx=a+1;
            else continue;
            if(x1[a]==x2[a])
            {
                for(int j=y1[a];j<=y2[a];++j)
                {
                    if(s[x1[a]][j]<a+'a') {
                        flag=false;
                        continue;
                    }
                }
            }
            else
            {
                for(int j=x1[a];j<=x2[a];++j)
                {
                    if(s[j][y1[a]]<a+'a') {
                        flag=false;
                        continue;
                    }
                }
            }
        }
        if(!flag)
        {
            puts("NO");
            for(int i=0;i<26;++i) x1[i]=y1[i]=x2[i]=y2[i]=0;
            continue;
        }
        printf("YES\n%d\n",mx);
        for(int a=0;a<mx;++a)
        {
            if(!x1[a])
            {
                bool f=true;
                for(int i=1;f&&i<=n;++i)
                    for(int j=1;f&&j<=m;++j)
                    {
                        if(s[i][j]>a+'a')
                        {
                            printf("%d %d %d %d\n",i,j,i,j);
                            f=false;
                        }
                    }
                continue;
            }
            printf("%d %d %d %d\n",x1[a],y1[a],x2[a],y2[a]);
            x1[a]=y1[a]=x2[a]=y2[a]=0;
        }
    }
}

F. Two Pizzas

The meaning of problems

There \ (n \) personal, everyone has some favorite ingredients; there \ (m \) pizzas, each pizza has a price and a number of ingredients. As little as possible at the price now want you to buy two pizzas, so as to satisfy the people as much as possible premise. A person can be satisfied if and only if all of his favorite ingredients appeared on two pizza.

Several ingredients does not exceed \ (9 \) . \ (n-, m \ Le 2 \ ^. 5 CDOT 10 \) .

Solution

Obviously, several kinds of pizza and people of no more than \ (2 ^ 9 \) , the direct use of barrels remember what each person how many each pizza minimum / second smallest price and its number. Then \ ((2 ^ 9) ^ 3 \) enumeration of pizza and two people can be. Note that some of the details.

code

#include<cstdio>
#include<cstring>
const int N=515;
int a[N],b[N],id[N],b2[N],xid[N],id1,id2,ans,cost;
inline int gi()
{
    char c=getchar(); int x=0;
    for(;c<'0'||c>'9';c=getchar());
    for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+c-'0';
    return x;
}
int main()
{
    int n=gi(),m=gi();
    for(int i=1;i<=n;++i)
    {
        int x=gi(),s=0;
        while(x--) s|=(1<<gi()-1);
        ++a[s];
    }
    memset(b,0x3f,sizeof(b));
    memset(b2,0x3f,sizeof(b2));
    for(int i=1;i<=m;++i)
    {
        int c=gi(),x=gi(),s=0;
        while(x--) s|=(1<<gi()-1);
        if(c<b[s]) b[s]=c,id[s]=i;
        else if(c<b2[s]) b2[s]=c,xid[s]=i;
    }
    cost=2e9+5;
    for(int s1=0;s1<512;++s1)
        for(int s2=0;s2<512;++s2)
        {
            if(!id[s1]||!id[s2]) continue;
            int tid1,tid2,tcost;
            if(s1==s2) tid1=id[s1],tid2=xid[s1],tcost=b[s1]+b2[s1];
            else tid1=id[s1],tid2=id[s2],tcost=b[s1]+b[s2]; 
            int ret=0;
            for(int s3=0;s3<512;++s3)
                if(((s1|s2)&s3)==s3) ret+=a[s3];
            if(ret>ans||(ret==ans&&cost>tcost)) cost=tcost,ans=ret,id1=tid1,id2=tid2;
        }
    printf("%d %d",id1,id2);
}

Guess you like

Origin www.cnblogs.com/farway17/p/11058079.html