这题,首先感谢google有个奇葩的手气不错,我直接用搜索都搜不到这道题,居然真的手气不错了一下!rp啊~
Code Lock |
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) |
Total Submission(s): 78 Accepted Submission(s): 30 |
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 |
码的时候还挺顺的,自己编译也没问题,提交就各种wa。数据给的好弱啊……最后发现是一个地方的long long写成了int……哎哟哎哟。
#include <iostream>
using namespace std;
#define MAX 10000010
int root[MAX];
#define MOD 1000000007
int find(int x)
{
if(root[x]!=x)
{
root[x]=find(root[x]);
}
return root[x];
}
long long binary(int x)
{
if(x==0)return 1;
long long a=binary(x/2);//a need to be long long
a=a*a%MOD;
if(x%2==1)a=a*26%MOD;
return a;
}
bool merge(int l,int r)
{
int fl=find(l);
int fr=find(r);
if(fl==fr)
return false;
else
{
root[fr]=fl;
return true;
}
}
int main()
{
int n,m;
long long ans;
while(cin>>n>>m)
{
int i;
for(i=0;i<=n;i++)
{
root[i]=i;
}
int x=0;
while(m--)
{
int l,r;
cin>>l>>r;
l--;
if(merge(l,r))
x++;
}
ans=binary(n-x);
cout<<ans<<endl;
}
system("pause");
return 0;
}
某人说的对,有的题果然是智商问题……默默流泪……