prepare for the provincial time --10.2--Density of Power Network
2014-03-20 15:07
465 查看
Density of Power Network
嗯,通过这个题目还是对自己的读题能力有自信的,哈哈,是我先看懂的。。
题意:给出一个公交网络,给出公交车号的数量,给出每段公交路线的起始点公交号,问这个公交网络的密度,也就是线路的数量除以公交号的数量,但是有一点要注意,这个路线是认为是无向的,比如2---3、、3---2认为是一条路。
那么问题就变成计算有多少条公交路线,我一开始想的是用两重循环的数组检验现在的路线和之前的路线书否重复,思路不好,就容易时出错。。啊、然后SH学长说可以当成是一个二维数组,行列分别代表起始点,AX姐在这个基础上写了一个只浏览一半数组的方法,哈哈,至于我么,也是一样的思路,实现方法不同而已,就是如果这半边的数据符合要求,就把对应的另外半边的合法数据抹掉。
细节+代码:
嗯,通过这个题目还是对自己的读题能力有自信的,哈哈,是我先看懂的。。
题意:给出一个公交网络,给出公交车号的数量,给出每段公交路线的起始点公交号,问这个公交网络的密度,也就是线路的数量除以公交号的数量,但是有一点要注意,这个路线是认为是无向的,比如2---3、、3---2认为是一条路。
那么问题就变成计算有多少条公交路线,我一开始想的是用两重循环的数组检验现在的路线和之前的路线书否重复,思路不好,就容易时出错。。啊、然后SH学长说可以当成是一个二维数组,行列分别代表起始点,AX姐在这个基础上写了一个只浏览一半数组的方法,哈哈,至于我么,也是一样的思路,实现方法不同而已,就是如果这半边的数据符合要求,就把对应的另外半边的合法数据抹掉。
细节+代码:
#include<stdio.h> #include<string.h> int a[600][600],b[600],c[600]; int main(){ int T,i,j,k,bus,road,count; double end; scanf("%d",&T); for(i = 1;i<=T;i++){ scanf("%d%d",&bus,&road); memset(a,0,sizeof(a)); b[0] = c[0] = 0; for(j = 1;j<=road;j++) scanf("%d",&b[j]); for(j = 1;j<=road;j++) scanf("%d",&c[j]); for(j = 1;j<=road;j++) a[b[j]][c[j]] = 1; count = 0; for(j = 0;j<=bus;j++){ for(k = 0;k<=bus;k++){ if(a[j][k]==1){ count++; if(a[k][j]==1) a[k][j] = 0; } } } end = count*1.00/bus; printf("%.3lf\n",end); } return 0; }
相关文章推荐
- prepare for the provincial time --10.1--Hard to Play
- prepare for the provincial time --9.2--Taxi Fare
- prepare for the provincial time --10.5--Friends
- prepare for the provincial time --9.1-- Yet Another Story of Rock-paper-scissors
- prepare for the provincial time --10.4-- Java Beans
- prepare for the provincial time –10.6-- In 7-bit
- preapre for the provincial time --10.3--Break Standard Weight
- The partner transaction manager has disabled its support for remote/network transactions
- The Case For Automating Manual Time Tracking
- Real-time stream processing: The next step for Apache Flink
- 222. Hope for the best, and prepare for the worst.抱最好的愿望,做最坏的打算
- The proplem of Prepare for Upload for App store upload Application
- error MSB4057: The target "PlatformPrepareForBuild" does not exist in the project
- ZOJ3708 Density of Power Network(水题)
- Authentication is required to set the network proxy used for downloading packages
- zoj 3708 Density of Power Network(数学啊)
- weblogic报错----Received exception while creating connection for pool "TDMSKD": The Network Adapter could not establish the connection
- Prepare the Eclipse IDE for UNO
- How to configure the network for Linux
- How to prepare the docs for a sw development project