1. 程式人生 > >Day5上午解題報告

Day5上午解題報告

click mit cst () logs mes code har display

預計分數: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上午解題報告