牛客练习赛63题解
A. 牛牛的三角形
题意:
题解:
AC代码
/* Author:zzugzx Lang:C++ Blog:blog.csdn.net/qq_43756519 */ #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define endl '\n' typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; //const int mod=1e9+7; const int mod=998244353; const double eps = 1e-10; const double pi=acos(-1.0); const int maxn=1e6+10; const ll inf=0x3f3f3f3f; const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}}; int a[110]; int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int n; cin>>n; for(int i=1;i<=n;i++)cin>>a[i]; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) for(int k=1;k<=n;k++){ if(i==k||i==j||k==j)continue; if(a[i]+a[j]>a[k]&&a[i]+a[k]>a[j]&&a[k]+a[j]>a[i]){ cout<<a[i]<<' '<<a[j]<<' '<<a[k]<<endl; return 0; } } cout<<"No solution"<<endl; return 0; }
B. 牛牛的鱼缸
题意:
题解:
AC代码
/* Author:zzugzx Lang:C++ Blog:blog.csdn.net/qq_43756519 */ #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define endl '\n' typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; //const int mod=1e9+7; const int mod=998244353; const double eps = 1e-10; const double pi=acos(-1.0); const int maxn=1e6+10; const ll inf=0x3f3f3f3f; const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}}; int main() { //ios::sync_with_stdio(false); //cin.tie(0);cout.tie(0); //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); double h,l,H,L; cin>>h>>l>>H>>L; double x=H/L; if(x>=h/l) printf("%.9lf",h*h/x/2); else{ double ans=(h-l*x+h)*l/2; printf("%.9lf",ans); } return 0; }
C. 牛牛的揠苗助长
题意:
题解:
AC代码
/* Author:zzugzx Lang:C++ Blog:blog.csdn.net/qq_43756519 */ #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define endl '\n' typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; //const int mod=1e9+7; const int mod=998244353; const double eps = 1e-10; const double pi=acos(-1.0); const int maxn=1e6+10; const ll inf=0x3f3f3f3f; const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}}; int n; ll a[maxn],b[maxn]; bool ok(ll x){ for(int i=1;i<=n;i++){ b[i]=a[i]+x/n; if(x%n>=i)b[i]++; } sort(b+1,b+1+n); ll y=b[(n+1)/2],res=0; for(int i=1;i<=n;i++)res+=abs(y-b[i]); return x>=res; } int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); cin>>n; for(int i=1;i<=n;i++)cin>>a[i]; ll l=0,r=1e18,ans; while(l<=r){ ll mid=l+r>>1; if(ok(mid))ans=mid,r=mid-1; else l=mid+1; } cout<<ans; return 0; }
D. 牛牛的01限定串
题意:
题解:
AC代码
/* Author:zzugzx Lang:C++ Blog:blog.csdn.net/qq_43756519 */ #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define endl '\n' typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; //const int mod=1e9+7; const int mod=998244353; const double eps = 1e-10; const double pi=acos(-1.0); const int maxn=1e6+10; const ll inf=0x3f3f3f3f; const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}}; ll dp1[1010][1010],dp2[1010][1010]; int sum[1010]; int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int n,c0,c1,vp,vs; cin>>n>>c0>>c1>>vp>>vs; string s,t; cin>>s>>t; s='.'+s,t='.'+t; for(int i=1;i<=n;i++){ sum[i]=sum[i-1]; if(s[i]=='1')sum[i]++; } for(int i=0;i<=n;i++) for(int j=0;j<=c1;j++) dp1[i][j]=1e18,dp2[i][j]=-1e18; dp1[0][0]=dp2[0][0]=0; for(int i=1;i<=n;i++) for(int j=0;j<=c1;j++){ ll tmp; if(t[i]!='1'){ tmp=dp1[i-1][j]; if(j==sum[i])tmp+=vp; if(sum[n]-sum[i-1]==c1-j)tmp+=vs; dp1[i][j]=min(dp1[i][j],tmp); tmp=dp2[i-1][j]; if(j==sum[i])tmp+=vp; if(sum[n]-sum[i-1]==c1-j)tmp+=vs; dp2[i][j]=max(dp2[i][j],tmp); } if(t[i]!='0'&&j-1>=0){ tmp=dp1[i-1][j-1]; if(j==sum[i])tmp+=vp; if(sum[n]-sum[i-1]==c1-j+1)tmp+=vs; dp1[i][j]=min(dp1[i][j],tmp); tmp=dp2[i-1][j-1]; if(j==sum[i])tmp+=vp; if(sum[n]-sum[i-1]==c1-j+1)tmp+=vs; dp2[i][j]=max(dp2[i][j],tmp); } } cout<<dp1[n][c1]<<' '<<dp2[n][c1]; return 0; }