contest 1000

A: greed. Since a plurality of characters can be changed, so that one will be able to match a string of a string template. Remember what the number put forward a map template string, then the string directly match the direct match or spend time changes.

#include<bits/stdc++.h>
using namespace std;
#define For(i,x,y)for(i=x;i<=y;i++)
map<string,int>mp;
string str;
int main()
{
    int s,n,i;
    cin>>n;
    s=n;
    For(i,1,n)
    {
        cin>>str;
        if(!mp.count(str))mp[str]=1;
        else mp[str]++;
    }
    For(i,1,n)
    {
        cin>>str;
        if(mp.count(str)&&mp[str])s--,mp[str]--;
    }
    cout<<s;
    return 0;
}
/*3
XS
XX
M
XS
XS
M*/

B: It is clear to change the status of a lamp behind it will also change the state of the lamp, the statistical suffix turn on and off times and time, between which the two lamps enumerated change this state. This must have only two choices, either temporarily change immediately after a certain time node, or when a change in a certain time before the junction, the time between the two points which can be moved in order to become better.

#include<bits/stdc++.h>
using namespace std;
#define N 100005
#define Max(x,y)(x>y?x:y)
#define For(i,x,y)for(i=x;i<=y;i++)
#define Down(i,x,y)for(i=x;i>=y;i--)
int tim[N][2],a[N];
int main()
{
    int n,m,i,mx;
    scanf("%d%d",&n,&m);
    For(i,1,n)scanf("%d",&a[i]);
    a[n+1]=m;
    Down(i,n,0)
    {
        tim[i][1]=tim[i+1][1];
        //关灯时间 
        tim[i][0]=tim[i+1][0];
        //开灯时间 
        tim[i][i&1]+=a[i+1]-a[i];
    }
    /*printf("%d",tim[0][0]);*/
    mx=/*0*/tim[0][0];
    Down(i,n,0)
    {
        if(a[i+1]>a[i]+1)mx=Max(mx,tim[i][1]+tim[0][0]-tim[i][0]+(i&1?-1:1));
        if(a[i+1]>a[i]+1)mx=Max(mx,tim[i+1][1]+tim[0][0]-tim[i+1][0]+(i&1?1:-1));
    }
    printf("%d",mx);
    return 0;
}

If only a maximum range of data can be directly off a small difference, consider the course of our difference, in fact, there are many locations are of no use, change of location: C \ (2n \) a, values between two adjacent position constant. So pull out the end row of a sequence can be simulated differential, and every time statistical answer.

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 400005
#define For(i,x,y)for(i=x;i<=y;i++)
struct line
{
    ll w;
    int v;
}p[N];
ll ans[N];
ll read()
{
    ll A;
    bool K;
    char C;
    C=A=K=0;
    while(C<'0'||C>'9')K|=C=='-',C=getchar();
    while(C>'/'&&C<':')A=(A<<3)+(A<<1)+(C^48),C=getchar();
    return(K?-A:A);
}
void write(ll X)
{
    if(X<0)putchar('-'),X=-X;
    if(X>9)write(X/10);
    putchar(X%10|48);
}
inline bool cmp(line _,line __)
{
    return _.w<__.w;
}
int main()
{
    ll l,r;
    int n,i,cnt,now;
    n=read();
    now=cnt=0;
    For(i,1,n)
    {
        l=read(),r=read();
        p[++cnt].w=l;
        p[cnt].v=1;
        p[++cnt].w=r+1;
        p[cnt].v=-1;
    }
    sort(p+1,p+cnt+1,cmp);
    now=p[1].v;
    For(i,2,cnt)ans[now]+=p[i].w-p[i-1].w,now+=p[i].v;
    For(i,1,n)write(ans[i]),putchar(' ');
    return 0;
}

D: First flip array, in order to transfer. Set \ (f_i \) expressed in section (i \) \ serial number ending in the number of good sequences, enumerated a \ (j \) , the \ (j \) at the end of a good fight sequence on a good array, according to the principle of multiplication by multiplying. The number of good array count by the number of combinations, in \ (ij-1 \) to select number in \ (a_i \) th (the \ (I \) number has been selected). Remember the final cumulative \ (f \) array.

#include<bits/stdc++.h>
using namespace std;
#define N 1005
#define Mod 998244353
#define For(i,x,y)for(i=x;i<=y;i++)
#define Down(i,x,y)for(i=x;i>=y;i--)
int fac[N],inv[N],a[N],f[N];
namespace BASICMATH
{
    inline void inc(int&x,int y)
    {
        x=(x+y)%Mod;
    }
}
using namespace BASICMATH;
int ksm(int x,int y)
{
    if(!y)return 1;
    return 1LL*ksm(1LL*x*x%Mod,y>>1)*(y&1?x:1)%Mod;
}
int C(int x,int y)
{
    if(y>x)return 0;
    return 1LL*fac[x]*inv[y]%Mod*inv[x-y]%Mod;
}
int main()
{
    int n,i,j,tot=0;
    cin>>n;
    fac[1]=1;
    For(i,2,n)fac[i]=1LL*fac[i-1]*i%Mod;
    inv[n]=ksm(fac[n],Mod-2);
    Down(i,n-1,0)inv[i]=1LL*inv[i+1]*(i+1)%Mod;
    For(i,1,n)cin>>a[n-i+1];
    f[0]=1;
    //基数 
    For(i,1,n)
    {
        if(a[i]>0)
        For(j,0,i-a[i]-1)inc(f[i],1LL*f[j]*C(i-j-1,a[i])%Mod);
        //强制选取i 
        inc(tot,f[i]);
    }
    cout<<tot;
    return 0;
}
/*4
2 2 1 1*/

Guess you like

Origin www.cnblogs.com/May-2nd/p/12505762.html