博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Code Lock 并查集&&二分求幂
阅读量:6735 次
发布时间:2019-06-25

本文共 2579 字,大约阅读时间需要 8 分钟。

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
***************************************************************************************************************************
并查集&&二分求幂
***************************************************************************************************************************
1 /* 2 并查集加二分求幂 3  4 */ 5 #include
6 #include
7 #include
8 #include
9 #include
10 using namespace std;11 #define MOD 100000000712 int fa[10000005];13 int i,j,k,n,m;14 void init()15 {16 for(int it=0;it<=n;it++)17 {18 fa[it]=it;19 }20 }21 int find(int x)22 {23 int r=x;24 while(r!=fa[r])25 r=fa[r];26 while(x!=r)27 {28 int temp=fa[x];29 fa[x]=r;30 x=temp;31 }32 return r;33 }34 bool Unon(int a,int b)35 {36 int x=find(a);37 int y=find(b);38 if(x==y)return false;39 fa[x]=y;40 return true;41 }42 __int64 pow(__int64 a,int b)43 {44 __int64 sum=1;45 while(b)46 {47 if(b&1)sum=(sum*a)%MOD;48 a=(a*a)%MOD;49 b>>=1;50 }51 return (sum%MOD);52 }53 int main()54 {55 while(scanf("%d%d",&n,&m)!=EOF)56 {57 init();58 int a,b,cnt=0;59 for(i=0;i
View Code

 

转载于:https://www.cnblogs.com/sdau--codeants/p/3407489.html

你可能感兴趣的文章
修改VS自带的模版文件
查看>>
hdu2874 LCA
查看>>
fedora中丢失或损坏fstab,无法启动,如何补救
查看>>
JAVA基本算法面试题:1斐波纳契数列
查看>>
GPU Memory Usage占满而GPU-Util却为0的调试
查看>>
iOS开发-UITapGestureRecognizer手势
查看>>
Java中的Lambda表达式
查看>>
Android中数据存储之SharedPreferences
查看>>
查询oracle中所有用户信息
查看>>
PHP数字价格格式化,保留两位小数
查看>>
MVC3.0入门学习笔记--Razor 之样式加载方式1
查看>>
Linux下LDAPSearch的例子
查看>>
创建指定大小的文件
查看>>
Java将byte[]和int的互相转换
查看>>
10.1-10.2泛型算法
查看>>
【转】Objective-C学习笔记四:循环结构
查看>>
JavaBeans 中添加 private static final long serialVersionUID = 1L
查看>>
ORACLE RAC集群硬件资源管理与单节点的区别
查看>>
洛谷 5061 秘密任务——二分图染色
查看>>
bzoj 2836 魔法树——树链剖分
查看>>