A. Insomnia cure
题解:
水,暴力一下就行了
代码:
#include<bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define se second #define fs first #define ll long long #define CLR(x) memset(x,0,sizeof x) #define SZ(x) ((int)(x).size()) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++) typedef pair<int,int> P; const double eps=1e-9; const int maxn=100010; ll read() { ll x=0,f=1;char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} return x*f; } //----------------------------------------------------------------------------- int a[maxn]; int main() { int k,l,m,n,d; cin>>k>>l>>m>>n>>d; for(int i=k;i<=d;i+=k) a[i]=1; for(int i=l;i<=d;i+=l) a[i]=1; for(int i=m;i<=d;i+=m) a[i]=1; for(int i=n;i<=d;i+=n) a[i]=1; int sum=0; for(int i=1;i<=d;i++) if(a[i]) sum++; cout<<sum<<endl; }
B. Escape
题解:
追击问题,也挺水的。
代码:
#include<bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define se second #define fs first #define ll long long #define CLR(x) memset(x,0,sizeof x) #define SZ(x) ((int)(x).size()) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++) typedef pair<int,int> P; const double eps=1e-9; const int maxn=100010; ll read() { ll x=0,f=1;char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} return x*f; } //----------------------------------------------------------------------------- int a[maxn]; int main() { double p,d,t,f,c,tmp; int cnt=0; cin>>p>>d>>t>>f>>c; if(p>=d||p*t>=c) cout<<0<<endl; else { tmp=p*t; while(tmp<c) { double t1=tmp/(d-p); if(tmp+p*t1>=c) break; cnt++; tmp+=p*t1; t1=tmp/d; tmp+=p*(t1+f); } cout<<cnt<<endl; } return 0; }
C. Terse princess
题解:
构造一个数组,要求有a个比他之前的全部的数和大。b个比他之前的任意一个都大(前者优先级高于后者)
注意a<=15,是不会超过50000
贪心构造就行了,在构造时有个trick,在t[1]=1,t[2]=2时,这算比他之前的全部的数和大
代码:
#include<bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define se second #define fs first #define ll long long #define CLR(x) memset(x,0,sizeof x) #define SZ(x) ((int)(x).size()) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++) typedef pair<int,int> P; const double eps=1e-9; const int maxn=110; ll read() { ll x=0,f=1;char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} return x*f; } //----------------------------------------------------------------------------- int a[maxn]; int main() { int n,c,b; cin>>n>>c>>b; a[1]=1; int sum=1,tmp=1; if(c+1==n&&n!=1) { cout<<-1<<endl; return 0; } if(n==1) { cout<<1<<endl; return 0; } for(int i=1;i<=b;i++) { a[++tmp]=sum+1; sum+=a[tmp]; } if(b==0) a[++tmp]=1; for(int i=1;i<=c;i++) a[++tmp]=a[tmp-1]+1; for(int i=1;i<=tmp;i++) cout<<a[i]<<" "; for(int i=tmp+1;i<=n;i++) cout<<1<<" "; cout<<endl; return 0; }
D. Bag of mice
题解:
概率dp.
dp[i][j]表示公主在面对i个白鼠,j个黑鼠,赢的概率。具体看注释
代码:
#include<bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define se second #define fs first #define ll long long #define CLR(x) memset(x,0,sizeof x) #define SZ(x) ((int)(x).size()) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++) typedef pair<int,int> P; const double eps=1e-9; const int maxn=110; ll read() { ll x=0,f=1;char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} return x*f; } //----------------------------------------------------------------------------- double dp[1010][1010];//dp[i][j]表示公主面对i个白鼠和j个黑鼠赢的概率 int w,b; int main() { cin>>w>>b; dp[0][0]=0.0; for(int i=1;i<=w;i++) dp[i][0]=1.0; for(int i=1;i<=b;i++) dp[0][i]=0.0; for(int i=1;i<=w;i++) { for(int j=1;j<=b;j++) { dp[i][j]+=(double)i/(i+j);//直接选白鼠 if(j==1) continue;//如果选黑鼠,但是黑鼠只有一个,不可能赢 if(j>2) dp[i][j]+=(double)j/(i+j)*(double)(j-1)/(i+j-1)*(double)(j-2)/(i+j-2)*dp[i][j-3];//公主选黑鼠,龙选黑鼠,掉落黑鼠 dp[i][j]+=(double)j/(i+j)*(double)(j-1)/(i+j-1)*(double)i/(i+j-2)*dp[i-1][j-2];//公主选黑鼠,龙选黑鼠,掉落白鼠 } } cout<<setprecision(9)<<dp[w][b]<<endl; return 0; }
E. Porcelain
题解:
预处理出每个书架选j个时的最大值。然后就是类似多重背包了
如何预处理?暴力一下即可。先求前缀和,然后枚举
代码:
#include<bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define se second #define fs first #define ll long long #define CLR(x) memset(x,0,sizeof x) #define SZ(x) ((int)(x).size()) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++) typedef pair<int,int> P; const double eps=1e-9; const int maxn=110; ll read() { ll x=0,f=1;char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} return x*f; } //----------------------------------------------------------------------------- int a[maxn][maxn],pre[maxn][maxn],dp[maxn][10010],sz[maxn]; int main() { int n,m,tmp; cin>>n>>m; for(int i=1;i<=n;i++) { cin>>sz[i]; for(int j=1;j<=sz[i];j++) { cin>>pre[i][j]; pre[i][j]+=pre[i][j-1]; } a[i][0]=0; for(int j=1;j<=sz[i];j++) for(int k=0;k<=j;k++) a[i][j]=max(a[i][j],pre[i][k]+pre[i][sz[i]]-pre[i][sz[i]-(j-k)]); } for(int i=1;i<=n;i++) for(int j=0;j<=m;j++) for(int k=0;k<=min(j,sz[i]);k++) dp[i][j]=max(dp[i][j],max(dp[i-1][j],dp[i-1][j-k]+a[i][k])); cout<<dp[n][m]<<endl; return 0; }
时间: 2024-10-08 03:27:44