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\n",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\n",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\n");
77         else
78             printf("NO\n");
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\n",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\n",a[n]);
39     }
40     return 0;
41 }

 

转载于:https://www.cnblogs.com/cmyg/p/8908424.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ACM-ICPC(国际大学程序设计竞赛)是一项全球性的大学程序设计比赛,每年吸引来自世界各地的顶尖大学代表队参与。ACM-ICPC竞赛的核心内容是团队编程和问题解决能力。 首先,ACM-ICPC竞赛对参赛选手的编程能力要求很高。参赛队伍需要在规定的时间内解决一系列的算法问题,这些问题常常包含复杂的数据结构和算法,要求选手在有限的时间内设计和实现高效的程序。 其次,ACM-ICPC竞赛强调团队协作。每个队伍由三名选手组成,他们需要分工合作,保持良好的沟通与协调,共同解决问题。团队成员需要相互理解、相互信任,快速地协商和决策,同时要保持高效的任务分配和时间管理。 此外,ACM-ICPC竞赛也需要选手具备良好的问题解决能力。这些问题往往是实际应用或理论推导相关的,选手需要从数学、计算机科学和算法等多个角度出发,找到最佳解决方案。在面对问题时,选手需要对问题进行分析、抽象和建模,运用各种算法和数据结构进行解决。 对于参赛选手来说,ACM-ICPC提供了一个学习与交流的平台。在比赛中,选手可以接触到不同国家和地区的优秀程序设计人才,学习他们的思维方式和编程技巧。同时,ACM-ICPC还举办了一系列的培训和研讨会,让选手有机会深入了解计算机科学和算法领域最新的研究成果。 总之,ACM-ICPC国际大学程序设计竞赛是一个挑战性与学习性兼具的比赛。它要求选手具备扎实的编程技能、团队合作能力和问题解决能力。参与此竞赛不仅可以锻炼自己的编程能力,还能与全球的顶尖程序设计人才进行交流,拓宽自己的视野和思维方式。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值