首页 > 其他 > 详细

HDU 3461 Code Lock

时间:2014-02-15 16:31:50      阅读:453      评论:0      收藏:0      [点我收藏+]

题解:计算出所有可以操作的区间,留下不可操作区间求26的幂次即可,注意直接合并区间端点可能会出现一些问题,所以将右端点加一:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <cstdio> 
#include <iostream>
using namespace std; 
const int mod=1000000007;
long long t; 
int f[10000010]; 
int sf(int x){return x==f[x]?x:f[x]=sf(f[x]);} 
int Union(int x,int y){ 
    x=sf(x),y=sf(y); 
    if(x==y)return 0; 
    f[x]=y; 
    return 1; 
long long power(int x){
    if(x==0)return 1; 
    long long t=power(x/2); 
    t=t*t%mod; 
    if(x%2==1)t=t*26%mod; 
    return t; 
int main(){
    int m,n,a,b;
    while(scanf("%d%d",&n,&m)!=EOF){ 
        for(int i=1;i<=n+2;i++)f[i]=i;    
        int ans=0;
        while(m--){ 
            scanf("%d%d",&a,&b); 
            ans+=Union(a,b+1);   
        
        cout<<power(n-ans)<<endl; 
    }    

HDU 3461 Code Lock

原文:http://www.cnblogs.com/forever97/p/3550477.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!