#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN=1e2+7;
int a[MAXN][MAXN];
template <typename _TP>
inline void read(_TP &X){
char ch=0;int w;X=0;
while(!isdigit(ch)){w=ch=='-';ch=getchar();}
while(isdigit(ch)){X=(X<<1)+(X<<3)+(ch^48);ch=getchar();}
X=w?-X:X;
}
inline int minn(const int a,const int b){
return a<b?a:b;
}
int main(){
//freopen("a.out","w",stdout);
int x,y,z,sum,opt=0,num=0,cnt=0;
while(true){
read(x);read(y);
if(!x && !y)break;
memset(a,0x3f,sizeof(a));
num=0;sum=0;
while(true){
a[x][y]=1;
read(x);read(y); //这里可能需要离散化一下数据
if(!x && !y)break; //但是这个题可能不需要
}
for(int k=1;k<=100;k++){
for(int i=1;i<=100;i++){
for(int j=1;j<=100;j++){
a[i][j]=minn(a[i][k]+a[k][j],a[i][j]);
}
}
}
for(int i=1;i<=100;i++){
for(int j=1;j<=100;j++){
if(a[i][j]!=0x3f3f3f3f && i!=j){
num++;
sum+=a[i][j];
// printf("%d -> %d = %d \n",i,j,a[i][j]);
// cout<<num<<"\n";
}
}
}
// cout<<"***************\n"<<"num:"<<num<<"\nsum:"<<sum<<"\n***************\n";
printf("Case %d: average length between pages = %.3lf clicks\n",++cnt,1.0*sum/num);
}
return 0;
}
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN=1e2+7;
int a[MAXN][MAXN];
template <typename _TP>
inline void read(_TP &X){
char ch=0;int w;X=0;
while(!isdigit(ch)){w=ch=='-';ch=getchar();}
while(isdigit(ch)){X=(X<<1)+(X<<3)+(ch^48);ch=getchar();}
X=w?-X:X;
}
inline int minn(const int a,const int b){
return a<b?a:b;
}
int main(){
//freopen("a.out","w",stdout);
int x,y,z,sum,opt=0,num=0,cnt=0;
while(true){
read(x);read(y);
if(!x && !y)break;
if(opt)cout<<'\n';
else opt=1;
memset(a,0x3f,sizeof(a));
num=0;sum=0;
while(true){
a[x][y]=1;
read(x);read(y); //这里可能需要离散化一下数据
if(!x && !y)break; //但是这个题可能不需要
}
for(int k=1;k<=100;k++){
for(int i=1;i<=100;i++){
for(int j=1;j<=100;j++){
a[i][j]=minn(a[i][k]+a[k][j],a[i][j]);
}
}
}
for(int i=1;i<=100;i++){
for(int j=1;j<=100;j++){
if(a[i][j]!=0x3f3f3f3f && i!=j){
num++;
sum+=a[i][j];
// printf("%d -> %d = %d \n",i,j,a[i][j]);
// cout<<num<<"\n";
}
}
}
// cout<<"***************\n"<<"num:"<<num<<"\nsum:"<<sum<<"\n***************\n";
printf("Case %d: average length between pages = %.3lf clicks",++cnt,1.0*sum/num);
}
return 0;
}
两份代码只有
if(opt)cout<<'\n';
else opt=1;
有不同,这句话旨在让最后一行不输出空行
加了这段代码的WA了
直接输出的(第一份代码)A了
很奇怪,冥思苦想了半天也不知道哪里出了问题。