http://coderspace.net/bbs/viewthread.php?tid=1558&extra=page%3D1
原题就不给了
#include <cstdio> #include <cstring> #include <cstdlib> int n,m; int score[1010]; int max,maxi; int hash[7]; int main(){ freopen("game.in","r",stdin); freopen("game.out","w",stdout); scanf("%d%d",&n,&m); int t=1,mm=0; for (int i=1;i<=m;i++){ int j=t; int s=0; while (s!=n){ memset(hash,0,sizeof(hash)); for (int i=1;i<=6;i++){ int x; scanf("%d",&x); hash[x]++; } int base=0,k; for (int l=1;l<=6;l++){ if (hash[l]>base){ k=l; base=hash[l]; } } int improve=1; if (k==1 || k==4) improve=2; int num=improve*base; score[j]+=num; if (score[j]>mm){ mm=score[j]; t=j; }else if (score[j]==mm && j<t){ t=j; } s++; j=(j+1) % n; if (j==0) j=n; } } for (int i=1;i<=n;i++){ if (score[i]>max){ max=score[i]; maxi=i; } } printf("%d %d\n",maxi,max); return 0; }
#include <cstdio> #include <cstring> long long INF=1 << 30; int n,m,p; struct edge{ int x,next; long long w; }e[20010]; int a[20]; int k[210]; int tot; int v[210]; long long d[210]; int q[1000001]; long long dis[15][15]; long long f[8200][15]; long long min(long long a,long long b){return a<b?a:b;} void add(int x,int y,long long z){ e[++tot].x=y; e[tot].w=z; e[tot].next=k[x]; k[x]=tot; } long long SPFA(int st,int en){ int head=0,tail=1; for (int i=1;i<=n;i++) d[i]=INF; memset(v,0,sizeof(v)); q[tail]=st; d[st]=0; v[st]=true; while (head<tail){ int x=q[++head]; v[x]=false; for (int t=k[x];t;t=e[t].next){ if (d[e[t].x]>d[x]+e[t].w){ d[e[t].x]=d[x]+e[t].w; if (!v[e[t].x]){ q[++tail]=e[t].x; v[e[t].x]=true; } } } } return d[en]; } int main(){ freopen("gold.in","r",stdin); freopen("gold.out","w",stdout); scanf("%d%d\n",&n,&m); for (int i=1;i<=m;i++){ int x,y; long long z; scanf("%d%d%I64d\n",&x,&y,&z); add(x,y,z); add(y,x,z); } INF <<= 10; for (int i=0;i<=p+1;i++) for (int j=0;j<=p+1;j++) dis[i][j]=INF; scanf("%d\n",&p); for (int i=1;i<=p;i++){ scanf("%d",&a[i]); dis[0][i]=dis[i][0]=SPFA(1,a[i]); dis[p+1][i]=dis[i][p+1]=SPFA(n,a[i]); } a[p+1]=n; for (int i=1;i<=p+1;i++) for (int j=1;j<=p+1;j++) dis[i][j]=dis[j][i]=SPFA(a[i],a[j]); for (int i=0;i<8200;i++) for (int j=0;j<=13;j++) f[i][j]=INF; for (int i=1;i<=p+1;i++) f[1 << (i-1)][i]=dis[0][i]; for (int i=0;i<(1 << (p+1));i++){ for (int j=1;j<=p+1;j++) if (i & (1 << (j-1))){ for (int k=0;k<=p;k++){ if (!(i & (1 << k))){ f[i | (1 << k)][k+1]=min(f[i | (1 << k)][k+1],f[i][j]+dis[j][k+1]); } } } } long long ans=f[(1 << (p+1))-1][p+1]; if (ans>INF >> 3) printf("-1\n");else printf("%I64d\n",ans); return 0; }
#include <cstdio> #include <cstdlib> #include <cstring> int fa[1010]; int a[1010][1010]; bool v[1010]; int n,m; int l,r; int get(int x){ if (fa[x]==x) return x; fa[x]=get(fa[x]); return fa[x]; } int check(int x){ for (int i=1;i<=n;i++) fa[i]=i; for (int i=1;i<=n;i++){ for (int j=i+1;j<=n;j++){ if (a[i][j]<x){ int a=get(i); int b=get(j); fa[a]=b; } } } memset(v,0,sizeof(v)); int tot=0; for (int i=1;i<=n;i++){ int t=get(i); if (!v[t]){ tot++; v[t]=true; } } return tot; } int main(){ freopen("hero.in","r",stdin); freopen("hero.out","w",stdout); scanf("%d%d",&n,&m); for (int i=1;i<=n;i++){ for (int j=1;j<=n;j++){ scanf("%d",&a[i][j]); if (a[i][j]>r) r=a[i][j]; } } while (l<r){ int mid=(l + r) >> 1; if (check(mid)>=m) l=mid+1;else r=mid; } int ans=l-1; printf("%d\n",ans); return 0; }