HDU 3461 Code Lock(并查集+二分求幂)
At each operation, you are only allowed to move some specific subsequence of contiguous wheels up. This has the same effect of moving each of the wheels up within the subsequence.
If a lock can change to another after a sequence of operations, we regard them as same lock. Find out how many different locks exist?
InputThere are several test cases in the input.
Each test case begin with two integers N (1<=N<=10000000) and M (0<=M<=1000) indicating the length of the code system and the number of legal operations.
Then M lines follows. Each line contains two integer L and R (1<=L<=R<=N), means an interval [L, R], each time you can choose one interval, move all of the wheels in this interval up.
The input terminates by end of file marker.
OutputFor each test case, output the answer mod 1000000007Sample Input
1 1
1 1
2 1
1 2
Sample Output
1
26 题解:先放一放
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
bool cmp(int x,int y)
{
return x>y;
}
const int N=;
const int mod=1e9+;
int f[N];
int find1(int x) {return x==f[x]?x:f[x]=find1(f[x]);};
int Union(int x,int y)
{
x=find1(x),y=find1(y);
if(x==y) return ;
return f[x]=y,;
}
ll multi(int x)
{
ll ans=,tmp=;
while(x){
if(x&) ans=(ans*tmp)%mod;
tmp=(tmp*tmp)%mod;
x>>=;
}
return ans;
}
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m)){
for(int i=;i<=n+;i++) f[i]=i;
int a,b,ans=;
for(int i=;i<m;i++){
scanf("%d%d",&a,&b);
ans+=Union(a,b+);
}
printf("%lld\n",power(n-ans));
}
return ;
}
HDU 3461 Code Lock(并查集+二分求幂)的更多相关文章
- HDU 3461 Code Lock(并查集,合并区间,思路太难想了啊)
完全没思路,题目也没看懂,直接参考大牛们的解法. http://www.myexception.cn/program/723825.html 题意是说有N个字母组成的密码锁,如[wersdfj],每一 ...
- hdu 3461 Code Lock 并查集(有点难想到)★★
#include<stdio.h> #include<math.h> ]; int count; #define mod 1000000007 int find(int x) ...
- HDU 3461 Code Lock(并查集)
很好的一个题,思想特别6 题意:给你小写字母个数n,每个字母可以向上翻动,例如:d->c,a->z.然后给你m对数(L,R)(L<=R),表示[L,R]之间可以同时向上翻动,且翻动后 ...
- hdu 3461 Code Lock(并查集)2010 ACM-ICPC Multi-University Training Contest(3)
想不到这还可以用并查集解,不过后来证明确实可以…… 题意也有些难理解—— 给你一个锁,这个所由n个字母组成,然后这个锁有m个区间,每次可以对一个区间进行操作,并且区间中的所有字母要同时操作.每次操作可 ...
- HDU 3461 Code Lock(并查集的应用+高速幂)
* 65536kb,仅仅能开到1.76*10^7大小的数组. 而题目的N取到了10^7.我開始做的时候没注意,用了按秩合并,uset+rank达到了2*10^7所以MLE,所以貌似不能用按秩合并. 事 ...
- HDU 3461 思维+并查集
Code Lock 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=3461 Problem Description A lock you use has ...
- HDU 5441——Travel——————【并查集+二分查界限】
Travel Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Su ...
- Marriage Match II 【HDU - 3081】【并查集+二分答案+最大流】
题目链接 一开始是想不断的把边插进去,然后再去考虑我们每次都加进去边权为1的边,直到跑到第几次就没法继续跑下去的这样的思路,果不其然的T了. 然后,就是想办法咯,就想到了二分答案. 首先,我们一开始处 ...
- hdu 3461 Code Lock
http://acm.hdu.edu.cn/showproblem.php?pid=3461 并差集和幂取模 这道题主要是求不可操作区间. #include <cstdio> #inclu ...
随机推荐
- discuz优化10个小技巧
Discuz论坛是国内使用最多的论坛系统,现在最新版为X 3.4,X3.4 从 2018 年 1 月 1 日起只在官方 Git 发布,地址:https://gitee.com/ComsenzDiscu ...
- UILabel部分文字可点击
源代码:https://github.com/lyb5834/YBAttributeTextTapAction地址 如果想用富文本文件,可以参考的另外一篇博客; https://www.cnblogs ...
- 004-js-md5
参看地址:https://www.bootcdn.cn/blueimp-md5/
- 简明 ASP.NET Core 手册2018
https://windsting.github.io/little-aspnetcore-book/book/ 中文版 https://nbarbettini.gitbooks.io/little- ...
- 实例:使用puppeteer headless方式抓取JS网页
puppeteer google chrome团队出品的puppeteer 是依赖nodejs和chromium的自动化测试库,它的最大优点就是可以处理网页中的动态内容,如JavaScript,能够更 ...
- 将c语言的结构体定义变成对应的golang语言的结构体定义,并将golang语言结构体变量的指针传递给c语言,cast C struct to Go struct
https://groups.google.com/forum/#!topic/golang-nuts/JkvR4dQy9t4 https://golang.org/misc/cgo/gmp/gmp. ...
- Centos7下ups监控apcupsd的使用
什么是UPS UPS-Uninterrupted Power System:利用电池化学能作为后备能量,在市电断电等电网故障时,不间断地为用户设备提供(交流)电能的一种能量转换装置. UPS的主要功能 ...
- (转)Fabric CA环境的集成
PS:因为我部署的是集群(4peer+1order),需要为order,org1,org2分别建立一个CA,拿org1使用举例,获取org1根证书私钥名称:PRIVATE_KEY.sh #!/bin/ ...
- 遇到问题---hosts不起作用问题的解决方法
c:\WINDOWS\system32\drivers\etc\hosts 文件的作用是添加 域名解析 定向 比如添加 127.0.0.1 www.baidu.com 那我们访问www.baidu. ...
- SVM、LR、决策树的对比
一.LR LR,DT,SVM都有自身的特性,首先来看一下LR,工业界最受青睐的机器学习算法,训练.预测的高效性能以及算法容易实现使其能轻松适应工业界的需求.LR还有个非常方便实用的额外功能就是它并不会 ...