标签:style io os for sp 数据 div on 问题
#include <iostream> using namespace std; #include <cstdio> int n,i; int main(){ freopen("prime.in","r",stdin); freopen("prime.out",'w",stdout); cin>>n; for(i=2;i*i<=n;i++) if(n%i==0){cout<<n/i;break;} return 0; }
#include <iostream> #include <cstdio> using namespace std; const int MaxN=10010; const int MaxM=101; const int Mod=20123; int build[MaxN][MaxM][2],n,t[MaxN],m; int ans=0; int main(){ freopen("treasure.in","r",stdin); freopen("treasure.out","w",stdout); scanf("%d %d",&n,&m); int tot,i,j,k,ii; for(i=1;i<=n;i++) for(j=0;j<m;j++) { scanf("%d %d",&build[i][j][0],&build[i][j][1]); if(build[i][j][0]==1)t[i]++; } scanf("%d",&k); for(i=1;i<=n;i++){ tot=0; ans=(ans+build[i][k][1])%Mod; ii=build[i][k][1]%t[i]; if(ii==0)ii=t[i]; for(;tot<ii;k++){ k%=m; if(build[i][k][0]==1)tot++; } k=(k-1+m)%m; } printf("%d",ans); return 0; }
</pre></div><pre name="code" class="cpp">#include <iostream> using namespace std; #include <cstdio> #include <cstring> const int MaxN=1001; const int Mod=1000007; int a[MaxN],n,m; int f[MaxN][MaxN],k; void init(){ freopen("flower.in","r",stdin); freopen("flower.out","w",stdout); scanf("%d %d",&n,&m); for(int i=1;i<=n;i++)scanf("%d",&a[i]); } void DP(){ int i,j,k; //f(i,j)表示前i朵花k盆放入容量为j的背包 f[0][0]=1; for(i=1;i<=n;i++) for(j=0;j<=m;j++) for(k=0;k<=j && k<=a[i];k++){ f[i][j]+=f[i-1][j-k]; f[i][j]%=Mod; } cout<<f[n][m]; } int main(){ init(); DP(); return 0; }
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; const int MaxN=101; const int oo=1<<25; int c[MaxN],a[MaxN][MaxN],d[MaxN][MaxN]; int n,kd,m,s,t; bool vis[MaxN][MaxN]; int main() { freopen("culture.in","r",stdin); freopen("culture.out","w",stdout); scanf("%d%d%d%d%d",&n,&kd,&m,&s,&t); int c1,c2,i,j,k,u,v,cap; memset(d,0,sizeof(d)); memset(vis,false,sizeof(vis)); for(i=1;i<=n;i++)scanf("%d",&c[i]); for(i=1;i<=kd;i++) for(j=1;j<=kd;j++) scanf("%d",&a[i][j]); for(i=1;i<=n;i++) for(j=1;j<=n;j++) d[i][j]=oo; for(i=1;i<=n;i++) for(j=1;j<=n;j++) { c1=c[i],c2=c[j]; if(a[c1][c2]==0)vis[j][i]=true; } for(i=1;i<=m;i++){ scanf("%d %d %d",&u,&v,&cap); if(vis[u][v] && cap<d[u][v]) d[u][v]=cap; if(vis[v][u] && cap<d[v][u]) d[v][u]=cap; } for(k=1;k<=n;k++) for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(vis[i][k]&&vis[k][j]&&d[i][j]>d[i][k]+d[k][j]) d[i][j]=d[i][k]+d[k][j]; if(d[s][t]>=oo)cout<<-1; else cout<<d[s][t]; return 0; }
标签:style io os for sp 数据 div on 问题
原文地址:http://blog.csdn.net/u012746396/article/details/40690625