A
题面:
长度不超过n,且包含子序列“us”的、只由小写字母构成的字符串有多少个? 答案对1e9+7取模。
所谓子序列,指一个字符串删除部分字符(也可以不删)得到的字符串。
例如,“unoacscc"包含子序列"us”,但"scscucu"则不包含子序列"us"
输入
一个n,2<=n<=1e6
样例
输入
874520
输出
16471619
思路:
根据题目我们可以列举u,s数量从2到n,当u,s数量为t时,其他字母的数量为n-t,我们可以得到
C
n
n
−
t
∗
[
2
t
−
(
t
+
1
)
]
∗
2
4
n
−
t
C_n^{n-t}* [2^t-(t+1)]*24^{n-t}
Cnn−t∗[2t−(t+1)]∗24n−t
其中第一项就是简单的一个排列,第二项为u,s的排列数,因为这t位可以取u也可以取s,所以得到
2
t
2^t
2t而像ssss,sssu,ssuu,suuu,uuuu这些都是不合法的,我们减去(t+1),而其他字母的位可以任意取到24个字母(去掉u, s)因此得到
2
4
n
−
t
24^{n-t}
24n−t
a
n
=
∑
t
=
2
n
C
n
n
−
t
[
2
t
−
(
t
+
1
)
]
2
4
n
−
t
=
2
6
n
−
2
5
n
−
n
2
5
n
−
1
a_n = \sum\limits_{t=2}^nC_n^{n-t}[2^t-(t+1)]24^{n-t}=26^n-25^n-n25^{n-1}
an=t=2∑nCnn−t[2t−(t+1)]24n−t=26n−25n−n25n−1
s n = ∑ i = 1 n a i = 26 ( 2 6 n − 1 ) 25 − 25 ( 2 5 n − 1 ) 24 − ( 24 n − 1 ) 2 5 n + 1 576 s_n= \sum\limits_{i=1}^na_i=\frac{26(26^n-1)}{25}-\frac{25(25^n-1)}{24}-\frac{(24n-1)25^{n}+1}{576} sn=i=1∑nai=2526(26n−1)−2425(25n−1)−576(24n−1)25n+1
代码
//Siberian Squirrel
//#include<bits/stdc++.h>
#include<unordered_map>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int N = 6e6 + 10;
const int mod = 1e9 + 7;
inline ll quick_pow(ll ans, ll p) {
int res = 1;
for(; p; p >>= 1, ans = 1ll * ans * ans % mod)
if(p & 1) res = 1ll * res * ans % mod;
return res % mod;
}
inline ll inv(ll ans) {
return quick_pow(ans, mod - 2);
}
inline void solve() {
ll n;
cin >> n;
ll a1 = (quick_pow(26, n) - 1) % mod * 26 % mod * inv(25) % mod;
ll a2 = (quick_pow(25, n) - 1) % mod * 25 % mod * inv(24) % mod;
ll a3 = (24 * n - 1) * quick_pow(25, n) % mod + 1;
cout << (a1 - a2 + mod - a3 * inv(576) % mod + mod ) % mod << endl;
}
int main() {
#ifdef ACM_LOCAL
freopen("input", "r", stdin);
freopen("output", "w", stdout);
#endif
int T = 1;
// cin >> T;
while(T --) {
solve();
}
return 0;
}
/* /へ /|
/\7 ∠_/
/ │ / /
│ | _,< / /`ヽ
│ ヽ / 〉
\ ` / /
イ● 、 ● ⊂⊃〈 /
() へ | \〈
>ー 、_ ィ │ //
/ へ / ノ<| \\
ヽ_ノ (_/ │//
7 |/
>―= ̄ ̄`ー―_*/
E
题面
以P点为圆心形成一个半径为r的实心球体去截棱长为a的正四面体,求截取表面积。
思路
S
=
{
0
,
r
<
h
1
,
4
π
(
r
2
−
h
1
2
)
,
h
1
<
r
<
b
,
6
O
H
2
(
s
i
n
(
2
θ
)
+
φ
)
,
b
<
r
<
r
1
,
3
a
2
,
r
>
r
1
,
S= \begin{cases} 0,& {r<h_1,}\\ 4\pi(r^2-h_1^2),& {h_1<r<b,}\\ 6OH^2(sin(2\theta)+\varphi),& {b<r<r_1,}\\ \sqrt3a^2,& {r>r_1,}\\ \end{cases}
S=⎩⎪⎪⎪⎨⎪⎪⎪⎧0,4π(r2−h12),6OH2(sin(2θ)+φ),3a2,r<h1,h1<r<b,b<r<r1,r>r1,
代码
//Siberian Squirrel
//#include<bits/stdc++.h>
#include<unordered_map>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
const double pi = acos(-1.0);
const double eps = 1e-6;
const int N = 2e6 + 10;
inline void solve() {
double a, r, theta, fai, r1, r2, h1, h2, b;
cin >> a >> r;
r1 = sqrt(6) * a / 4;
r2 = sqrt(3) * a / 3;
h1 = sqrt(6) * a / 12;
h2 = sqrt(3) * a / 6;
b = sqrt(2) * a / 4;
if(r < h1) cout << "0.0000" << endl;
else if(r <= b) {
cout << 4 * pi * (r * r - h1 * h1) << endl;
} else if(r <= r1) {
theta = acos(h2 / (sqrt(r * r - h1 * h1)));
fai = 2.0 * pi / 3 - 2.0 * theta;
cout << 6.0 * (r * r - h1 * h1) * (sin(2 * theta) + fai) << endl;
} else cout << sqrt(3) * a * a;
}
int main() {
#ifdef ACM_LOCAL
freopen("input", "r", stdin);
freopen("output", "w", stdout);
#endif
// cin >> o;
int o = 1;
while(o --) {
solve();
}
return 0;
}
/* /へ /|
/\7 ∠_/
/ │ / /
│ | _,< / /`ヽ
│ ヽ / 〉
\ ` / /
イ● 、 ● ⊂⊃〈 /
() へ | \〈
>ー 、_ ィ │ //
/ へ / ノ<| \\
ヽ_ノ (_/ │//
7 |/
>―= ̄ ̄`ー―_*/
```