11.4NOIP模擬賽
阿新 • • 發佈:2018-11-05
!= alt nod ios fine read names show space
/* 唉,那個第二種策略應該是沒用吧。 為什麽我列出式子最優策略跟第二種策略有關??
為什麽我寫了寫分布列還是跟第二種策略有關?? 唉。人生啊。 */ #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #include <iostream> using namespace std; const int maxn=1000+15; int n; double p[maxn][maxn]; doublef[maxn][maxn]; int main() { freopen("game.in","r",stdin); freopen("game.out","w",stdout); 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); return 0; }
/* 一道比較好寫的折半搜索題。 估計暴搜剪枝也能差不多A。 */ #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define N 50 #define inf 0x3f3f3f3f using namespace std; int n,m,ans,cnt1,cnt2,dep,flag; int v[N],sum1[10485780],sum2[10485780]; bool cmp(int a,int b){return a>b;} inline int read() { int x=0,f=1;char c=getchar(); while(c>‘9‘||c<‘0‘){if(c==‘-‘)f=-1;c=getchar();} while(c>=‘0‘&&c<=‘9‘){x=x*10+c-‘0‘;c=getchar();} return x*f; } void dfs(int k,int rest) { if(k==dep) { if(flag) { sum1[++cnt1]=rest;return; } else { sum2[++cnt2]=rest;return; } } dfs(k+1,rest); dfs(k+1,rest-v[k+1]); } int main() { freopen("cake.in","r",stdin); freopen("cake.out","w",stdout); n=read();m=read(); for(int i=1;i<=n;i++) v[i]=read(); dep=n/2;flag=1;dfs(0,m/2); dep=n;flag=0;dfs(n/2,m-m/2); int L=1,R=1;ans=inf; sort(sum1+1,sum1+cnt1+1);sort(sum2+1,sum2+cnt2+1,cmp); if(sum1[1]+sum2[cnt2]>=0) ans=sum1[1]+sum2[cnt2]; else { while(L<=cnt1 && R<=cnt2) { while(sum1[L]+sum2[R]<0) L++; ans=min(ans,sum1[L]+sum2[R]); while(sum1[L]+sum2[R]>0) { R++; ans=min(ans,sum1[L]+sum2[R-1]); } L++; } } printf("%d\n",ans); fclose(stdin);fclose(stdout); return 0; }
/* 20dfs+特判n=1,2 下次再忘了取模剁手了。 */ #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #include <iostream> #define N 1001 #define mod 1000000007 #define ll long long using namespace std; ll n,m,h,w,ans,cnt; ll a,b,c,d,v; ll Mar[N][N]; struct node{ ll a,b,c,d,v; }ask[N]; inline ll read() { ll x=0,f=1;char c=getchar(); while(c>‘9‘||c<‘0‘){if(c==‘-‘)f=-1;c=getchar();} while(c>=‘0‘&&c<=‘9‘){x=x*10+c-‘0‘;c=getchar();} return x*f; } ll ksm(ll a,ll b) { ll res=1; while(b) { if(b&1) res=res*a%mod; b>>=1;a=a*a%mod; }return res; } void solve1() { for(int i=1;i<=n;i++) { a=read();b=read();c=read();d=read();v=read(); for(int x=a;x<=c;x++) for(int y=b;y>=d;y--) Mar[x][y]=v; } ans=1; } bool judge() { ll mx=0; for(int i=1;i<=n;i++) { for(int x=ask[i].a;x<=ask[i].c;x++) for(int y=ask[i].d;y>=ask[i].b;y--) { if(Mar[x][y]>ask[i].v) return false; mx=max(mx,Mar[x][y]); } if(mx!=ask[i].v) return false; }return true; } void dfs(int x,int y) { if(y>w) x++,y%=w; if(x<1 || y<1) return; if(x==h+1) { if(judge()) ans++;ans%=mod; return; } for(int i=1;i<=m;i++) { Mar[x][y]=i; dfs(x,y+1); } } int main() { freopen("grid.in","r",stdin); freopen("grid.out","w",stdout); h=read();w=read();m=read();n=read(); if(n==0) { cout<<ksm(m,h*w)%mod<<endl; return 0; } if(n==1) { a=read();b=read();c=read();d=read();v=read(); ll num=(c-a+1)*(d-b+1); ll res1=ksm(m,h*w-num)%mod; ll res2=ksm(v,num)%mod; ll res3=(res1%mod*ksm(v-1,num)%mod)%mod; ans=(res1%mod*res2%mod-res3+mod)%mod; cout<<ans%mod<<endl; return 0; } if(h<=3 && w<=3) { for(int i=1;i<=n;i++) { ask[i].a=read();ask[i].b=read(); ask[i].c=read();ask[i].d=read(); ask[i].v=read(); } dfs(1,1),cout<<ans<<endl; } fclose(stdin);fclose(stdout); return 0; }50暴力
11.4NOIP模擬賽