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 从食蚁兽所在的边向叶节点推,会得到一个渐渐放大的取值区间,在叶子节点上二分有几群蚂蚁符 ...
随机推荐
- 使用FileReader与FileWriter读写数据
-------------siwuxie095 工程名:TestFileRW 包名:com.siwuxie095.filerw 类名:FileReade ...
- php析构方法关于栈的问题
<?php class test{ var $name; var $sex; var $age; function __construct( $name, $sex ,$age ) { $thi ...
- vim 的小幅移动
1.操作符命令和位移 x --->删除一个字符,4x ---->删除4个字符. dw --->可以删除一个单词,d4w ---->删除4个单词. d$ ----> 删除 ...
- 383. Ransom Note 在字典数组中查找笔记数组
[抄题]: Given an arbitrary ransom note string and another string containing letters from all the magaz ...
- 766. Toeplitz Matrix斜对角矩阵
[抄题]: A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element. Now ...
- Flask 之 上下文管理
Flask上下文管理 分类: 请求上下文管理 应用上下文管理 请求上下文管理 request a. 温大爷:wsig b. 赵毅: ctx = ReuqestContext(session,reque ...
- Which Uri Encoding method should i use in C#/.net?
June 19, 2015 This too is one of the boring "factual" posts. Sorry Lachlan. I never know w ...
- java IO Nio 文件拷贝工具类Files
public static void main(String[] args) throws Exception { Files.copy(Paths.get("file/text.txt&q ...
- (转)Asp.net页面生命周期详解任我行(1)-小试牛刀,编写页面代码
原文地址:http://www.cnblogs.com/xuyubing/archive/2013/10/01/3348344.html 前言 很久很久以前,还是我在学校的时候,我就看了传智里面视频, ...
- 编写高质量代码改善C#程序的157个建议——建议47:即使提供了显式释放方法,也应该在终结器中提供隐式清理
建议47:即使提供了显式释放方法,也应该在终结器中提供隐式清理 在标准的Dispose模式中,我们注意到一个以~开头的方法,如下: /// <summary> /// 必须,防止程序员忘记 ...