老李又不知道从哪搞到了写奇怪的题……
数据+题面http://pan.baidu.com/s/1kTokwkf
T1:水~ AC
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; int ans,res,cntO,cntX,maxO,maxX; int main(){ freopen("bs.in","r",stdin); freopen("bs.out","w",stdout); while(scanf("%d%d%d%d",&cntO,&cntX,&maxO,&maxX)==4){ ans=res=0; if(!maxO&&!maxX){puts("0");continue;} if(!maxO){printf("%d\n",min(maxX,cntX));continue;} if(!maxX){printf("%d\n",min(maxO,cntO));continue;} int X=cntX/maxX+bool(cntX%maxX),O=cntO/maxO+bool(cntO%maxO); ans=max(ans,min(cntX,min(cntX,O)*maxX)+min(cntO,min(cntX+1,O)*maxO)); ans=max(ans,min(cntO,min(cntO,X)*maxO)+min(cntX,min(cntO+1,X)*maxX)); printf("%d\n",ans); } return 0; }
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; const int maxn=1e5+10; int prime[10010]; bool p[maxn]; int fa[maxn]; bool vis[maxn]; int bel[maxn]; int find(int x){ return fa[x]==x?x:fa[x]=find(fa[x]); } int A,B,P; void getprime(){ for(int i=2;i<=B;i++){ if(!p[i]){ prime[++prime[0]]=i; for(int j=i+i;j<=B;j+=i){ p[j]=1; if(i>=P) fa[find(j)]=find(i); } } } } int main(){ freopen("set.in","r",stdin); freopen("set.out","w",stdout); cin>>A>>B>>P; for(int i=1;i<=B;i++)fa[i]=i; getprime(); for(int i=A;i<=B;i++)bel[i]=find(i); sort(bel+A,bel+1+B); int ans=unique(bel+A,bel+1+B)-bel-A; cout<<ans<<endl; return 0; }T3:水区间DP,SB只有 50分
#include<cstdio> #include<climits> #include<iostream> #include<algorithm> using namespace std; int P,Q; int a[101]; int solve(int l,int r,int l0,int r0){ if(l>r||l0>r0)return 0; if(l==r)return r0-l0; int ans=INT_MAX; for(int i=l;i<=r;i++){ int tmp=r0-l0; tmp+=solve(l,i-1,l0,a[i]-1); tmp+=solve(i+1,r,a[i]+1,r0); ans=min(ans,tmp); }return ans; } int main(){ freopen("prison.in","r",stdin); freopen("prison.out","w",stdout); scanf("%d",&P); scanf("%d",&Q); for(int i=1;i<=Q;i++){ scanf("%d",a+i); }sort(a+1,a+1+Q); printf("%d\n",solve(1,Q,1,P)); return 0; }
#include<cstdio> #include<vector> #include<iostream> #include<algorithm> using namespace std; const int maxn=1010; vector<int>G[maxn]; typedef long long LL; void add(int u,int v){ G[u].push_back(v); G[v].push_back(u); } int dep[maxn],n; int f[maxn][2]; LL g[maxn][2]; bool leaf[maxn]; void dfs(int u){ int ok=0; for(int i=0;i<G[u].size();i++){ int v=G[u][i]; if(!dep[v]){ dep[v]=dep[u]+1; ok=1; dfs(v); } }leaf[u]=!ok; } void dp(int u,int k){ if(g[u][k])return ; if(leaf[u]){ g[u][k]=1; f[u][k]=0; return; } g[u][k]=1;int sum=0;LL cas=1,mul=1; for(int i=0;i<G[u].size();i++){ int v=G[u][i];if(dep[v]<dep[u])continue; if(!g[v][0]) dp(v,0); if(!g[v][1]) dp(v,1); sum+=max(f[v][0],f[v][1]); cas*=g[v][0]*bool(f[v][0]>=f[v][1])+g[v][1]*bool(f[v][0]<=f[v][1])*!leaf[v]; } if(k==0){ f[u][0]=sum; g[u][0]=cas; }else for(int i=0;i<G[u].size();i++){ int v=G[u][i];if(dep[v]<dep[u])continue; int tmp=sum-(f[v][1]-f[v][0])*bool(f[v][1]>f[v][0])+1; if(f[v][1]>f[v][0]){ mul+=bool(f[u][1]==tmp); if(f[u][1]<tmp){ f[u][1]=tmp; g[u][1]=cas/g[v][1]*g[v][0]; mul=1; } }else if(f[v][1]<f[v][0]){ mul+=bool(f[u][1]==tmp); if(f[u][1]<tmp){ f[u][1]=tmp; g[u][1]=cas; mul=1; } }else{ mul+=bool(f[u][1]==tmp); if(f[u][1]<tmp){ f[u][1]=tmp; g[u][1]=cas/(g[v][1]*!leaf[v]+g[v][0])*g[v][0]; mul=1; } } }g[u][1]*=mul; } int main(){ freopen("tree.in","r",stdin); freopen("tree.out","w",stdout); scanf("%d",&n); for(int i=1;i<=n;i++){ int u,v,k;scanf("%d%d",&u,&k); while(k--){scanf("%d",&v);add(u,v);} }dep[1]=1; dfs(1); //pair<int,int>an; dp(1,0);//f[1][0]=an.first;g[1][0]=an.second; dp(1,1);//f[1][1]=an.first;g[1][1]=an.second; if(f[1][0]>f[1][1]){ cout<<f[1][0]<<endl; cout<<g[1][0]<<endl; }else if(f[1][0]<f[1][1]){ cout<<f[1][1]<<endl; cout<<g[1][1]<<endl; }else{ cout<<f[1][0]<<endl; cout<<g[1][0]+g[1][1]<<endl; } return 0; }