zoukankan      html  css  js  c++  java
  • HDU 3461 Code Lock(并查集+二分求幂)

    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

    题解:先放一放
     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstring>
     4 #include <cstdio>
     5 #include <vector>
     6 #include <cstdlib>
     7 #include <iomanip>
     8 #include <cmath>
     9 #include <ctime>
    10 #include <map>
    11 #include <set>
    12 #include <queue>
    13 using namespace std;
    14 #define lowbit(x) (x&(-x))
    15 #define max(x,y) (x>y?x:y)
    16 #define min(x,y) (x<y?x:y)
    17 #define MAX 100000000000000000
    18 #define MOD 1000000007
    19 #define pi acos(-1.0)
    20 #define ei exp(1)
    21 #define PI 3.141592653589793238462
    22 #define INF 0x3f3f3f3f3f
    23 #define mem(a) (memset(a,0,sizeof(a)))
    24 typedef long long ll;
    25 ll gcd(ll a,ll b){
    26     return b?gcd(b,a%b):a;
    27 }
    28 bool cmp(int x,int y)
    29 {
    30     return x>y;
    31 }
    32 const int N=10000005;
    33 const int mod=1e9+7;
    34 int f[N];
    35 int find1(int x) {return x==f[x]?x:f[x]=find1(f[x]);};
    36 int Union(int x,int y)
    37 {
    38     x=find1(x),y=find1(y);
    39     if(x==y) return 0;
    40     return f[x]=y,1;
    41 }
    42 ll multi(int x)
    43 {
    44     ll ans=1,tmp=26;
    45     while(x){
    46         if(x&1) ans=(ans*tmp)%mod;
    47         tmp=(tmp*tmp)%mod;
    48         x>>=1;
    49     }
    50     return ans;
    51 }
    52 int main()
    53 {
    54     int n,m;
    55     while(~scanf("%d%d",&n,&m)){
    56         for(int i=1;i<=n+2;i++) f[i]=i;
    57         int a,b,ans=0;
    58         for(int i=0;i<m;i++){
    59             scanf("%d%d",&a,&b);
    60             ans+=Union(a,b+1);
    61         }
    62         printf("%lld
    ",power(n-ans));
    63     }
    64     return 0;
    65 }
  • 相关阅读:
    linux磁盘简介
    linux用户管理、su和sudo、文件权限、SUID/SGID/SBIT
    dubbo框架的使用方法。。。
    Linux 配置 dubbo 和 dubbo的简单介绍。
    单列模式简单介绍
    Linux配置zookeeper 和zookeeper简单介绍
    Linux配置 ftp 和 ftp简单介绍
    正向代理 、反向代理, 和 Linux系统配置nginx。
    Linux配置Redis集群 和 缓存介绍。
    Linux 集群 和免秘钥登录的方法。
  • 原文地址:https://www.cnblogs.com/wydxry/p/7295645.html
Copyright © 2011-2022 走看看