hud3018 解题报告
来源:互联网 发布:允儿好看还是js卡好看 编辑:程序博客网 时间:2024/05/16 08:03
Ant Trip
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 860 Accepted Submission(s): 324
Problem Description
Ant Country consist of N towns.There are M roads connecting the towns.
Ant Tony,together with his friends,wants to go through every part of the country.
They intend to visit every road , and every road must be visited for exact one time.However,it may be a mission impossible for only one group of people.So they are trying to divide all the people into several groups,and each may start at different town.Now tony wants to know what is the least groups of ants that needs to form to achieve their goal.
Ant Tony,together with his friends,wants to go through every part of the country.
They intend to visit every road , and every road must be visited for exact one time.However,it may be a mission impossible for only one group of people.So they are trying to divide all the people into several groups,and each may start at different town.Now tony wants to know what is the least groups of ants that needs to form to achieve their goal.
Input
Input contains multiple cases.Test cases are separated by several blank lines. Each test case starts with two integer N(1<=N<=100000),M(0<=M<=200000),indicating that there are N towns and M roads in Ant Country.Followed by M lines,each line contains two integers a,b,(1<=a,b<=N) indicating that there is a road connecting town a and town b.No two roads will be the same,and there is no road connecting the same town.
Output
For each test case ,output the least groups that needs to form to achieve their goal.
Sample Input
3 31 22 31 34 21 23 4
Sample Output
12HintNew ~~~ Notice: if there are no road connecting one town ,tony may forget about the town.In sample 1,tony and his friends just form one group,they can start at either town 1,2,or 3.In sample3 2,tony and his friends must form two group.其实,先用并查集,分成几个部分,然后,把每个部分的奇点数相加除2就可以,也就是说,分的组数和奇数点的个数的一半相等,不过要注意只有一个点的集合,不能算,要被怱略掉,才行,这一点,我错了好几次,
#include <iostream>#include <vector>#include <stdio.h>using namespace std;int down[100005],setnum[100005],in[100005],re[100005],num[100005];bool zh[100005];int fin(int x){ if(down[x]!=x) { down[x]=fin(down[x]); } return down[x];}int main(){ int n,m,k,a,b,i,s,e,j,temp; while(~scanf("%d%d",&n,&m)) { for(i=0;i<=n;i++) { zh[i]=true; num[i]=0; in[i]=0; down[i]=i; } while(m--) { scanf("%d%d",&s,&e); a=fin(s); b=fin(e); if(a!=b) { down[a]=b; } in[s]++; in[e]++; } bool zhe; int sum=0,ans; for(i=1,j=1;i<=n;i++) { temp=fin(i); zh[temp]=false; if(in[i]%2) { num[temp]++; } } for(i=1;i<=n;i++) { if((zh[i]==false)&&(num[i]==0)) { if(in[fin(i)]) sum++; } else if((zh[i]==true)&&(num[i]==0)) { continue; } else { sum+=num[i]/2; } } printf("%d\n",sum); } return 0;}
Source
2009 Multi-University Training Contest 12 - Host by FZU
- hud3018 解题报告
- 解题报告
- 解题报告
- 解题报告
- 解题报告
- 解题报告
- 解题报告
- 解题报告
- Antiprime解题报告
- expr解题报告
- 华容道解题报告
- tju解题报告
- zju1062/pku1095解题报告
- UsacoGate解题报告 --- 序曲
- ZJU 2060 解题报告
- ZJU 1331 解题报告
- ZJU 1115 解题报告
- ZJU1057解题报告
- 伟易达(深圳)2013.6.6实习生笔试题
- 排序算法--直接插入排序
- 我所理解的设计模式(C++实现)——责任链模式(Chain Of Responsibility Pattern)
- android Canvas(2D)详解
- rad grid, drag and drop
- hud3018 解题报告
- 这两天的情况
- 学会了处理项目中那些没有确定方案的东西(使用“策略模式”)
- Sqlite
- 文件类的常用方法
- 第十三堂课后作业
- 黑马程序员---集合框架之Map集合重点盲点总结
- VS2012下基于Glut OpenGL绘制点(添加设置点大小)示例程序:
- Extjs中三种不同的数据提交方式