我类个去啊!!!!!!!!!!!!!!
我类个大去啊!!!!!!!!!!!!!!!!!!
我类个去去去啊!!!!!!!!!!!!!!!!!!!!
有木有!!!!!!!!!!!!!!!!!!!!!!!!!!!
这样的题,我WA了一晚上!!!!!!!!!!!!!!!!!!!!!!!!!!!
擦啊,某人一下就过了啊!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
还跟我说可水啊!!!!!!!!!!!!!!!!!!!!!!
我大半夜debug到现在啊!!!!!!!!!!!!!!
我把POJ的discuss里面的各种BT测试数据都过了啊!!!!!!!!!!!!!!!!!!!!
特码照样WA啊!!!!!!!!!!!!!!!!!!!!!!!!!!
我搜报告,没人解释啊,都说水啊!!!!!!!!!!!!!!!!!!
“水”的我现在还没睡啊!!!!!!!!!!!!!!!!
好吧,我这次真心SB了一回:枚举图上任意两点,看最后一块是否倒在俩点之间时,我自作聪明的从 i=2 开始,没管第一个点,就TM杯具了……
思路:找起点到每个点的最短路,然后枚举所有相邻的点对,如果其中一点对另一点不满足松弛条件,那么最后一块就有可能倒在这两者之间,取这些可能值的最大值。当然如果不存在这样的点对,那么最后一块是倒在某一个点上,那么结果就是刚才最短路中的最大值。
#include<stdio.h> #include<string.h> #include<math.h> #define Ni 520 #define MAX 99999999 int map[Ni][Ni],cap[Ni][Ni],n,mark; int floyd() { int i,j,k,max=-1; for(k=1;k<=n;k++) { for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(map[i][j]>map[i][k]+map[k][j]) map[i][j]=map[i][k]+map[k][j]; } for(i=1;i<=n;i++) { if(map[1][i]>max) max=map[1][i],mark=i; } return max; } int main() { int i,j,a,b,c,m,t,key1,key2,time=1; while(scanf("%d%d",&n,&m),n+m) { for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { if(i==j)map[i][j]=0; else map[i][j]=MAX; cap[i][j]=map[i][j]; } } while(m--) { scanf("%d%d%d",&a,&b,&c); cap[a][b]=cap[b][a]=c; map[a][b]=map[b][a]=c; } int max=floyd(); max=max*2; for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { if(map[1][i]!=MAX && map[1][j]!=MAX && cap[i][j]!=MAX && cap[i][j]!=0) { if( abs(map[1][i]-map[1][j])<cap[i][j]) { int x=map[1][i]+cap[i][j]+map[1][j]; if(x>max) max=x,mark=-1,key1=i,key2=j; } } } } if(key1>key2){t=key1;key1=key2;key2=t;} printf("System #%d/n",time++); if(mark!=-1) printf("The last domino falls after %.1lf seconds, at key domino %d./n",max/2.0,mark); else printf("The last domino falls after %.1lf seconds, between key dominoes %d and %d./n",max/2.0,key1,key2); printf("/n"); } return 0; }