BZOJ 2935/ Poi 1999 原始生物
【bzoj2935】【Poi1999】原始生物
2935: [Poi1999]原始生物
Time Limit: 3 Sec Memory Limit: 128 MB
Submit: 145 Solved: 71
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
2 3
3 9
9 6
8 5
5 7
7 6
4 5
5 1
1 4
4 2
2 8
8 6
Sample Output
注:
PIE.IN中的所有特征都包含在以下遗传密码中:
(8, 5, 1, 4, 2, 3, 9, 6, 4, 5, 7, 6, 2, 8, 6)
#include<cstdio>
//#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define INF 0x3f3f3f3f
#define re register
#define Ii inline int
#define Il inline long long
#define Iv inline void
#define Ib inline bool
#define Id inline double
#define ll long long
#define Fill(a,b) memset(a,b,sizeof(a))
#define R(a,b,c) for(register int a=b;a<=c;++a)
#define nR(a,b,c) for(register int a=b;a>=c;--a)
#define Min(a,b) ((a)<(b)?(a):(b))
#define Max(a,b) ((a)>(b)?(a):(b))
#define Cmin(a,b) ((a)=(a)<(b)?(a):(b))
#define Cmax(a,b) ((a)=(a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):-(a))
#define D_e(x) printf("&__ %d __&\n",x)
#define D_e_Line printf("-----------------\n")
using namespace std;
const int N=;
Ii read(){
int s=,f=;char c;
for(c=getchar();c>''||c<'';c=getchar())if(c=='-')f=-;
while(c>=''&&c<='')s=s*+(c^''),c=getchar();
return s*f;
}
Iv print(int x){
if(x<)putchar('-'),x=-x;
if(x>)print(x/);
putchar(x%^'');
}
int fa[N],deg[N],vis[N],tag[N];
Ii Find(int x){
return x==fa[x]?x:fa[x]=Find(fa[x]);
}
int main(){
int m=read(),n=;
R(i,,n)fa[i]=i;//Father
R(i,,m){
int u=read(),v=read();
++deg[u],--deg[v],//Out- In
vis[u]=,vis[v]=,
fa[Find(u)]=Find(v);//Union
}
int sum=;
R(i,,n)
if(deg[i])
tag[Find(i)]=,//In the same tag
sum+=abs(deg[i]);
int k=;
R(i,,n)
if(vis[i]&&Find(i)==i&&!tag[i])
++k;//Totol tags
print(k+(sum>>)+m);
return ;
}
/*
5
1 3
3 4
2 4
4 7
4 6 6
1 2
1 3
1 6
2 3
3 4
2 5
*/
BZOJ 2935/ Poi 1999 原始生物的更多相关文章
- bzoj 2936 [Poi 1999] 降水 - 并查集
题目传送门 需要root权限的传送门 题目大意 有一个$n\times m$的网格图,每一格都有一个高度.一次降雨过后问最多能积多少水. 考虑算每一高度能储存的水的量. 如果小于等于这个高度的格子和边 ...
- bzoj 2935 [Poi1999]原始生物——欧拉回路思路!
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2935 有向图用最小的路径(==总点数最少)覆盖所有边. 完了完了我居然连1999年的题都做不 ...
- 【刷题】BZOJ 2935 [Poi1999]原始生物
Description 原始生物的遗传密码是一个自然数的序列K=(a1,...,an).原始生物的特征是指在遗传密码中连续出现的数对(l,r),即存在自然数i使得l=ai且r=ai+1.在原始生物的遗 ...
- [BZOJ 3747] [POI 2015] Kinoman【线段树】
Problem Link : BZOJ 3747 题解:ZYF-ZYF 神犇的题解 解题的大致思路是,当区间的右端点向右移动一格时,只有两个区间的左端点对应的答案发生了变化. 从 f[i] + 1 到 ...
- [BZOJ 2083] [POI 2010] Intelligence test
Description 霸中智力测试机构的一项工作就是按照一定的规则删除一个序列的数字,得到一个确定的数列.Lyx很渴望成为霸中智力测试机构的主管,但是他在这个工作上做的并不好,俗话说熟能生巧,他打算 ...
- bzoj 1112 poi 2008 砖块
这滞胀题调了两天了... 好愚蠢的错误啊... 其实这道题思维比较简单,就是利用treap进行维护(有人说线段树好写,表示treap真心很模板) 就是枚举所有长度为k的区间,查出中位数,计算代价即可. ...
- BZOJ 4726 POI 2017 Sabota? 树形DP
4726: [POI2017]Sabota? Time Limit: 20 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 128 Solved ...
- [BZOJ 1124][POI 2008] 枪战 Maf
1124: [POI2008]枪战Maf Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 659 Solved: 259[Submit][Status ...
- bzoj 3872 [ Poi 2014 ] Ant colony —— 二分
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3872 从食蚁兽所在的边向叶节点推,会得到一个渐渐放大的取值区间,在叶子节点上二分有几群蚂蚁符 ...
随机推荐
- jps, jinfo命令
jps主要用来输出JVM中运行的进程状态信息. -q 不输出类名.Jar名和传入main方法的参数 -m 输出传入main方法的参数 -l 输出main类或Jar的全限名 -v 输出传入JVM的参数 ...
- 345. Reverse Vowels of a String翻转字符串中的元音字母
[抄题]: Write a function that takes a string as input and reverse only the vowels of a string. Example ...
- 557. Reverse Words in a String III 翻转句子中的每一个单词
[抄题]: Given a string, you need to reverse the order of characters in each word within a sentence whi ...
- Docker学习笔记_安装和使用Redis
一.准备 1.宿主机OS:Win10 64位 2.虚拟机OS:Ubuntu18.04 3.操作账号:Docker 二.安装过程 1.搜索Redis su ...
- UOJ 176 新年的繁荣
挺妙的解法. 发现边权很小,我们可以考虑从大到小枚举边权来进行$kruskal$算法,这样子对于每一个边权$i$,我们只要枚举$0 \leq j < m$,找到一个点使它的点权为$i | 2^j ...
- vuex 数据绑定
操作文档: 安装vuex: cnpm install vuex --save 文档介绍: https://vuex.vuejs.org/guide/modules.html import Vu ...
- Reportng 的测试报告在 Jenkins 中显示不全
通过Jenkins执行接口测试生成测试报告,用Jenkins的web服务打开html显示不全. 环境: Jenkins版本:1.651.2 Jenkins发布在mac上面 使用的是testng管理测试 ...
- Controlling Session Behavior in Asp.Net MVC4
Posted By : Shailendra Chauhan, 06 Jan 2013 Updated On : 11 Jun 2014 By default, Asp.Net MVC support ...
- Asp.net MVC 基于Area的路由映射
对于一个较大规模的Web应用,我们可以从功能上通过Area将其划分为较小的单元.每个Area相当于一个独立的子系统,具有一套包含Models.Views和Controller在内的目录结构和配置文件. ...
- Eclipse下的Hadoop应用开发准备
window下开发的准备: A.在windows的某个目录下解压一个hadoop的安装包 B.将安装包下的lib和bin目录用对应windows版本平台编译的本地库替换 C.在window系统中配置H ...