SZU:B36 Reading books
2013-05-15 20:07
239 查看
Description
In the summer vacation, LRJ wants to improve himself in computer science. So he finds out N books of computer science in the school library. The books are numbered from 0 to N-1.To finish reading the i-th book, it takes LRJ time[i] minutes. But some books are similar in the content. If the i-th book and the j-th book are similar, then if LRJ has finished reading the i-th book, it will take him only
![](http://acm.szu.edu.cn/wiki/images/math/4/9/e/49eee5fb28cdc2a951196a7d52ebdc85.png)
minutes to finish reading the j-th book. Of course if LRJ has finished reading the j-th book, it will take him only
![](http://acm.szu.edu.cn/wiki/images/math/7/8/2/782cb5e9b8fabc84a9ca29fc6bcfbdb1.png)
minutes to finish reading the i-th book. Now you are asked to tell LRJ the minimal total time to finish reading all the N books.
Input
The first line contains two integers![](http://acm.szu.edu.cn/wiki/images/math/c/1/7/c178f9f9243070b5e0feff528fd0c143.png)
and
![](http://acm.szu.edu.cn/wiki/images/math/2/2/4/224c70b34383b7e5aff2963d04be9725.png)
. N is the total number of books. M is the number of pairs which are similar.
Then the following N lines describe
![](http://acm.szu.edu.cn/wiki/images/math/1/4/5/1459b0ed33eba9589b4a16d6b24a83d0.png)
.
Next comes M lines, each contains two integer (i,j), indicating that the i-th book and the j-th book are similar.
Input is ended with EOF.
Output
For each test case, just output the minimal total time on a single line.Sample Input
2 1 6 10 0 1 3 2 1 2 3 0 1 1 2 3 1 2 4 6 0 1
Sample Output
11 3 10
Hint:For the first test case, if LRJ read the books in the order (0, 1), then the total time = 6+10/2=11; If in the order (1, 0), then the total time =10+ 6/2=13.
Ps :这道题我看错题意了,导致一直无法AC,而且被无法言喻的提示误导了。原来这个(0,1)顺序是自动找出i,j 书最少时间的,思想错了,导致做了一下午无法解决
其实少了dd这个老师,挺难过的说。
#include<stdio.h> int num[120]; int root(int n) { if(n!=num ) n=root(num ); return n; } int main() { int m,n,i,sum,a,b,time[120]; while(scanf("%d%d",&m,&n)!=EOF){ for(i=0;i<m;i++){ scanf("%d",&time[i]); num[i]=i; } for(i=0;i<n;i++){ scanf("%d%d",&a,&b); a=root(a); b=root(b); if(time[a]<time[b]) num[b]=a; else num[a]=b; } sum=0; for(i=0;i<m;i++){ if(num[i]==i) sum+=time[i]; else sum+=time[i]/2; } printf("%d\n",sum); } return 0; }
相关文章推荐
- SZU:B36 Reading books
- 剑指offer-36-数组中的逆序对
- 无法打开python27_d.lib(python36_d.lib)的问题
- 【Educational Codeforces Round 36 A】 Garden
- Educational Codeforces Round 36
- Educational Codeforces Round 36 (Rated for Div. 2) E. Physical Education Lessons
- 36. Valid Sudoku
- (36) 泛型 (中) - 解析通配符 / 计算机程序的思维逻辑
- 36. 注入篇——伪静态注入
- NYOJ 36 最长公共子序列
- 《笨办法学 python3》系列练习计划——36.设计和调试
- 自定义函数 将十进制转化为16进制,将16换成 36的话,就可以转化为所有拼音字母的进制
- .net之旅-CompareValidator(36)
- Video 36 ISDN
- Windows API一日一练(36)SetWindowText函数
- CCIE学习(36)―― OSPF数据库交换(一)
- Windows API一日一练(36)SetWindowText函数
- Java编程那些事儿36—do-while语句语法
- Design Accessible Web Sites: 36 Keys to Creating Content for All Audiences and Platforms