[Simulation NOIP 20] explanations

Greetings from Dage ......

A. Week

Study class problem, do not completely QAQ

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
int n;
ll a[25],b[25],c[25],d[25],ans;
void dfs(int step,ll mdx,ll lhb)
{
    if(step>n)
    {
        ans=max(ans,mdx*lhb);
        return ;
    }
    //cout<<mdx<<' '<<lhb<<endl;
    dfs(step+1,mdx+a[step]>0?mdx+a[step]:0,lhb-b[step]>0?lhb-b[step]:0);
    dfs(step+1,mdx-d[step]>0?mdx-d[step]:0,lhb+c[step]>0?lhb+c[step]:0);
    return ;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%lld%lld%lld%lld",&a[i],&b[i],&c[i],&d[i]);
    dfs(1,0,0);
    cout<<ans<<endl;
    return 0;
}
View Code

B. any

Specifically highlighted title simple path, to the nature of the acyclic graph like. No = number of points apparently Unicom FIG ring block - the number of sides, the number of direct and maintain dimensional prefix black block, the number of transverse edges, the longitudinal edges to the number.

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int N=2019;
int n,m,Q;
int a[N][N];
int hl[N][N],sl[N][N],sum[N][N];
int read()
{
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return x*f;
}
/*
int getsum(int tmp[][N],int i,int j)
{
    return tmp[i][j-1]+tmp[i-1][j]-tmp[i-1][j-1];
}
*/
int main()
{
    /*freopen("dat.in","r",stdin);
    freopen("my.out","w",stdout);*/
    n=read();m=read();Q=read();
    char s[N];
    for(int i=1;i<=n;i++)
    {
        scanf("%s",s+1);
        for(int j=1;j<=m;j++)
            a[i][j]=s[j]-'0';
    }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            sum[i][j]=sum[i][j-1]+sum[i-1][j]-sum[i-1][j-1]+a[i][j];
            hl[i][j]=hl[i][j-1]+hl[i-1][j]-hl[i-1][j-1];
            sl[i][j]=sl[i][j-1]+sl[i-1][j]-sl[i-1][j-1];
            if(a[i-1][j]&&a[i][j])sl[i][j]++;
            if(a[i][j-1]&&a[i][j])hl[i][j]++;
        }
    for(int i=1;i<=Q;i++)
    {
        int x=read(),y=read(),xx=read(),yy=read();
        int ans=sum[xx][yy]-sum[x-1][yy]-sum[xx][y-1]+sum[x-1][y-1];
        int cover1=hl[xx][yy]-hl[xx][y]-hl[x-1][yy]+hl[x-1][y];
        int cover2=sl[xx][yy]-sl[x][yy]-sl[xx][y-1]+sl[x][y-1];
        ans-=(cover1+cover2);
        printf("%d\n",ans);
    }
    return 0;
}
View Code

C. Fly

The formula Kichiku value is actually $ C_n ^ 2 $, so that the contribution of each pair of intersecting lines 1, regardless of the number of lines intersect at one point in the case.

In fact, play with the hand it is easy to find on the subject of the request is to reverse the number ( as long as you do not like me thought it was a wonderful math exam pushed two A4 paper formula on the line )

But Dage order not to be out of the question AK (although we still have games that AK's), put the memory card into the 32M

Certainly have to seek a breakthrough in the $ x [] $ GENERATION, can be found in the sequence $ x [] $ consisting of multiple arithmetic constitute a series. If the $ x [i] $ and $ x [i-1] $ in the same period of arithmetic sequence, and $ x [i-1] $ and foregoing columns constituted by m reverse order, then $ x [i] $ preceding a number and must be configured mk inversions pairs. Because each segment is bound to have a number of energy and $ x [i-1] $ can not constitute a reverse order and $ x [i] $ constitution, it is the contribution of each segment to be one less.

If at the beginning of a new period of arithmetic sequence of number, the number on the reverse of the calculation directly Fenwick tree. In addition, for a period beginning incomplete arithmetic series needs Stuttgart sentence.

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
#define int  long long
int n,ini,a,mod,maxx,ans;
int c[100005];
int lb(int x){return x&-x;}
int add(int x,int val)
{
    for( ;x<=a;x+=lb(x))
        c[x]+=val;
}
int sum(int x)
{
    int res=0;
    for( ;x;x-=lb(x))
        res+=c[x];
    return res;
}

signed main()
{
    scanf("%lld%lld%lld%lld",&n,&ini,&a,&mod);
    int old=ini;
    if(ini<a)add(ini+1,1);
    int now=0,num=0;
    for(int i=2;i<=n;i++)
    {
        ini=(ini+a)%mod;
        if(ini<a)num=i-sum(ini+1)-1,now++,add(ini+1,1);
        else num-=now;
        if(ini>=a&&ini<old)num++;   
        ans+=num;
    }
    cout<<ans<<endl;
    return 0;
}
View Code

 

Guess you like

Origin www.cnblogs.com/Rorschach-XR/p/11370466.html
Recommended