zoukankan      html  css  js  c++  java
  • 2018 ACM-ICPC 中国大学生程序设计竞赛暨丝绸之路程序设计竞赛

    三道大水题,其它题都不会做,真是尴尬和无奈啊…… 

    有想法,但是解决不了,感觉个人不会一些基本解法,终究还是个人学习的内容太少了

    B. Goldbach

    /*
    数值较小,<2^63,分解的两个素数较小,其中一个小于xxx(etc. 1e5)
    生成1~x的素数:O(n) 
    判断素数不能只用已求出的素数相除,这样结果不对。而且这个方法速度太慢。
    
    Code largely studys from https://paste.ubuntu.com/p/JmDk43TTPB/
    
    米勒拉宾素数测试
    https://www.cnblogs.com/cons/p/5188910.html
    
    用unsigned long long 不明觉厉…… 
    */
    
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <list>
    #include <stack>
    #include <vector>
    #include <set>
    #include <map>
    #include <queue>
    #include <algorithm>
    #include <iostream>
    using namespace std;
    #define ll unsigned long long
    const long maxn=1e6;
    //const ll mod=1e9+7;
    
    bool vis[maxn];
    long sum=0;
    ll zhi[maxn];
    
    //由于考虑到取模数很大 快速幂会溢出
    ll add_mod(ll a,ll b,ll mod) //a*b = a*x1 + a*x2 + …
    {
        ll ans=0;
        while (b)
        {
            if (b & 1)
                ans=(ans+a)%mod;
            a=(a<<1)%mod;
            b>>=1;
        }
        return ans;
    }
    
    ll pow_mod(ll a,ll b,ll mod) //a^b =a^(b/2)*a^(b/2) *a(if b%2==1)
    {
        if (b>1)
        {
            ll tmp=pow_mod(a,b>>1,mod);
            tmp=add_mod(tmp,tmp,mod);
            if (b & 1)
                tmp=add_mod(tmp,a,mod);
            return tmp;
        }
        return a;
        
    //    ll r=1;
    //    while (b)
    //    {
    //        if (b & 1)
    //            r=r*a%mod;
    //        a=a*a%mod;
    //        b>>=1;
    //    }
    //    return r;
    }
    
    bool Miller_Rabbin(ll s,ll chu)
    {
        long ci=0,i;
        ll d=s-1;    //ll
        while (!(d & 1))    //除成奇数 
        {
            d>>=1;
            ci++;
        }
        ll k=pow_mod(chu,d,s);
        if (k==1)    //第一个为奇数 
            return 1;
        for (i=0;i<ci;i++,k=k*k%s)
            if (k==s-1)    //以后的为偶数 
                return 1;
        return 0;
    }
    
    bool pan(ll s)
    {
        long i,g=5;
        ll chu[]={2,3,5,7,11};
        for (i=0;i<g;i++)
            if (s==chu[i])
                return 1;
        for (i=0;i<g;i++)
            if (s%chu[i]==0)
                return 0;
        for (i=0;i<g;i++)
            if (!Miller_Rabbin(s,chu[i]))
                return 0;
        return 1;
        
    //    if (s<maxn)
    //        return vis[s];
    //    else
    //    {
    //        long i;
    //        for (i=1;i<=ans;i++)
    //            if (s%zhi[i]==0)
    //                return false;
    //        return true;
    //    }
    }
    
    int main()
    {
        long i,j,t;
        ll n;
        for (i=1;i<maxn;i++)
            vis[i]=true;
        for (i=2;i<maxn;i++)
        {
            if (vis[i])
            {
                sum++;
                zhi[sum]=i;
            }
            for (j=1;j<=sum;j++)
            {
                if (i*zhi[j]>=maxn)
                    break;
                vis[i*zhi[j]]=false;
                if (i%zhi[j]==0)
                    break;
            }
        }
        
        scanf("%ld",&t);
        while (t--)
        {
            scanf("%llu",&n);
            for (i=1;i<=sum;i++)
                if (pan(n-zhi[i]))
                {
                    printf("%llu %llu
    ",zhi[i],n-zhi[i]);
                    break;
                }
        }
        return 0;
    }
    /*
    126
    146
    22222222222
    */

    E. Copy and Submit II

    运行题目程序一遍就知道了

    内存超限(没删原程序的a数组) -> 编译错误(只删了原程序的a数组,没删其它a变量) -> 运行超时(按照题目的代码用cin) -> 运行超时(scanf没用EOF) -> 正确通过

    满满的泪水………………………………………………………………………………………………………………………………………………………………………

    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <list>
    #include <stack>
    #include <vector>
    #include <set>
    #include <map>
    #include <queue>
    #include <algorithm>
    #include <iostream>
    using namespace std;
    #define ll long long
    const long maxn=1e6+5;
    const ll mod=1e9+7;
    
    int main()
    {
        int n,i;
        long long r,a;
        while (scanf("%ld",&n)!=EOF)
        {
            r=1;
            for (i=0;i<n;i++)
            {
                scanf("%lld",&a);
                r=r*(a+1)%mod;
            }
            printf("%lld
    ",r);
        }
        return 0;
    }

    I. Reversion Count

     1 //找个样例从头到尾调试一次,查看变量 
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <cmath>
     6 #include <list>
     7 #include <stack>
     8 #include <vector>
     9 #include <set>
    10 #include <map>
    11 #include <queue>
    12 #include <algorithm>
    13 #include <iostream>
    14 using namespace std;
    15 #define ll long long
    16 const long maxn=1e6+5;
    17 const ll mod=1e9+7;
    18 
    19 long a[105],b[105],n;
    20 
    21 bool pan()
    22 {
    23     long i;
    24     //从高位到低位,之前写错了 ,其实无关紧要,结果能被9整除 
    25     for (i=n;i>=1;i--)
    26         if (a[i]>b[i])
    27             return true;
    28         else if (a[i]<b[i])
    29             return false;
    30     return false;
    31 }
    32 
    33 int main()
    34 {
    35     long i,t,x;
    36     char s[105];
    37 //    while (scanf("%s",s)!=EOF)
    38     while (cin>>s)
    39     {
    40         n=strlen(s);
    41         for (i=1;i<=n;i++)
    42             a[i]=s[n-i]-48;
    43         for (i=1;i<=n;i++)
    44             b[i]=a[n+1-i];
    45         if (!pan())
    46         {
    47             for (i=1;i<=n;i++)
    48             {
    49                 t=a[i];
    50                 a[i]=b[i];
    51                 b[i]=t;
    52             }
    53         }
    54         for (i=1;i<=n;i++)
    55         {
    56             a[i]-=b[i];
    57             if (a[i]<0)
    58             {
    59                 a[i+1]--;
    60                 a[i]+=10;
    61             }
    62         }
    63         x=0;
    64         for (i=n;i>=1;i--)
    65         {
    66             x=x*10+a[i];
    67             a[i]=x/9;
    68             x=x%9;
    69         }
    70         while (n>1 && a[n]==0)
    71             n--;
    72         //只使用一位数字,之前写错了
    73         while (n>1 && a[n]==a[n-1])
    74             n--;
    75         if (n==1)
    76             printf("YES
    ");
    77         else
    78             printf("NO
    ");
    79     }
    80     return 0;
    81 }

    L. Nise-Anti-AK Problem

     1 #include <cstdio>
     2 #include <cstdlib>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <list>
     6 #include <stack>
     7 #include <vector>
     8 #include <set>
     9 #include <map>
    10 #include <queue>
    11 #include <algorithm>
    12 #include <iostream>
    13 using namespace std;
    14 #define ll long long
    15 const long maxn=1e6+5;
    16 const ll mod=1e9+7;
    17 
    18 long a[1005];
    19 
    20 int main()
    21 {
    22     long t,n,i;
    23 //    for (i=1;i<=100;i++)
    24 //    {
    25 //        long sum=0;
    26 //        for (int j=0;j<=i;j++)
    27 //            sum+= (i | j);
    28 //        printf("%ld
    ",sum);
    29 //    }
    30     
    31     scanf("%ld",&t);
    32     while (t--)
    33     {
    34         scanf("%ld",&n);
    35         for (i=1;i<=n;i++)
    36             scanf("%ld",&a[i]);
    37         sort(a+1,a+n+1);
    38         printf("%ld
    ",a[n]);
    39     }
    40     return 0;
    41 }
  • 相关阅读:
    Linux开机自动启动ORACLE设置
    linux下查找过滤文件内容
    weblogic 修改控制台访问路径
    ASM实例挂载磁盘失败错误日志
    weblogic服务器下一个domain建多个server(端口)
    Oracle Profile
    codeforces_724C_Ray Tracing
    struts2_validate表单验证
    struts2.5.2 通配符问题_亲测有用
    hibernate+struts2
  • 原文地址:https://www.cnblogs.com/cmyg/p/8908424.html
Copyright © 2011-2022 走看看