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

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
H
Hacker News: Front Page
A
About on SuperTechFans
云风的 BLOG
云风的 BLOG
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
博客园 - 叶小钗
Last Week in AI
Last Week in AI
Recent Announcements
Recent Announcements
P
Palo Alto Networks Blog
Webroot Blog
Webroot Blog
Hacker News: Ask HN
Hacker News: Ask HN
IT之家
IT之家
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
Google DeepMind News
Google DeepMind News
Hugging Face - Blog
Hugging Face - Blog
H
Help Net Security
P
Privacy & Cybersecurity Law Blog
C
Cisco Blogs
罗磊的独立博客
The GitHub Blog
The GitHub Blog
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
Y
Y Combinator Blog
AWS News Blog
AWS News Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
K
Kaspersky official blog
博客园 - 司徒正美
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Security Archives - TechRepublic
Security Archives - TechRepublic
The Last Watchdog
The Last Watchdog
Jina AI
Jina AI
MyScale Blog
MyScale Blog
TaoSecurity Blog
TaoSecurity Blog
大猫的无限游戏
大猫的无限游戏
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cisco Talos Blog
Cisco Talos Blog
美团技术团队
T
Tor Project blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园 - 【当耐特】
博客园 - 聂微东
V2EX - 技术
V2EX - 技术
I
Intezer
V
Visual Studio Blog
酷 壳 – CoolShell
酷 壳 – CoolShell

博客园 - 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 }