惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
WordPress大学
WordPress大学
S
SegmentFault 最新的问题
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
The Cloudflare Blog
L
LangChain Blog
博客园 - 司徒正美
G
Google Developers Blog
博客园 - 【当耐特】
GbyAI
GbyAI
月光博客
月光博客
人人都是产品经理
人人都是产品经理
D
DataBreaches.Net
大猫的无限游戏
大猫的无限游戏
A
About on SuperTechFans
Microsoft Azure Blog
Microsoft Azure Blog
V
Visual Studio Blog
D
Docker
MongoDB | Blog
MongoDB | Blog
Vercel News
Vercel News
Stack Overflow Blog
Stack Overflow Blog
Jina AI
Jina AI
博客园 - 聂微东

博客园 - saintqdd

pku 2777 Count Color 解体报告 石子合并问题 nkoj1139和乘积最大那题一样. A Tour in Loquat Orchard (FZU 2007 ICPC Qualification Round I tzw) 最大黑区域 滑雪 一道经典题,humble number 今天碰到了一个很诡异的题,Alphacode (zoj 2202) 这两天经常碰到dp题,就写了一个0-1背包 实训以来,到这里的次数少了! 郁闷,乘积最大那题WA原来只是因为我用了pow函数引起的! Smith Number POJ强烈推荐50题 JOJ 2391 words POJ 1014 三十分钟掌握STL STL学习小记 POJ1006,中国剩余定理 POJ1003,简单题
hdu 1102 pku 2421 解题报告
saintqdd · 2007-11-07 · via 博客园 - saintqdd

这题很简单,我差不多15分钟就写好代码了,运行结果也是正确的。可提交就是RE,百思不得其解,调了两个小时的时候,我才忽然发现我存边的时候数组开小了,我当时也想到肯定是数组问题,但是我却忽律了图的边不等于顶点的个数,我是拿顶点个数来开的数组(我不是用矩阵存的)。改过之后,就AC了。

 1 #include<iostream>
 2 #include<algorithm>
 3 using namespace std;
 4 #define MAXN 110
 5 struct edge{
 6   int s;
 7   int e;
 8   int dis;
 9 }a[MAXN*60];
10 
11 int N,Q,pre[MAXN],rank[MAXN];
12 
13 void init(){
14   int i;
15   for(i=1;i<=N;i++){
16     pre[i]=-1;
17     rank[i]=1;
18   }
19 }
20 
21 int find(int i){
22   if(pre[i]==-1return i;
23   else return pre[i]=find(pre[i]);
24 }
25 
26 void Union(int i,int j){
27   i=find(i);
28   j=find(j);
29   if(i==j) return;
30   int temp=rank[i]+rank[j];
31   if(rank[i]<rank[j]){
32     pre[i]=j;
33     rank[j]=temp;
34   }
35   else{
36     pre[j]=i;
37     rank[i]=temp;
38   }
39 }
40 int cmp(const void *c,const void *b){
41   return (*(edge*)c).dis-(*(edge*)b).dis;
42 }
43 int main(){
44   int i,j,k,temp;
45   int z,y,sum;
46   while(scanf("%d",&N)!=-1){ 
47     k=0;
48     for(i=1;i<=N;i++){
49       for(j=1;j<=i;j++) scanf("%d",&temp);
50       for(;j<=N;j++){
51         scanf("%d",&temp);
52         a[k].s=i;
53         a[k].e=j;
54         a[k].dis=temp;
55         k++;
56       }
57     }
58     qsort(a,k,sizeof(a[0]),cmp);
59     init();
60     scanf("%d",&Q);
61     while(Q--){
62       scanf("%d%d",&z,&y);
63       Union(z,y);
64     }
65     sum=0;
66     for(i=0;i<k;i++){
67       if(find(a[i].s)!=find(a[i].e)){
68         sum+=a[i].dis;
69         Union(a[i].s,a[i].e);
70       }
71     }
72     printf("%d\n",sum);
73   }    
74 }