2018年长沙理工大学第十三届程序设计竞赛

 

A   LL > 25182063

用c、c++的函数可能比较好

 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=1e2+5;
16 const ll mod=1e9+7;
17 
18 
19 int main()
20 {
21     long i;
22     char s[maxn];
23     while (gets(s))
24     {
25         for (i=0;i<strlen(s);i++)
26             s[i]=tolower(s[i]);
27         if (strcmp(s,"lovelive")==0)
28             printf("yes\n");
29         else
30             printf("no\n");
31     }
32     return 0;
33 }
 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  
15  
16 int main()
17 {
18     long i;
19     char s[105];
20     while (gets(s))
21     {
22         for (i=0;i<strlen(s);i++)
23             if (s[i]>='A' && s[i]<='Z')
24                 s[i]+=32;
25 //      printf("%s\n",s);
26         if (strcmp(s,"lovelive")==0)
27             printf("yes\n");
28         else
29             printf("no\n");
30          
31     }
32     return 0;
33 }

 

B   奇怪的加法 > 25182833

注意0的判断

 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  
15  
16 int main()
17 {
18     char sa[15],sb[15];
19     long i,a[15],b[15],lena,lenb;
20     while (scanf("%s%s",sa,sb)!=EOF)
21     {
22         for (i=1;i<=10;i++)
23         {
24             a[i]=0;
25             b[i]=0;
26         }
27         lena=strlen(sa);
28         for (i=0;i<lena;i++)
29             a[lena-i]=sa[i]-48;
30         lenb=strlen(sb);
31         for (i=0;i<lenb;i++)
32             b[lenb-i]=sb[i]-48;
33          
34         for (i=1;i<=max(lena,lenb);i++)
35             a[i]=(a[i]+b[i])%10;
36         i=max(lena,lenb);
37         while (i>1 && a[i]==0)  
38             i--;
39         while (i)
40         {
41             printf("%ld",a[i]);
42             i--;
43         }
44         printf("\n");
45     }
46     return 0;
47 }

 

C   取手机 > 25183015

求概率

 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  
15  
16 int main()
17 {
18     long a,b,t,k;
19     scanf("%ld",&t);
20     while (t--)
21     {
22         scanf("%ld%ld%ld",&a,&b,&k);
23         printf("%.3lf\n",1.0*b/(a+b));
24     }
25     return 0;
26 }

 

D   zzq的离散数学教室1 > 25187242

b>a 且b=c*k1=a*k2*k1(k2,k1>1)不存在,即b/c为质数

[L,R]区间中a/b=k的(a,b)对的个数为(R-L+1)/k。

用O(n)求出1~1e6的质数

 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 const long maxn=1e6+5;//
15  
16 bool vis[maxn];
17 long zhi[maxn],g=0;
18  
19 bool pan(long i)
20 {
21     long j;
22     for (j=1;j<=g;j++)
23         if (i%zhi[j]==0)
24             return false;
25     return true;
26 }
27  
28 int main()
29 {
30     long l,r,i,j,k,sum;
31     for (i=1;i<=maxn;i++)
32         vis[i]=true;
33     for (i=2;i<=maxn;i++)
34     {
35         if (vis[i])
36         {
37             g++;
38             zhi[g]=i;
39         }
40         for (j=1;j<=g;j++)
41         {
42             if (i*zhi[j]>maxn)
43                 break;
44             vis[i*zhi[j]]=false;
45             if (i%zhi[j]==0)
46                 break;
47         }
48     }
49     while (scanf("%ld%ld",&l,&r)!=EOF)
50     {
51         if (l>r)
52         {
53             printf("0\n");
54             continue;
55         }
56         sum=0;
57         j=r/l;
58         for (i=1;zhi[i]<=j;i++)
59             sum+=r/zhi[i]-l+1;
60         printf("%ld\n",sum);
61     }
62     return 0;
63 }

 

E   小木乃伊到我家 > 25185272

最短路模板 spfa

long long

 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 const long maxn=2e5+5;
15 const long long maxlen=1e9;
16  
17 struct node
18 {
19     long d;
20     long long len;
21     struct node *next;
22 }*point[maxn],*p;
23 long q[maxn*10];
24 long long dist[maxn];
25 bool use[maxn];
26  
27 int main()
28 {
29     long n,m,u,v,i,head,tail,d;
30     long long w;
31     scanf("%ld%ld",&n,&m);
32     for (i=1;i<=n;i++)
33         point[i]=NULL;
34     for (i=1;i<=m;i++)
35     {
36         scanf("%ld%ld%lld",&u,&v,&w);
37         p=(struct node *) malloc (sizeof(struct node));
38         p->d=v;
39         p->len=w;
40         p->next=point[u];
41         point[u]=p;
42          
43         p=(struct node *) malloc (sizeof(struct node));
44         p->d=u;
45         p->len=w;
46         p->next=point[v];
47         point[v]=p;
48     }
49     for (i=2;i<=n;i++)
50         use[i]=false;
51     use[1]=true;
52     for (i=2;i<=n;i++)
53         dist[i]=maxlen;
54     dist[1]=0;
55     q[1]=1;
56     head=0;
57     tail=1;
58     while (head<tail)
59     {
60         head++;
61         d=q[head];
62         p=point[d];
63         while (p)
64         {
65             if (dist[p->d] > dist[d]+p->len)
66             {
67                 dist[p->d] = dist[d]+p->len;
68                 if (!use[p->d])
69                 {
70                     use[p->d]=true;
71                     tail++;
72                     q[tail]=p->d;               
73                 }
74             }
75             p=p->next;
76         }
77         use[d]=false;
78     }
79     if (dist[n]==maxlen)
80         printf("qwb baka\n");
81     else
82         printf("%lld\n",dist[n]);
83     return 0;
84 }
85 /*
86 4 4
87 1 2 1
88 1 2 5
89 2 3 4
90 3 4 2
91 */

 

F   箱庭的股市 > 25344718

数论,杨辉三题 好题

(1*2*…*n) * NiYuan(1*2*…*n) = 1(mod p)

(1*2*…*(n-1)) * NiYuan(1*2*…*n-1) = 1(mod p)

(1*2*…*(n-1)) * (NiYuan(1*2*…*n)*n) = 1(mod p)

So   NiYuan(1*2*…*n-1) = NiYuan(1*2*…*n)*n%p

 

 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 const long mod=1e9 + 7;
15 const long maxn=1e6;
16   
17 long long f[maxn+5],a[maxn+5],b[maxn+5];
18   
19 int main()
20 {
21     long m,x,y,i,ci;
22     long long be,r;
23       
24     f[0]=1;
25     a[0]=1;
26     for (i=1;i<=maxn;i++)
27     {
28         f[i]=(f[i-1]<<1)%mod;
29         a[i]=a[i-1]*i%mod;
30     }
31      
32     b[maxn]=1;
33     ci=mod-1-1;
34     r=a[maxn];
35     while (ci)
36     {
37         if ((ci & 1)==1)
38             b[maxn]=b[maxn]*r%mod;
39         ci=ci>>1;
40         r=r*r%mod;
41     }
42     /*
43     a[i+1]*b[i+1] %mod = 1
44     (a[i]*(i+1))*b[i+1] %mod = 1
45      
46     a[i]*b[i] %mod = 1
47     a[i]*((i+1)*b[i+1]) %mod = 1
48     */
49      
50     for (i=maxn-1;i>=1;i--)
51         b[i]=b[i+1]*(i+1)%mod;
52     b[0]=1;
53      
54     while (scanf("%ld%ld%ld%lld",&m,&x,&y,&be)!=EOF)
55     { 
56         x--;
57         if (x<=y)
58         {
59             printf("%lld\n",f[x]*be%mod);
60             continue;
61         }
62         r=0;
63         for (i=0;i<=y;i++)
64             r=(r+ a[x]*b[x-i]%mod*b[i]%mod )%mod;
65         printf("%lld\n",r*be%mod);
66     }
67     return 0;
68 }

 

H   数学考试 > 25191023

前缀和

Result = t之前的大小的区间的最大值+以t为开头的区间

 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 const long maxn=2e5+5;
15 const long long minv=-1e12;
16  
17 long long a[maxn],sum[maxn],value,r;
18  
19  
20 int main()
21 {
22     long t,n,k,i;
23     scanf("%ld",&t);
24     while (t--)
25     {
26         scanf("%ld%ld",&n,&k);
27         sum[0]=0;
28         for (i=1;i<=n;i++)
29         {
30             scanf("%lld",&a[i]);
31             sum[i]=sum[i-1]+a[i];
32         }
33         value=minv;
34         r=minv;
35         for (i=k;i<=n-k;i++)
36         {
37 //          printf("%ld\n",i);
38             value=max(value,sum[i]-sum[i-k]);
39             r=max(r,value+sum[i+k]-sum[i]);
40         }
41         printf("%lld\n",r);
42     }
43     return 0;
44 }

 

J   杯子 > 25472494

百度百科 卡特兰数 好题

#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=2e6+5;//but not 1e6 //etc. cat1(x+y,y)
const ll mod=1e9+7;
const long maxv=2e6;
 
ll a[maxn],b[maxn];
 
ll ni(ll s)
{
    long ci=mod-1-1;
    ll r=1;
    while (ci)
    {
        if ((ci & 1)==1)
            r=r*s%mod;
        s=s*s%mod;
        ci=ci>>1;
    }
    return r;
}
 
//long long but not long
ll cat1(long x,long y)
{
    return a[x] *b[x-y]%mod *b[y]%mod;
}
 
ll cat2(long x,long y)
{
    if (y==0)
        return 1;
    else
        return (cat1(x+y,y)-cat1(x+y,y-1)+mod)%mod;
}
 
int main()
{
    long t,n,m,k,i;
    a[1]=1;
    for (i=2;i<=maxv;i++)
        a[i]=a[i-1]*i%mod;
    b[maxv]=ni(a[maxv]);
    for (i=maxv-1;i>=1;i--)
        b[i]=b[i+1]*(i+1)%mod;
    b[0]=1; //must have
         
    scanf("%ld",&t);
    while (t--)
    {
        scanf("%ld%ld%ld",&n,&m,&k);
        if (m>n || k>m)
        {
            printf("0\n");
            continue;
        }
         
        //反过来想,从最后到最初还原过程,放球(出栈) k+n-m次、出栈(放球) n-m次, 任何情况 放球(出栈)次数 <= 出栈(放球)次数
         
        //放球m-1 出栈m-k   (最后一步是放球)
        //放球(出栈) k+n-m次、出栈(放球) n-m次
        printf("%lld\n",cat2(m-1,m-k)*cat2(k+n-m,n-m)%mod);
    }
    return 0;
}
/*
10
3 2 1
2
4 3 1
4
4 2 1
5
5 3 1
10
5 5 3
9
5 4 0
0
5 4 1
10
10 2 1
4862
10 5 3
5148
1 1 1
1
 
100 50 10
295867726
1000 500 100
600162427
100000 12323 123
546590088
1000000 999995 123
196452903
 
 
*/

 

L   仓鼠养殖计划 > 25183993

先尽量使用大架子(同一个人的架子),若大架子超了,使用小架子;然后若小架子超了,使用大架子;最后判断使用小架子和大架子的数目是否超过规定

先尽量使用大架子(同一个人的架子),然后求出剩余可以放置的笼子(大架子1*2 + 大架子2*1 + 小架子*1)

先尽量使用大架子(同一个人的架子),若大架子超了,使用小架子;最后判断当前大架子的空闲数目是否大于等于小架子的超出数目 [最好]

 

 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  
15  
16 int main()
17 {
18     long t,a,b,n,p,x,y,i;
19     scanf("%ld",&t);
20     while (t--)
21     {
22         scanf("%ld%ld%ld",&b,&a,&n);
23         x=0;
24         y=0;
25         for (i=1;i<=n;i++)
26         {
27             scanf("%ld",&p);
28             x+=p/2;
29             y+=p%2;
30         }
31         if (x>a)
32         {
33             y+=(x-a)*2;
34             x=a;
35         }
36         if (a-x>=y-b)
37             printf("Yes\n");
38         else
39             printf("No\n");
40     }
41     return 0;
42 }

 

 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  
15  
16 int main()
17 {
18     long t,a,b,n,p,x,y,i;
19     scanf("%ld",&t);
20     while (t--)
21     {
22         scanf("%ld%ld%ld",&b,&a,&n);
23         x=0;
24         y=0;
25         for (i=1;i<=n;i++)
26         {
27             scanf("%ld",&p);
28             x+=p/2;
29             y+=p%2;
30         }
31         if (x>a)
32         {
33             y+=(x-a)*2;
34             x=a;   
35         }
36         else if (x<a && y>b)
37         {
38             x+=(y-b);
39             y=b;
40         }
41         if (x<=a && y<=b)
42             printf("Yes\n");
43         else
44             printf("No\n");
45     }
46     return 0;
47 }

 

posted @ 2018-04-18 23:03  congmingyige  阅读(193)  评论(0编辑  收藏  举报