Output
对每个测试用例,在1行里输出最少还需要建设的道路数目。
Sample Input
4 2 1 3 4 3 3 3 1 2 1 3 2 3 5 2 1 2 3 5 999 0 0
Sample Output
1 0 2 998 Hint Hint
Huge input, scanf is recommended.
Source
浙大计算机研究生复试上机考试-2005年
Recommend
JGShining
代码:#include
#include
int arr[MAX][2]; int res[MAX]; int set; void proc() {
int i,j; int rest;
set=1; //用来统计集合个数 memset(res,0,(n+1)*sizeof(int)); res[arr[0][0]]=res[arr[0][1]]=1; for(i=1;i<=set;i++) {
for(j=0;j if(res[arr[j][0]]*res[arr[j][1]]) continue; //当前数据已经归类,则不进行任何操作 if(res[arr[j][0]]==i||res[arr[j][1]]==i) { res[arr[j][0]]=res[arr[j][1]]=i; //对数据进行集合划分 j=-1; //从第一组元素开始继续遍历 } } 31 for(j=0;j if(res[arr[j][0]]*res[arr[j][1]]==0) break; //遇到首或尾没有归类的情况的时候跳出 if(j if(res[arr[j][0]]*res[arr[j][1]]==0){ res[arr[j][0]]=res[arr[j][1]]=set; break; } } } rest=0; for(i=1;i<=n;i++) if(res[i]==0) rest++; if(m==0) printf(\ else if(rest==0) { if(set==1) printf(\ else printf(\ } else printf(\} int main() { int i; scanf(\ while(n) { scanf(\ for(i=0;i scanf(\ } return 0; } 2000 ASCII码排序 Problem Description 输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。 Input 输入数据有多组,每组占一行,有三个字符组成,之间无空格。 Output 对于每组输入数据,输出一行,字符中间用一个空格分开。 32 Sample Input qwe asd zxc Sample Output e q w a d s c x z Author lcy Source C语言程序设计练习(一) Recommend JGShining 解答: #include char a,b,c,d; while(scanf(\,&a,&b,&c)!=EOF) { getchar(); if(a>=b) { if(c>=a) printf(\,b,a,c); else if(b>=c) printf(\,c,b,a); else if(b printf(\,b,c,a); } else { if(c>=b) printf(\,a,b,c); else if(c>=a) printf(\,a,c,b); else if(a>c) 33 printf(\,c,a,b); } } } 2001 计算两点间的距离 Problem Description 输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离。 Input 输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔开。 Output 对于每组输入数据,输出一行,结果保留两位小数。 Sample Input 0 0 0 1 0 1 1 0 Sample Output 1.00 1.41 Author lcy Source C语言程序设计练习(一) Recommend JGShining 解答: #include double a,b,c,d,s; 34 while(scanf(\,&a,&b,&c,&d)!=EOF) { s=sqrt((a-c)*(a-c)+(b-d)*(b-d)); printf(\,s); } } 2002 计算球体积 Problem Description 根据输入的半径值,计算球的体积。 Input 输入数据有多组,每组占一行,每行包括一个实数,表示球的半径。 Output 输出对应的球的体积,对于每组输入数据,输出一行,计算结果保留三位小数。 Sample Input 1 1.5 Sample Output 4.189 14.137 Hint #define PI 3.1415927 Author lcy Source C语言程序设计练习(一) Recommend JGShining 解答: #include double a,v; 35 百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库整理出ACM所有题目及答案 - 图文(8)在线全文阅读。
相关推荐: