赞
踩
void solves(){
for(int i=0;i<3;++i) cin>>a[i];
sort(a,a+3);
if(a[2]+a[0]==2*a[1]){
cout<<"Yes"<<endl;
} else cout<<"No\n";
}
bool cmp(pair<string,int>a,pair<string,int>b){
return a.second>b.second;
}
void solves(){
int n;cin>>n;
vector<pair<string,int>>a(n);
for(int i=0;i<n;++i){
cin>>a[i].first>>a[i].second;
}
sort(a.begin(),a.end(),cmp);
cout<<a[1].first<<endl;
}
可能是高中的排列组合大题
先阐述一下不同种类的小球构成的长度为4的排列的一般性。
一种小球可以构成的排列有1种。
两种小球的话就列举一下有14种,如
A
B
B
B
A
A
B
B
A
A
A
B
ABBB \qquad AABB \qquad AAAB
ABBBAABBAAAB
C
4
1
+
C
4
2
∗
C
2
2
+
C
4
1
\;\;C_4^1 \qquad + C_4^2*C_2^2 \;\;\;\; + \;\;\; C_4^1
C41+C42∗C22+C41
三种小球可以隔板,
C
3
1
∗
C
3
1
∗
C
4
1
=
36
C_3^1*C_3^1*C_4^1=36
C31∗C31∗C41=36
四种小球
A
4
4
=
24
A_4^4=24
A44=24
然后记certain的数量为c,not sure的数量为re。对c进行讨论。
c=0时,可能选取re的数量分别为1 2 3 4。
即
C
r
e
1
∗
1
+
C
r
e
2
∗
14
+
C
r
e
3
∗
36
+
C
r
e
4
∗
24
C_{re}^1*1+C_{re}^2*14+C_{re}^3*36+C_{re}^4*24
Cre1∗1+Cre2∗14+Cre3∗36+Cre4∗24
c=1时,可能选取re的数量分别为1 2 3。
即
1
+
C
r
e
1
∗
14
+
C
r
e
2
∗
36
+
C
r
e
3
∗
24
1+C_{re}^1*14+C_{re}^2*36+C_{re}^3*24
1+Cre1∗14+Cre2∗36+Cre3∗24
c=2时,可能选取re的数量分别为1 2。
即
14
+
C
r
e
1
∗
36
+
C
r
e
2
∗
24
14+C_{re}^1*36+C_{re}^2*24
14+Cre1∗36+Cre2∗24
c=3时,可能选取re的数量为1。
即
36
+
C
r
e
1
∗
24
36+C_{re}^1*24
36+Cre1∗24
c=4时,
A
4
4
=
24
A_4^4=24
A44=24
需要特判c>4或c=0,re=0的情况
void solves(){ string s;cin>>s; int c=0,re=0; for(auto x:s){ if(x=='o') c++; if(x=='?') re++; } if(c>4||(!c&&!re)){ cout<<0<<endl; return; } int ans=0; if(c==1){ ans+=1; ans+=re*14; ans+=(re-1)*re*18; ans+=(re-2)*(re-1)*re*4; } if(c==2){ ans+=14; ans+=(re-1)*re*12; ans+=re*36; } if(c==3){ ans+=36; ans+=re*24; } if(c==4)ans+=24; if(!c&&re){ ans+=re+(re-1)*re*7+(re-2)*(re-1)*re*6+(re-3)*(re-2)*(re-1)*re; } cout<<ans<<endl; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。