#include<bits/stdc++.h>usingnamespace std;typedeflonglong ll;constint maxn =5e5+10;const ll mod =998244353;
vector<int> v[maxn];
vector<int> ans;
vector<int> s;char ss[maxn];intmain(){//freopen("/Users/zhangkanqi/Desktop/11.txt","r",stdin);scanf("%s", ss+1);int len =strlen(ss+1);int div =1;for(int i =1; i <= len; i++){if(ss[i]=='+') div++;else s.push_back(ss[i]-'1'+1);}sort(s.begin(), s.end(), greater<int>());int SIZE =0;for(int i =0; i < s.size(); i++)
v[i%div].push_back(s[i]), SIZE =max(SIZE,(int)v[i%div].size());int ca =0, sum;for(int i =0; i < SIZE; i++){
sum = ca;for(int j =0; j < div; j++)if(i<v[j].size()) sum += v[j][i];
ans.push_back(sum%10);
ca = sum/10;}if(ca!=0) ans.push_back(ca);for(int i = ans.size()-1; i >=0; i--)printf("%d", ans[i]);return0;}
F 博弈
题意:现有一个 n 个点,n-1条边组成的树,其中 1 号点为根节点。 牛牛和牛妹在树上玩游戏,他们在游戏开始时分别在树上两个不同的节点上。 在游戏的每一轮,牛牛先走一步,而后牛妹走一步。他们只能走到没有人的空节点上。如果谁移动不了,就输掉了游戏。现在牛牛和牛妹决定随机选择他们分别的起点,于是他们想知道,有多少种游戏开始的方式,使得牛牛存在一种一定获胜的最优策略。 两种开始方式相同,当且仅当在两种开始方式中牛牛,牛妹的开始位置是分别相同的,否则开始方式就被视作不同的。
思路:(1)二分 直接二分答案,判断当前占比下,优秀的人数的期望值是否为
n
10
\frac{n}{10}
10n (2)直接计算 设平时分数是s,期末占比x,期末分数为y,若最终为优秀则有:
s
(
1
−
x
)
+
y
x
≥
90
⇒
y
≥
90
−
s
(
1
−
x
)
x
\displaystyle s(1-x)+yx≥90\Rightarrow y≥\frac{90-s(1-x)}{x}
s(1−x)+yx≥90⇒y≥x90−s(1−x) 那么最终这个人为优秀的概率为:
90
−
90
−
s
(
1
−
x
)
x
90
⇒
(
s
−
90
)
(
1
−
x
)
90
x
\displaystyle \frac{90-\frac{90-s(1-x)}{x}}{90}\Rightarrow \frac{(s-90)(1-x)}{90x}
9090−x90−s(1−x)⇒90x(s−90)(1−x)(这也可以解释为什么平时成绩x保证>90了) 题意要求:
∑
i
=
1
n
(
s
−
90
)
(
1
−
x
)
90
x
=
0.1
n
⇒
x
=
∑
i
=
1
n
(
s
i
−
90
)
9
n
+
∑
i
=
1
n
(
s
i
−
90
)
\displaystyle \sum_{i=1}^n\frac{(s-90)(1-x)}{90x}=0.1n \Rightarrow x=\frac{\sum_{i=1}^n (s_i-90)}{9n+\sum_{i=1}^n (s_i-90)}
i=1∑n90x(s−90)(1−x)=0.1n⇒x=9n+∑i=1n(si−90)∑i=1n(si−90) 另外注意输出。。。我🚮了
ac代码:
//二分#include<bits/stdc++.h>usingnamespace std;typedeflonglong ll;constint maxn =1e5+10;const ll mod =998244353;constdouble eps =1e-9;int n;int a[maxn];double ans =0;boolcheck(double x){double res =0, p =0;for(int i =1; i <= n*10; i++){
p =(90.0-a[i]*(1-x))/x;
res +=(90-p)/90;}return res > n;}intmain(){//freopen("/Users/zhangkanqi/Desktop/11.txt","r",stdin);scanf("%d",&n);for(int i =1; i <= n; i++)scanf("%d",&a[i]);
n/=10;double l =0, r =1;while((r-l)>1e-7){double mid =(l+r)/2;if(check(mid)) l = mid;else r = mid;}//cout << ans << endl;printf("%.2lf%%", r*100);return0;}
#include<bits/stdc++.h>usingnamespace std;typedeflonglong ll;constint maxn =5e5+10;#define lowbit(x) (x&(-x))struct node{int x, y, z;friendbooloperator<(node a, node b){return a.x==b.x ? a.z>b.z : a.x<b.x;}}a[maxn];int n;
multiset<int> s;intmain(){//freopen("/Users/zhangkanqi/Desktop/11.txt","r",stdin);scanf("%d",&n);for(int i =1; i <= n; i++)scanf("%d %d %d",&a[i].x,&a[i].y,&a[i].z);sort(a+1, a+1+n);
multiset<int>::iterator it;int ans =0;for(int i =1; i <= n; i++){if(a[i].z){
it = s.lower_bound(a[i].y);if(it!=s.begin()){
it--;
s.erase(it);
ans++;}}else s.insert(a[i].y);}printf("%d\n", ans);return0;}
J 有点难
题意:
思路:emmm这魔幻的题目描述。。。题目是想告诉我们不关心y轴,当前x轴坐标是x,
x
⇒
x
+
1
x \Rightarrow x+1
x⇒x+1 有3种方案,
x
⇒
x
x \Rightarrow x
x⇒x 有1种方案,
x
⇒
x
−
1
x \Rightarrow x-1
x⇒x−1 有2种方案。 具体推一下题解的后半部分:
G
(
i
)
=
f
(
n
−
i
,
L
i
)
+
f
(
n
−
i
,
L
i
+
1
)
+
.
.
.
+
f
(
n
−
i
,
R
i
−
1
)
+
f
(
n
−
i
,
R
i
)
G(i)=f(n-i,L_i)+f(n-i,L_i+1)+...+f(n-i,R_i-1)+f(n-i,R_i)
G(i)=f(n−i,Li)+f(n−i,Li+1)+...+f(n−i,Ri−1)+f(n−i,Ri)
G
(
i
−
1
)
=
f
(
n
−
i
+
1
,
L
i
−
1
)
+
f
(
n
−
i
+
1
,
L
i
−
1
+
1
)
+
.
.
.
+
f
(
n
−
i
+
1
,
R
i
−
1
−
1
)
+
f
(
n
−
i
+
1
,
R
i
−
1
)
G(i-1)=f(n-i+1,L_{i-1})+f(n-i+1,L_{i-1}+1)+...+f(n-i+1,R_{i-1}-1)+f(n-i+1,R_{i-1})
G(i−1)=f(n−i+1,Li−1)+f(n−i+1,Li−1+1)+...+f(n−i+1,Ri−1−1)+f(n−i+1,Ri−1)
2
G
(
i
)
=
2
f
(
n
−
i
,
L
i
)
+
2
f
(
n
−
i
,
L
i
+
1
)
+
.
.
.
+
2
f
(
n
−
i
,
R
i
−
1
)
+
2
f
(
n
−
i
,
R
i
)
2G(i)=2f(n-i,L_i)+2f(n-i,L_i+1)+...+2f(n-i,R_i-1)+2f(n-i,R_i)
2G(i)=2f(n−i,Li)+2f(n−i,Li+1)+...+2f(n−i,Ri−1)+2f(n−i,Ri)
3
G
(
i
)
=
3
f
(
n
−
i
,
L
i
)
+
3
f
(
n
−
i
,
L
i
+
1
)
+
.
.
.
+
3
f
(
n
−
i
,
R
i
−
1
)
+
3
f
(
n
−
i
,
R
i
)
3G(i)=3f(n-i,L_i)+3f(n-i,L_i+1)+...+3f(n-i,R_i-1)+3f(n-i,R_i)
3G(i)=3f(n−i,Li)+3f(n−i,Li+1)+...+3f(n−i,Ri−1)+3f(n−i,Ri) 错位加:
5
G
(
i
)
=
2
f
(
n
−
i
,
L
i
)
+
3
f
(
n
−
i
,
R
i
)
+
f
(
n
−
i
+
1
,
L
i
+
1
)
+
.
.
+
f
(
n
−
i
+
1
,
R
i
−
1
)
+
f
(
n
−
i
+
1
,
R
i
)
5G(i)=2f(n-i,L_i)+3f(n-i,R_i)+f(n-i+1,L_i+1)+..+f(n-i+1,R_i-1)+f(n-i+1,R_i)
5G(i)=2f(n−i,Li)+3f(n−i,Ri)+f(n−i+1,Li+1)+..+f(n−i+1,Ri−1)+f(n−i+1,Ri)
3
f
(
n
−
i
,
L
i
−
1
)
+
2
f
(
n
−
i
,
R
i
+
1
)
+
5
G
(
i
)
=
G
(
i
−
1
)
∑
a
=
L
i
R
i
+
1
3f(n-i,L_i-1)+2f(n-i,R_i+1)+5G(i)=G(i-1)\sum_{a=L_i}^{R_i+1}
3f(n−i,Li−1)+2f(n−i,Ri+1)+5G(i)=G(i−1)∑a=LiRi+1 这样由G(i)就可以推得G(i-1)中的大多项,再根据
(
L
i
−
1
,
R
i
−
1
)
(L_{i-1},R_{i-1})
(Li−1,Ri−1)和
(
L
i
,
R
i
+
1
)
(L_i,R_i+1)
(Li,Ri+1) 对已求得的G(i-1)中的项就行增减,得到
(
L
i
−
1
,
R
i
−
1
)
(L_{i-1},R_{i-1})
(Li−1,Ri−1)对应的项之和