2018多校联合训练4

http://acm.hdu.edu.cn/userloginex.php?cid=805

过了6题,第一次进入前100名

 

1012:直接从1走到n

solved by wyq

#include
#include
int a[100005];
int reabs(int x)
{
    if(x<0)return -x;
    else return x;
}
int main()
{
    int T,i,n;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        for(i=1;i<=n;i++)
            scanf("%d",&a[i]);
        printf("%d\n",(int)(sqrt(reabs(a[1]-a[n]))));
    }
    return 0;
}

 

1004:和出题人心有灵犀2333

solved by lyy

#include 
using namespace std;
#define ll long long
struct st
{
    int a,b;
}p[105];
int t,n,m;

bool cmp(st a,st b)
{
    return a.b

 

1011:

solved by wyq

#include
#include
#include
char s[1005];
bool isnum(int x,int y)
{
    if(x>y)return false;
    //printf("%d %d\n",x,y);
    if(x!=y && s[x]=='0')return false;
    int i;
    for(i=x;i<=y;i++)
        if(s[i]=='+' || s[i]=='*')return false;
    for(i=x;i<=y;i++)
    {
        if(s[i]=='?')s[i]='1';
    }
    return true;
}
int main()
{
    int T,i,n;
    scanf("%d",&T);
    while(T--)
    {
       scanf("%s",s);
       int lens=strlen(s);
       if(s[0]=='0' && s[1]=='?')s[1]='+';
       for(i=2;i<=lens;i++)
            if((s[i-2]=='+' || s[i-2]=='*')&& s[i-1]=='0' && s[i]=='?')s[i]='+';
        int lastfuhao=lens;
        bool ans=true;
       for(i=lens-1;i>=0;i--)
       {
           if(s[i]=='+' || s[i]=='*')
           {
               ans=isnum(i+1,lastfuhao-1);
               lastfuhao=i;
               if(!ans)break;
           }
       }
       if(ans)ans=isnum(0,lastfuhao-1);
       if(!ans)printf("IMPOSSIBLE\n");
       else printf("%s\n",s);
    }
    return 0;
}

 

1002:搞不懂为什么是莫队算法,不过和莫队算法比较相似,按照\sqrt{n}分块,首先求出所有200的倍数行,然后利用T(n,k) = 2 T(n-1,k-1) + C_{n-1}^{k}

递推

solved by lyy

#include 
using namespace std;
#define ll long long
const ll mod=1000000007;
ll f[100005];
ll ff[100005];
ll c[205][100005];
int t,n,m;

long long inv(long long a,long long m)
{
    if(a == 1)return 1;
    return inv(m%a,m)*(m-m/a)%m;
}

int main()
{
    f[0]=1;
    for (int i=1;i<=100000;i++)
    {
        f[i]=f[i-1]*i%mod;
    }
    for (int i=0;i<=100000;i++)
    {
        ff[i]=inv(f[i],mod);
    }
    c[0][0]=0;
    for (int i=1;i<=200;i++)
    {
        ll x=1;
        c[i][0]=1;
        for (int j=1;j<=500*i;j++)
        {
            x=(x+f[i*500]*ff[j]%mod*ff[500*i-j]%mod)%mod;
            c[i][j]=x;
        }
    }
    scanf("%d",&t);
    while (t--)
    {
        scanf("%d%d",&n,&m);
        if (m<=600)
        {
            ll x=1;
            for (int i=1;i<=m;i++)
            {
                x=(x+f[n]*ff[i]%mod*ff[n-i]%mod)%mod;
            }
            printf("%lld\n",x);
        }
        else if (n==m)
        {
            ll ans=1;
            for (int i=1;i<=n;i++)
            {
                ans=ans*2%mod;
            }
            printf("%lld\n",ans);
        }
        else
        {
            vector v;
            ll ans=0;
            while (n%500!=0)
            {
                v.push_back(f[n-1]*ff[m]%mod*ff[n-1-m]%mod);
                m--;
                n--;
            }
            reverse(v.begin(),v.end());
            ans=c[n/500][m];
            for (int i=0;i

 

1005:行和列都是2L的周期,第i行第j 列的数是:

\frac{i*(i+3)+j*(j+1)+2ij}{2} \%L

那么很容易分析出i和j都是2L的周期,更确切的是当n位奇数时周期是L,n为偶数时周期为2L(一开始把周期当L,结果Wa了),

然后分成4块求即可

solved by lyy

#include 
using namespace std;
#define ll long long
int t;
int l,q;
int a[22];
int p[22][22];
int r[22];
int row[22][22];
int col[22][22];
ll s[22];

int main()
{
    scanf("%d",&t);
    while (t--)
    {
        memset(p,0,sizeof(p));
        memset(r,0,sizeof(r));
        memset(s,0,sizeof(s));
        memset(row,0,sizeof(row));
        memset(col,0,sizeof(col));
        scanf("%d",&l);
        int k=l*2;
        for (int i=0;i

 

1010:愉快的暴力题,先对行暴力,时间复杂度 O(4*4^5*16),每行只有两种可行的情况,再判断列并取最小值即可

solved by lyy

#include 
using namespace std;
#define ll long long
#define per(i,j,k) for (int i=j;i go(int r)
{
    vector ans;
    st x;
    for (int i=0;i<4;i++)
    {
        for (int j=0;j<16;j++)
        {
            x.data[i][j]=a[i+r*4][j];
        }
    }
    per(x1,0,4)
    {
        per(x2,0,4)
        {
            per(x3,0,4)
            {
                per(x4,0,4)
                {
                    int can=1;
                    for (int i=0;i<4;i++)
                    {
                        init();
                        for (int j=0;j<16;j++)
                        {
                            if (vis[x.data[i][j]]==1) can=0;
                            else vis[x.data[i][j]]=1;
                        }
                    }
                    if (can==1)
                    {
                        //cout< v1=go(0);
        vector v2=go(1);
        vector v3=go(2);
        vector v4=go(3);
        int ans=10000;
        for (auto x1:v1)
        {
            for (auto x2:v2)
            {
                for (auto x3:v3)
                {
                    for (auto x4:v4)
                    {
                        int can=1;
                        for (int i=0;i<16;i++)
                        {
                            init();
                            for (int j=0;j<4;j++)
                            {
                                if (vis[x1.data[j][i]]==1) can=0;
                                else vis[x1.data[j][i]]=1;
                            }
                            for (int j=0;j<4;j++)
                            {
                                if (vis[x2.data[j][i]]==1) can=0;
                                else vis[x2.data[j][i]]=1;
                            }
                            for (int j=0;j<4;j++)
                            {
                                if (vis[x3.data[j][i]]==1) can=0;
                                else vis[x3.data[j][i]]=1;
                            }
                            for (int j=0;j<4;j++)
                            {
                                if (vis[x4.data[j][i]]==1) can=0;
                                else vis[x4.data[j][i]]=1;
                            }
                            if (can==1)
                            {
                                ans=min(ans,x1.num+x2.num+x3.num+x4.num);
                            }
                        }
                    }
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

 

你可能感兴趣的:(2018多校联合训练4)