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

推荐订阅源

量子位
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Schneier on Security
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
C
Cybersecurity and Infrastructure Security Agency CISA
Engineering at Meta
Engineering at Meta
Google DeepMind News
Google DeepMind News
酷 壳 – CoolShell
酷 壳 – CoolShell
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
T
Threat Research - Cisco Blogs
C
Cisco Blogs
Recent Announcements
Recent Announcements
S
Securelist
N
Netflix TechBlog - Medium
The Register - Security
The Register - Security
P
Privacy & Cybersecurity Law Blog
宝玉的分享
宝玉的分享
D
Darknet – Hacking Tools, Hacker News & Cyber Security
L
LINUX DO - 热门话题
T
Tor Project blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
月光博客
月光博客
AWS News Blog
AWS News Blog
P
Proofpoint News Feed
博客园 - 司徒正美
L
LINUX DO - 最新话题
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
H
Help Net Security
Spread Privacy
Spread Privacy
PCI Perspectives
PCI Perspectives
Project Zero
Project Zero
I
Intezer
T
The Blog of Author Tim Ferriss
有赞技术团队
有赞技术团队
The Last Watchdog
The Last Watchdog
C
Check Point Blog
Blog — PlanetScale
Blog — PlanetScale
B
Blog RSS Feed
MyScale Blog
MyScale Blog
V
Vulnerabilities – Threatpost
Recorded Future
Recorded Future
T
Tenable Blog
Jina AI
Jina AI
D
DataBreaches.Net
阮一峰的网络日志
阮一峰的网络日志

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