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? 

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(并查集+二分求幂)的更多相关文章

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

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

  2. hdu 3461 Code Lock 并查集(有点难想到)★★

    #include<stdio.h> #include<math.h> ]; int count; #define mod 1000000007 int find(int x) ...

  3. HDU 3461 Code Lock(并查集)

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

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

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

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

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

  6. HDU 3461 思维+并查集

    Code Lock 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=3461 Problem Description A lock you use has ...

  7. HDU 5441——Travel——————【并查集+二分查界限】

    Travel Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Su ...

  8. Marriage Match II 【HDU - 3081】【并查集+二分答案+最大流】

    题目链接 一开始是想不断的把边插进去,然后再去考虑我们每次都加进去边权为1的边,直到跑到第几次就没法继续跑下去的这样的思路,果不其然的T了. 然后,就是想办法咯,就想到了二分答案. 首先,我们一开始处 ...

  9. hdu 3461 Code Lock

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

随机推荐

  1. 自定义PopView

    改代码是参考一个Demo直接改的,代码中有一些漏洞,如果发现其他的问题,可以下方直接留言 .h文件 #import <UIKit/UIKit.h> typedef void(^Popove ...

  2. 如何在ASP.NET 网站项目中使用C# 6?

    作者:Generic链接:https://www.zhihu.com/question/48864375/answer/113316462来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业 ...

  3. 【adaboost】周志华

  4. vue中的路由高亮

  5. vue接口地址配一个全局的

    main.js加 if (process.env.NODE_ENV !== 'development') { Vue.prototype.URL_PREFIX = 'http://139.196.7. ...

  6. 根据构建类型动态设置AndroidManifest.xml文件中的meta-data

    当debug和release版本使用不同的值时,使用Gradle设置相应的值. Android主配置文件 <meta-data android:name="com.amap.api.v ...

  7. 无法连接 MKS:套接字连接尝试次数太多正在放弃

    我的电脑 -> 右键 -> 管理 -> 服务和应用程序 -> 服务: 开启下面的服务: 服务启动成功后,重启虚拟机; 或者先挂起虚拟机,等服务启动后,继续运行挂起的虚拟机:

  8. Linux用户群组权限恢复

    /etc/passwd:该文件用于存放用户详细信息:例如 root:x:0:0:root:/root:/bin/bash 用户id 0:就表示root用户 bin下的bash:表示可以登入操作系统 s ...

  9. Editplus 竖选,竖插入技巧

    竖选方法 1,Alt + C, 然后用鼠标拖选 2,按住Alt健,再用鼠标拖选 行首行尾批量添加字符 以及其它常用正则 操作:Ctrl + H, 调出查找窗口,勾选按正则表达式查询 行首批量添加   ...

  10. [LeetCode] 69. Sqrt(x)_Easy tag: Binary Search

    Implement int sqrt(int x). Compute and return the square root of x, where x is guaranteed to be a no ...