# Codeforces每日一练 1030D+1154E+540D

## 1030D Vasya and Triangle

1700 数论+几何

#include<bits/stdc++.h>
using namespace std;
#define IOS  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define maxn 5005
#define ll long long
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
int main()
{
IOS
ll n,m,k;
cin>>n>>m>>k;
if((n*m*2)%k!=0)cout<<"NO";
else{
cout<<"YES"<<endl;
cout<<"0 0"<<endl;
ll tmp=gcd(2*n,k);
if(tmp==1){cout<<n<<" 0\n"<<"0 "<<2*m/k;}
else {cout<<2*n/tmp<<" 0\n"<<"0 "<<m*tmp/k;}
}
return 0;
}


## 1154E Two Teams

1800 数据结构

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
#define maxn 200005
int n,k;
int a[maxn],nxt[maxn],pre[maxn],sig[maxn];
map<int,int> mp;
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n>>k;
for(int i=1;i<=n;i++){cin>>a[i];nxt[i]=i+1;mp[a[i]]=i;pre[i]=i-1;}
int cnt=0;
pre[0]=0;
nxt[0]=1;
pre[n+1]=n;
nxt[n+1]=n+1;
for (int j = n; j >=1 ; --j) {
if(mp[j]!=0){
int l=mp[j],r=mp[j];
sig[mp[j]]=cnt;
mp[j]=0;
for (int i = 0; i <k ; ++i) {
l=pre[l];
if(l==0)break;
sig[l]=cnt;
mp[a[l]]=0;
}
for (int m = 0; m <k ; ++m) {
r=nxt[r];
if(r==n+1)break;
sig[r]=cnt;
mp[a[r]]=0;
}
nxt[pre[l]]=nxt[r];
pre[nxt[r]]=pre[l];
cnt++;
cnt%=2;
}
}
for (int i = 1; i <=n ; ++i) {
cout<<sig[i]+1;
}
return 0;
}


2100 概率dp

dp[i][j-1][k]+=dp[i][j][k]*x*y/(x*y+y*z+z*x);
dp[i-1][j][k]+=dp[i][j][k]*x*z/(x*y+y*z+z*x)
dp[i][j][k-1]+=dp[i][j][k]*y*z/(x*y+y*z+z*x);


#include<bits/stdc++.h>
using namespace std;
#define IOS  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define maxn 105
#define ll long long
#define ld long double
int r,s,p;
ld dp[maxn][maxn][maxn];
ld a=0,b=0,c=0;
#define eps 1e-10
int main()
{
cin>>r>>s>>p;
dp[r][s][p]=1.0;
for (int i = r; i >=0 ; --i) {
for (int j = s; j >=0 ; --j) {
for (int k = p; k >=0 ; --k) {
ld x=i,y=j,z=k;
if(x*y+y*z+z*x<=eps)continue;
if(j>=1){
dp[i][j-1][k]+=dp[i][j][k]*x*y/(x*y+y*z+z*x);
}
if(i>=1){
dp[i-1][j][k]+=dp[i][j][k]*x*z/(x*y+y*z+z*x);
}
if(k>=1){
dp[i][j][k-1]+=dp[i][j][k]*y*z/(x*y+y*z+z*x);
}
}
}
}
for (int i = r; i >0 ; --i) a+=dp[i][0][0];
for (int i = s; i >0 ; --i) b+=dp[0][i][0];
for (int i = p; i >0 ; --i) c+=dp[0][0][i];
printf("%.12Lf %.12Lf %.12Lf",a,b,c);
return 0;
}


©️2019 CSDN 皮肤主题: 鲸 设计师: meimeiellie