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 ...
随机推荐
- centos安装Django之三:安装python
这是centos安装Django系列第三篇,安装python.centos系统已经自带了python2.6,但是它被系统很多程序所依赖,不建议删除.我们可以使用以下命令来查看我们使用的Python版本 ...
- MySQL8.0.11 组复制配置
my.cnf [mysql] prompt='node2 [\h] {\u} (\d) > ' # [client] user = sa password = cc.123 port = 22 ...
- [php] 索引数组合并选择两数组相加
header("Content-Type:text/html;charset=utf-8");$arr1= Array ( 0 => Array ( 'pic' => ...
- Dell R730服务器 Raid0 Raid5配置
Dell R730服务器,有7块5t硬盘,默认做的RAID5.我们的目的是取其中6块硬盘做RAID5,留一块硬盘做热备. 一块SSD系统盘. 在这里,我具体解释一下 ①6块硬盘做成RAID5 ②6块硬 ...
- 2019.03.24 Ajax
也还是会用到jquery中的Ajax请i求 所以第一还是引入jQuery包 可以去网上搜腾讯网静态资源库 然后引入包 Ajax还是异步处理 处理堵塞问题 import time 就可以了 ...
- 前端MD5加密【单向加密】
密码存储的方式: 密码该如何存储呢?按照安全性由低到高,有这样几种选择: 1.密码名文直接存储在系统中 2.密码经过对称加密后再存储 3.密码经过非对称加密后再存储 步骤: 1.用户端:用户提交用户名 ...
- json.dumps与json.loads实例
import json data= { 'no' : 1, 'name' : 'Runoob', 'url' : 'http:\\www.runoob.com' } json_str = json.d ...
- [Java in NetBeans] Lesson 17. File Input/Output.
这个课程的参考视频和图片来自youtube. 主要学到的知识点有: We want to handle the bad Error. (e.g bad input / bugs in program) ...
- mac 进程和线程工具
进程 查看端口进程 lsof lsof -i tcp:<port> 示例 $ lsof -i tcp:8082 COMMAND PID USER FD TYPE DEVICE SIZE/O ...
- 隐藏apache服务器信息
安装完apache一般第一时间都是关闭apache的版本信息,黑客会通过apache暴露出来的信息针对性的入侵,为了服务器的安全这些信息一定要及时关闭. 1.隐藏PHP版本 修改php.ini exp ...