2018.11.5 PION模拟赛
期望:30 + 40 + 50 = 120
实际:30 + 50 + 40 = 120
‘’
思路:最重要的是发现
是完全没有用的,然后这个题目就可以转成DP来做。
/* 期望的分:30 */ #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int n; double ans; double p[1010][1010],s[1010][1010]; int read(){ int 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 main(){ freopen("game.in","r",stdin); freopen("game.out","w",stdout); n=read(); for(int i=1;i<=n;i++) for(int j=0;j<i;j++){ scanf("%lf",&p[i][j]); s[i][j]=1.0-p[i][j]; } if(n==0){ ans=0; printf("%.2lf",ans); return 0; } if(n==1){ double ans1=p[1][0]; double ans2=s[1][0]*0; ans=ans1+ans2; printf("%.2lf",ans); } if(n==2){ double ans1=p[1][0]*p[2][1]*2; double ans2=p[1][0]*s[2][1]*1; double ans3=s[1][0]*p[2][0]*1; double ans4=s[1][0]*s[2][0]*0; ans=ans1+ans2+ans3+ans4; ans1=p[2][0]*1;ans2=s[2][0]*0; ans3=p[1][0]*1;ans4=s[1][0]*0; ans=max(ans,max(ans1+ans2,ans3+ans4)); printf("%.2lf",ans); } }
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int n; double p[1010][1010],f[1010][1010]; int main(){ scanf("%d",&n); for(int i=1;i<=n;i++) for(int j=0;j<i;j++) scanf("%lf",&p[i][j]); f[0][0]=1; for(int i=0;i<n;i++) for(int j=0;j<=i;j++){ f[i+1][j+1]+=f[i][j]*p[i+1][j]; f[i+1][j]+=f[i][j]*(1-p[i+1][j]); } double ans=0; for(int j=0;j<=n;j++) ans+=j*f[n][j]; printf("%.2lf\n",ans); }
/* 期望的分:40 */ #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int n,x,sum,ans=0x7f7f7f7f; int v[50],f[10000000]; int read(){ int 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 cmp(int a,int b){ return a>b; } void dfs(int now,int tot){ if(tot<0) return ; if(now==n+1){ ans=min(ans,tot); return ; } dfs(now+1,tot-v[now]); dfs(now+1,tot); } int main(){ freopen("cake.in","r",stdin); freopen("cake.out","w",stdout); n=read();x=read(); for(int i=1;i<=n;i++){ v[i]=read(); sum+=v[i]; } if(sum<=x){ printf("%d\n",x-sum);return 0; } if(n<20){ sort(v+1,v+1+n,cmp); dfs(1,x); cout<<ans; } else{ for(int i=1;i<=n;i++) for(int j=x;j>=v[i];j--) f[j]=max(f[j],f[j-v[i]]+v[i]); cout<<x-f[x]; } }
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int n,x,O,tot; int a[45],c[2][1100000]; int read(){ int 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; } void dfs(int l,int r,int sum){ c[O][++tot]=sum; for(int i=l;i<=r;i++) if(sum+a[i]<=x) dfs(i+1,r,sum+a[i]); } int build(int l,int r,int o){ O=o;tot=0; dfs(l,r,0); return tot; } int main(){ scanf("%d%d",&n,&x); for(int i=1;i<=n;i++) a[i]=read(); int A=build(1,n/2,0); int B=build(n/2+1,n,1); sort(c[0]+1,c[0]+A+1); sort(c[1]+1,c[1]+B+1); int now=B,ans=0; for(int i=1;i<=A;i++){ while(c[0][i]+c[1][now]>x&&now) now--; if(now==0) break; ans=max(ans,c[0][i]+c[1][now]); } printf("%d\n",x-ans); }
/* 期望得分:50 */ #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define mod 1000000007 using namespace std; long long ans; int h,w,m,n; int map1[4][4]; int x1[11],y1[11],x2[11],y2[11],v[11]; int read(){ int 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; } bool judge1(){ for(int k=1;k<=n;k++){ int maxn=0; for(int i=x1[k];i<=x2[k];i++) for(int j=y1[k];j<=y2[k];j++) maxn=max(maxn,map1[i][j]); if(maxn!=v[k]) return false; } return true; } void sove1(int now){ if(now==w*h+1){ if(judge1()){ ans++; ans%=mod; } return ; } for(int i=1;i<=m;i++){ int cx=now/w+1; int cy=now%w; if(cy==0) cy=w,cx-=1; map1[cx][cy]=i; sove1(now+1); map1[cx][cy]=0; } } long long fastpow(long long a,long long b){ long long s=1; for(;b;b>>=1){ if(b&1) s=s*a%mod; a=a*a%mod; } return s; } int main(){ freopen("grid.in","r",stdin); freopen("grid.out","w",stdout); h=read();w=read();m=read();n=read(); for(int i=1;i<=n;i++){ x1[i]=read();y1[i]=read(); x2[i]=read();y2[i]=read(); v[i]=read(); } if(h<=3&&w<=3&&n<=3&&m<=3){ sove1(1); printf("%I64d\n",ans); return 0; } else if(n==0){ int p=w*h; ans=fastpow(m,p); printf("%I64d\n",ans); } else if(n==1){ int sum=w*h; int sx=x2[1]-x1[1]+1; int zy=y2[1]-y1[1]+1; int sumn=sx*zy; long long ans1=fastpow(m,sum-sx*zy); long long ans2=(fastpow(v[1],sumn)-fastpow(v[1]-1,sumn)+mod)%mod; ans=ans1*ans2%mod; printf("%I64d\n",ans); } } /* 3 3 3 1 1 1 2 3 3 */
#include <cstdio> #include <cstdlib> #include <cstring> #include <string> #include <cmath> #include <algorithm> #include <iostream> #include <queue> #include <stack> #include <map> #include <set> #include <vector> using namespace std; typedef long long i64; const int P=1e9+7; int T,h,w,m,n; int xs[33],ys[33],xp,yp,vs[33],vp,ts[33]; int rc[33][5],mv[33][33],as[33][33]; void mins(int&a,int b){if(a>b)a=b;} int pw(int a,int n){ int v=1; for(;n;n>>=1,a=i64(a)*a%P)if(n&1)v=i64(v)*a%P; return v; } int main(){ freopen("grid.in","r",stdin); freopen("grid.out","w",stdout); int ans=0; scanf("%d%d%d%d",&h,&w,&m,&n); xp=yp=vp=0;xs[xp++]=1; xs[xp++]=h+1;ys[yp++]=1; ys[yp++]=w+1;vs[vp++]=m; for(int i=0;i<n;++i){ for(int j=0;j<5;++j) scanf("%d",rc[i]+j); xs[xp++]=rc[i][0]; xs[xp++]=rc[i][2]+1; ys[yp++]=rc[i][1]; ys[yp++]=rc[i][3]+1; vs[vp++]=rc[i][4]; vs[vp++]=rc[i][4]-1; } sort(xs,xs+xp); xp=unique(xs,xs+xp)-xs-1; sort(ys,ys+yp); yp=unique(ys,ys+yp)-ys-1; sort(vs,vs+vp); vp=unique(vs,vs+vp)-vs; for(int i=0;i<xp;++i) for(int j=0;j<yp;++j) as[i][j]=(xs[i+1]-xs[i])*(ys[j+1]-ys[j]); for(int t=0;t<n;++t){ rc[t][0]=std::lower_bound(xs,xs+xp,rc[t][0])-xs; rc[t][2]=std::lower_bound(xs,xs+xp,rc[t][2]+1)-xs; rc[t][1]=std::lower_bound(ys,ys+yp,rc[t][1])-ys; rc[t][3]=std::lower_bound(ys,ys+yp,rc[t][3]+1)-ys; rc[t][4]=std::lower_bound(vs,vs+vp,rc[t][4])-vs; }/*离散化*/ for(int S=0;S<(1<<n);++S){ for(int i=0;i<xp;++i) for(int j=0;j<yp;++j) mv[i][j]=vp-1; int s=1; for(int t=0;t<n;++t){ int v=rc[t][4]; if(S>>t&1) s=-s,--v; for(int i=rc[t][0];i<rc[t][2];++i) for(int j=rc[t][1];j<rc[t][3];++j) mins(mv[i][j],v); } for(int i=0;i<vp;++i) ts[i]=0; for(int i=0;i<xp;++i) for(int j=0;j<yp;++j) ts[mv[i][j]]+=as[i][j]; for(int i=0;i<vp;++i) s=i64(s)*pw(vs[i],ts[i])%P; ans=(ans+s)%P; } printf("%d\n",(ans+P)%P); return 0; }
细雨斜风作晓寒。淡烟疏柳媚晴滩。入淮清洛渐漫漫。
雪沫乳花浮午盏,蓼茸蒿笋试春盘。人间有味是清欢。