zoukankan      html  css  js  c++  java
  • 2016ccpc杭州

    Time:

    Link


    A

    题意

    分析


    B

    题意

    分析


    C

    题意

    分析


    D

    题意

    分析


    E

    题意

    分析


    F

    题意

    分析

      


    G

    题意

    分析


    H

    题意

    分析


    I

    题意

    分析


    J

    题意

    分析


    K

    题意

    给出n和s,匹配(s+1,s+2,s+3......s+n)和(1,2,3,4,5........n)让(s+x)%x==0,判断是否有解

    分析

    czh:

    先用程序跑一边,发现1到1e9得素数间隙小于300,那么如果n大于600时,一定会存在两个素数,直接输出no,否则就二分图匹配

    比赛得时候wa无数遍,赛后看题解发现,素数还可以模自身啊,不一定非要匹配到1得位置。。。也就是说,当存在两个区间相交的时候,是允许存在两个素数的。

    然后,我们需要证明,区间相交的部分一定是匹配自己最优,因为对于位置i,它可以匹配,i*1,i*2,i*3......那么显然匹配i的时候,留给其他位置更多匹配选择啊

    #include <cstdio>
    #include <iostream>
    #include<cstring>
    using namespace std;
    #define ll long long
    const int maxn=1000+10;
    int f[maxn],to[maxn*maxn],nex[maxn*maxn],cnt,vis[maxn],pe[maxn],n,s;
    void add(int a,int b)
    {
        cnt++;
        to[cnt]=b;
        nex[cnt]=f[a];
        f[a]=cnt;
    }
    bool is_ok(int x)
    {
        for(int i=f[x]; i; i=nex[i])
        {
            if(vis[to[i]]==0)
            {
                vis[to[i]]=1;
                if(pe[to[i]]==0||is_ok(pe[to[i]]))
                {
                    pe[to[i]]=x;
                    return true;
                }
            }
        }
        return false;
    }
    int main()
    {
        int T;
        cin>>T;
        for(int cn=1; cn<=T; cn++)
        {
            cnt=0;
            scanf("%d %d",&n,&s);
            if(n>s)
            {
                int kk=n;
                n=s;
                s=kk;
            }
            if(n>1000)
            {
                printf("Case #%d: No
    ",cn);
                continue;
            }
            for(int i=1; i<maxn; i++)
                f[i]=0,pe[i]=0;
            memset(nex,0,sizeof(nex));
            for(ll i=s+1; i<=n+s; i++)
            {
                for(int j=1; j<=n; j++)
                {
                    if(i%j==0)
                        add(j,i-s);
                }
            }
            int ans=0;
            for(int i=1; i<=n; i++)
            {
                for(int j=1; j<=n; j++)vis[j]=0;
                if(is_ok(i))ans++;
            }
            if(ans!=n)
                printf("Case #%d: No
    ",cn);
            else
                printf("Case #%d: Yes
    ",cn);
        }
        return 0;
    }
    

      


    Summary:

    ym:

    czh:

    hxx:  

  • 相关阅读:
    客户端用mstsc不能用一台设备连接终端服务器的解决办法
    [转]知识管理ABC
    Visual Studio常用小技巧[备忘]
    一套外企的数据库设计面试题
    MSDN中的图形元素和文档约定[备忘]
    设计模式概述
    ASP.Net 4.0中新增加的23项功能[转]
    Dreamweaver 8 的相关使用
    浅谈ThreadPool 线程池
    C#委托的异步调用[学习]
  • 原文地址:https://www.cnblogs.com/Deadline/p/9690365.html
Copyright © 2011-2022 走看看