Code Lock

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 255 Accepted Submission(s): 114
 
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
 
Author
hanshuai
 
Source
2010 ACM-ICPC Multi-University Training Contest(3)——Host by WHU
 
Recommend
zhouzeyong
/*
没有可操作区间的时候是26的n次方,然后多一个可操作区间,就会少26种
每一个不可操作的区间的种类数是26种,就是26^k种答案
*/
#include<bits/stdc++.h>
using namespace std;
const int mod=;
int n,m;
int l,r;
int x,y;
int bin[];
int findx(int x){
int temp=x;
while(x!=bin[x]){
x=bin[x];
}
bin[temp]=x;
return x;
}
int Union(int x,int y){
int fx=findx(x);
int fy=findx(y);
if(fx!=fy){
bin[fy]=fx;
return ;
}else return ;
}
/***********快速幂模板**************/
long long power(int n,int x){
if(x==) return ;
long long t=power(n,x/);
t=t*t%mod;
if(x%==)t=t*n%mod;
return t;
}
/***********快速幂模板**************/
int main(){
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
for(int i=;i<=n+;i++){
bin[i]=i;
}
int ans=;
for(int i=;i<m;i++){
scanf("%d%d",&x,&y);
ans+=Union(x,y+);
}
printf("%d\n",power(,n-ans));
}
}

Code Lock的更多相关文章

  1. Code Lock[HDU3461]

    Code LockTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Subm ...

  2. 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 ...

  3. hdu3461 Code Lock

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

  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. 17.tslib安装以及使用

    1.先在网上下载 tslib-1.4.tar.gz压缩包 2.然后在ubuntu编译: tar xzf tslib-1.4.tar.gz cd tslib ./autogen.sh mkdir tmp ...

  2. Manacher’s Algorithm (神啊)

    (转载自)http://blog.csdn.net/hopeztm/article/details/7932245 这里描述了一个叫Manacher’s Algorithm的算法. 算法首先将输入字符 ...

  3. Codeforces Round #309 (Div. 2)D

    C. Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  4. 移动端效果之Picker

    写在前面 接着前面的移动端效果的研究,这次来看看picker选择器的实现原理 移动端效果之Swiper 代码看这里:github 1. 核心解析 1.1 基本HTML结构 <!-- 说明: 1. ...

  5. ORACLE 本地冷迁移

    需求:把oracle数据库的数据文件,redo文件,控制文件迁移到本地的其它目录. 1.测试环境: 操作系统redhat 6.3,数据库oracle 11.2.0.1.0 [root@dbtest1 ...

  6. HDU1024 DP的优化 最大M子段和问题

    Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  7. IDL 存储数组

    IDL中的数组在内存中是按行存储的,这是因为IDL最初设计的设计目的是用来处理行扫描卫星数据. 1.一维数组 m个元素的一维数组arr[m]的存储方式为 arr[0]→arr[1]→...→arr[m ...

  8. python codis集群客户端(二) - 基于zookeeper对实例创建与摘除

    在这一篇中我们实现了不通过zk来编写codis集群proxys的api,http://www.cnblogs.com/kangoroo/p/7481567.html 如果codis集群暴露zk给你的话 ...

  9. gitlab仓库迁移

    遇到一个情况,需要将两个gitlab仓库合并.好在都是使用的ldap账户登陆,用户账户不需要迁移. 实际的使用情况下,需要迁移的主要部分为分组及分组下项目.gitlab的api还是很给力的,能够获取所 ...

  10. ActiveMQ——activemq的安装详情,修改密码

    1.安装 下载 http://activemq.apache.org/download-archives.html, [推荐]ActiveMQ 5.13.4 Release与jdk1.7搭配(其它版本 ...