Code Lock
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 2006 Accepted Submission(s): 766

Problem Description
A lock you use has a code system to be opened instead of a key. The lock contains a sequence of wheels. Each wheel has the 26 letters of the English alphabet 'a' through 'z', in order. If you move a wheel up, the letter it shows changes to the next letter in the English alphabet (if it was showing the last letter 'z', then it changes to 'a').
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?

Input
There 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.

Output
For each test case, output the answer mod 1000000007

Sample Input
1 1
1 1
2 1
1 2

Sample Output
1
26

#include <stdio.h>
class Union_Find_Set {
#define MAX_UNION_FIND_SET_SIZE 10000010
public:
int setSize;
int father[MAX_UNION_FIND_SET_SIZE];
Union_Find_Set() {
setSize = ;
}
Union_Find_Set(int x) {
setSize = x;
clear(x);
}
void clear(int x) {
for (int i = ; i < x; i++) {
father[i] = i;
}
}
int getFather(int x) {
int ret = x, tmp;
while (ret != father[ret]) {
ret = father[ret];
}
while (x != father[x]) {
tmp = father[x];
father[x] = ret;
x = tmp;
}
return ret;
}
bool merge(int a, int b) {
a = getFather(a);
b = getFather(b);
if (a != b) {
father[a] = b;
return true;
} else {
return false;
}
}
int countRoot() {
int ret = ;
for (int i = ; i < setSize; i++) {
if (father[i] = i) {
ret++;
}
}
return ret;
}
};
Union_Find_Set ufs;
__int64 quick_Mini(__int64 base, __int64 power, __int64 mod) {
__int64 x = base, ret = ;
while (power) {
if (power & ) {
ret *= x;
ret %= mod;
}
power >>= ;
x *= x;
x %= mod;
}
return ret;
}
int main() {
int n, m, a, b, t;
while (scanf("%d%d", &n, &m) != EOF) {
ufs.clear(n + );
t = ;
for (int i = ; i < m; i++) {
scanf("%d%d", &a, &b);
if (ufs.merge(a - , b)) {
t++;
}
}
printf("%I64d\n", quick_Mini(, n - t, ));
}
return ;
}

Code Lock[HDU3461]的更多相关文章

  1. Code Lock

    Code Lock Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Su ...

  2. hdu3461 Code Lock

    Problem Description A lock you use has a code system to be opened instead of a key. The lock contain ...

  3. HDU 3461 Code Lock(并查集+二分求幂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3461 A lock you use has a code system to be opened in ...

  4. HDU 3461 Code Lock(并查集)

    很好的一个题,思想特别6 题意:给你小写字母个数n,每个字母可以向上翻动,例如:d->c,a->z.然后给你m对数(L,R)(L<=R),表示[L,R]之间可以同时向上翻动,且翻动后 ...

  5. hdu Code Lock

    题意是说有N个字母组成的密码锁, 如[wersdfj],   每一位上的字母可以转动, w可转动变成x, z变成a.但是题目规定, 只能同时转动某个区间上的所有字母, 如[1,3], 那么第1到第3个 ...

  6. HDU 3461 Code Lock(并查集,合并区间,思路太难想了啊)

    完全没思路,题目也没看懂,直接参考大牛们的解法. http://www.myexception.cn/program/723825.html 题意是说有N个字母组成的密码锁,如[wersdfj],每一 ...

  7. hdu 3461 Code Lock(并查集)2010 ACM-ICPC Multi-University Training Contest(3)

    想不到这还可以用并查集解,不过后来证明确实可以…… 题意也有些难理解—— 给你一个锁,这个所由n个字母组成,然后这个锁有m个区间,每次可以对一个区间进行操作,并且区间中的所有字母要同时操作.每次操作可 ...

  8. hdu 3461 Code Lock

    http://acm.hdu.edu.cn/showproblem.php?pid=3461 并差集和幂取模 这道题主要是求不可操作区间. #include <cstdio> #inclu ...

  9. HDU 3461 Code Lock(并查集的应用+高速幂)

    * 65536kb,仅仅能开到1.76*10^7大小的数组. 而题目的N取到了10^7.我開始做的时候没注意,用了按秩合并,uset+rank达到了2*10^7所以MLE,所以貌似不能用按秩合并. 事 ...

随机推荐

  1. UOJ#213——【UNR #1】争夺圣杯

    1.题意:给一个序列,枚举长度x,然后在这个序列中所有长度为x的区间,我们求出这些区间的最大值之和并取模,最后将所有的异或起来就好啦 2.分析:听说好多人写的 ,特来写一发 的算法骗访问量 话说这个东 ...

  2. json和jsonp

    JSON是一种数据交换格式!   JSONP是一种依靠开发人员的聪明才智创造出的一种非官方跨域数据交互协议!   一般使用JSON来传数据,靠JSONP来跨域.   JSON的优点: 1.基于纯文本, ...

  3. 怎样在Windows资源管理器中添加右键菜单以及修改右键菜单顺序

    有时,我们需要在Windows资源管理器的右键菜单中添加一些项,以方便使用某些功能或程序. 比如我的电脑上有一个免安装版的Notepad++,我想在所有文件的右键菜单中添加一项用Notepad++打开 ...

  4. python3的编码问题

    Python3对文本(str)和二进制数据(bytes)作了更为清晰的区分. 文本默认是以Unicode编码(python2默认是ascii),由str类型表示,二进制数据则由bytes类型表示. s ...

  5. JSon解析

    1.解析总是犯糊涂 在图中,[]  中括号表示是jsonarray,{} 小括号 表示对象  这个解析可以写成: JSONArray array=new JSONArray(result); for( ...

  6. Eclipse下载与安装

    有很多小伙伴不知道eclipse在哪里下载以及怎么安装的,那我来给大家做个演示吧. 学习java比较常用的软件就是eclipse,而eclipse安装后并不能马上使用,还需要安装jdk并搭建环境.下面 ...

  7. 安装yum

    RedHat 安装配置 YUM 删除 1 . 查询系统是否安装 yum : rpm – qa|grep yum 2删除原有 yum rpm -qa|grep yum|xargs rpm -e – no ...

  8. es6要用严格模式

    实验let的块级作用域,在sublime的Tools--Babel--Babel Transform检测未出现错误,在html中也未出现错误,唯在控制台中一直报错. //js名为es6.js ---* ...

  9. MySQL 5.7 安装教程

    自序:最近又要重新用上Mysql,在有道笔记找了以前自己记录怎么安装mysql5.7的笔记,发现那个时候记得笔记比较随意,看的比较费劲,现在决定重新在博客记录一下,以便以后自己查阅的时候更加方便. 1 ...

  10. 禁止换行“white-space:nowrap;”!

    "white-space:nowrap;" <html> <div class="box">精彩的生活,精彩的世界</div> ...