第十九周 1.3-1.9

1.3

补个BC。

HDU 5608 function

题解这么说。复杂度不会。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <map>
 4 using namespace std;
 5 typedef long long LL;
 6 const LL mod = 1e9 + 7;
 7 const LL maxn = 1e6 + 10;
 8 map<LL,LL> M;
 9 LL t[maxn];
10 
11 LL S1(LL n)
12 {
13     LL ret = n * ( n + 1 ) % mod * ( 2 * n % mod + 1 ) % mod * 166666668LL % mod;
14     ret = ( ret - 3 * n % mod * ( n + 1 ) % mod * 500000004LL % mod + mod ) % mod;
15     ret = ( ret + 2 * n ) % mod;
16     return ret;
17 }
18 
19 LL S2(LL n)
20 {
21     if(n < maxn) return t[n];
22     if(M.find(n) != M.end()) return M[n];
23     LL ret = S1(n);
24     for(LL i = 2; i <= n; i++)
25     {
26         LL r = n / ( n / i );
27         ret = (ret - S2(n/i) * ( r - i + 1 ) % mod + mod) % mod;
28         i = r;
29     }
30     return M[n] = ret;
31 }
32 
33 void pre()
34 {
35     for(LL i = 1; i < maxn; i++) t[i] = (i - 1) * (i - 2) % mod;
36     for(int i = 1; i < maxn; i++)
37         for(int j = 2; i * j < maxn; j++)
38             t[i*j] = (t[i*j] - t[i] + mod) % mod;
39     for(int i = 1; i < maxn; i++) t[i] = ( t[i] + t[i-1] ) % mod;
40     return;
41 }
42 
43 int main(void)
44 {
45     pre();
46     int T;
47     scanf("%d", &T);
48     while(T--)
49     {
50         LL n;
51         scanf("%I64d", &n);
52         printf("%I64d\n", S2(n));
53     }
54     return 0;
55 }
Aguin

 

1.4-1.8

什么都没干。

 

1.9

怎么没人写C吖。

CF 615 C Running Track

n2预处理后缀。一路dp。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 using namespace std;
 5 int suf[2][2222][2222], dp[2222];
 6 char s[2][2222], t[2222];
 7 int l[2222], r[2222];
 8 int len[2222];
 9 
10 void ans_print(int pos)
11 {
12     if(pos <= 0) return;
13     ans_print(pos-len[pos]);
14     printf("%d %d\n", l[pos], r[pos]);
15     return;
16 }
17 
18 int main(void)
19 {
20     scanf("%s%s", s[0] + 1, t + 1);
21 
22     int ls = strlen(s[0]+1), lt = strlen(t+1);
23     for(int i = 1; i <= ls; i++) s[1][i] = s[0][ls-i+1];
24     for(int i = 1; i <= ls; i++)
25         for(int j = 1; j <= lt; j++)
26             suf[0][i][j] = s[0][i] == t[j] ? suf[0][i-1][j-1] + 1 : 0 ,
27             suf[1][i][j] = s[1][i] == t[j] ? suf[1][i-1][j-1] + 1 : 0 ;
28 
29     for(int j = 1; j <= lt; j++)
30     {
31         dp[j] = 2222;
32         for(int i = 1; i <= ls; i++)
33         {
34             if(dp[j] > dp[j-suf[0][i][j]] + 1)
35             {
36                 dp[j] = dp[j-suf[0][i][j]] + 1;
37                 len[j] = suf[0][i][j];
38                 l[j] = i - len[j] + 1, r[j] = i;
39             }
40             if(dp[j] > dp[j-suf[1][i][j]] + 1)
41             {
42                 dp[j] = dp[j-suf[1][i][j]] + 1;
43                 len[j] = suf[1][i][j];
44                 l[j] = ls - i + len[j], r[j] = ls - i + 1;
45             }
46         }
47     }
48 
49     if(dp[lt] == 2222) puts("-1");
50     else
51     {
52         printf("%d\n", dp[lt]);
53         ans_print(lt);
54     }
55 
56     return 0;
57 }
Aguin

 

你可能感兴趣的:(第十九周 1.3-1.9)