码迷,mamicode.com
首页 > 其他好文 > 详细

Day5上午解题报告

时间:2017-11-01 22:11:47      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:names   生成   pre   枚举   using   scan   技术   解题报告   二分   

预计分数:100+40+30=170

实际分数假分数:0+0+0=0 CE*3

实际真分数:60+50+0=110

老师没把我的程序放的文件夹里面,于是。。。。。

 

T1

https://www.luogu.org/problem/show?pid=T15678

一眼秒C(n,k)

组合数,

不过数组少开了1.。。翻车了呜呜呜~~~~(>_<)~~~~

技术分享
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #define LL long long 
 6 using namespace std;
 7 const LL MAXN=2*1e6;
 8 const LL INF=0x7ffff;
 9 const LL mod=1e9+7;
10 const LL limit=2*1e6+10;
11 inline LL read()
12 {
13     char c=getchar();LL flag=1,x=0;
14     while(c<0||c>9)    {if(c==-)    flag=-1;c=getchar();}
15     while(c>=0&&c<=9)     x=x*10+c-48,c=getchar();return x*flag;
16 }
17 LL n,k;
18 LL a[MAXN];
19 LL js[MAXN];
20 LL x,y;
21 LL exgcd(LL a,LL b,LL &x,LL &y)
22 {
23     if(b==0)
24     {
25         x=1,y=0;return a;
26     }
27     LL r=exgcd(b,a%b,x,y)%mod;
28     LL tmp=x%mod;x=y%mod;y=tmp-(a/b)*y%mod;
29     return r%mod;
30 }
31 LL C(LL n,LL k)
32 {
33     LL r=exgcd((js[n-k]%mod*js[k]%mod)%mod,mod,x,y);
34     while(x<0)    
35         x+=mod;
36     LL yy1=js[n]%mod;
37     LL xx1=x%mod;
38     LL rt=((LL)yy1*xx1)%mod;
39     return rt;
40 }
41 int main()
42 {
43 //12    freopen("cube.in","r",stdin);
44 //    freopen("cube.out","w",stdout);
45     n=read();k=read();
46 //    for(LL i=1;i<=n;i++)
47 //        a[i]=read();
48     js[0]=1;
49     for(LL i=1;i<=limit;i++)    js[i]=((LL)js[i-1]%mod*i%mod)%mod;
50     LL ans=C(n,k)%mod;
51     printf("%lld",ans%mod);
52     return 0;
53 }
54 
55 /*
56 3 2
57 1 1 0
58 //3
59 
60 4 2
61 0 0 0 0 //6
62 
63 5 3
64 1 0 1 0 1//10
65 //
66 
67 */
View Code

 

 

T2

没想到正解

正解其实很简单

先求最大生成树

在建最大生成树的时候记录下选择k次的最大限重

每次二分查找

考场上为了求稳光敲了暴力

 

T3

写了30分的暴力,但是被卡T了。

技术分享
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #define LL long long 
 6 using namespace std;
 7 const int MAXN=1e4+10;
 8 const int INF=0x7ffff;
 9 const int mod1=10260817;
10 const int mod2=100007;
11 const int mod =1e9+7;
12 inline int read()
13 {
14     char c=getchar();int flag=1,x=0;
15     while(c<0||c>9)    {if(c==-)    flag=-1;c=getchar();}
16     while(c>=0&&c<=9)     x=x*10+c-48,c=getchar();return x*flag;
17 }
18 int n,q;
19 char word[MAXN][51];
20 int len[MAXN];
21 int sum[MAXN];//长度>=i的单词有多少个
22 int mxlen=0; 
23 int hash[MAXN*200];
24 bool pd(int now,int nowlen,int will,int need)
25 {
26     if(need-nowlen>len[will]) return 1;
27     unsigned int seed=27;
28     unsigned LL h=0;
29     for(int i=1;i<=nowlen;i++)
30         h=(h+( (seed*word[now][i])%mod2))%mod1,seed=seed*seed;
31     for(int i=len[will]-(need-nowlen)+1;i<=len[will];i++)
32         h=(h+( (seed*word[will][i])%mod2))%mod1,seed=seed*seed;
33     h=h%mod1;
34     if(hash[h]==0)    
35     {
36         hash[h]=1;
37         return 0;
38     }
39     return 1;
40 }
41 int main()
42 {
43 //    freopen("word.in","r",stdin);
44 //    freopen("word.out","w",stdout);
45     n=read(),q=read();
46     for(int i=1;i<=n;i++)
47     {
48         scanf("%s",word[i]+1);
49         len[i]=strlen(word[i]+1);
50         mxlen=max(len[i],mxlen);
51         for(int j=len[i];j>=1;j--)
52         sum[j]++;
53     }
54     for(int i=1;i<=q;i++)
55     {
56         memset(hash,0,sizeof(hash));
57         int qr=read(),ans=0;
58         for(int j=1;j<=n;j++)//枚举每个单词
59             for(int k=1;k<=min(len[j],qr-1);k++)//这个单词的长度 
60                 for(int l=1;l<=n;l++)// 枚举其他的单词 
61                     if(pd(j,k,l,qr)==0)    
62                     {
63                     /*    for(int o=1;o<=k;o++)    cout<<word[j][o];
64                         for(int o=len[l]-(qr-k)+1;o<=len[l];o++)    cout<<word[l][o];
65                         cout<<endl;*/
66                         ans=(ans+1)%mod;
67                     }
68         printf("%d\n",ans%mod);
69     }
70     return 0;
71 }
72 
73 /*
74 2 2
75 cool
76 at
77 6
78 3
79 
80 //7 \n 5
81 */
View Code

正解:

没听懂。。。。。

 

总结

终于翻了一次车了(啪,成天打暴力还好意思翻车)

T2没想到正解,,好失败啊。。。。

T3被卡成零分。。

交题的时候因为各种原因老师忘记把我的程序放到文件夹里了。。

GG

 

 

 

 

 

 

Day5上午解题报告

标签:names   生成   pre   枚举   using   scan   技术   解题报告   二分   

原文地址:http://www.cnblogs.com/zwfymqz/p/7768723.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!