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 }
  • 相关阅读:
    js模板引擎v5
    js模板引擎v6
    python cookbook学习笔记[一次完成多个字符串的替换]
    您可能没注意到的ie6 select bug
    lambda参数写法问题
    python dict2种遍历方式及区别
    记一次 AXI id debug
    R2B fpga flow script
    axi 1.0
    advanced fpga design
  • 原文地址:https://www.cnblogs.com/wydxry/p/7295645.html
Copyright © 2011-2022 走看看