zoukankan      html  css  js  c++  java

# Too Simple

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1214    Accepted Submission(s): 406

Problem Description
Rhason Cheung had a simple problem, and asked Teacher Mai for help. But Teacher Mai thought this problem was too simple, sometimes naive. So she ask you for help.

Teacher Mai has

Input
For each test case, the first lines contains two numbers

Output
For each test case print the answer modulo

Sample Input
3 3 1 2 3 -1 3 2 1

Sample Output
1
Hint
The order in the function series is determined. What she can do is to assign the values to the unknown functions.

一开始看起来很复杂，想了想发现只要保证最后一个函数是任意的，中间的其他函数都没问题。
但是有一个坑的情况是，可能一个任意函数也没有，全都是固定的函数，这时要验证这组函数是否可行。我们当时验证的顺序弄反，卡了一场，真是too simple。
最近做的题都是模拟题啊，，，太没技术含量了，，，，

 1 #include <cstdio>
2 #include <algorithm>
3 #include <cstring>
4 #include <ctype.h>
5 #include <cstdlib>
6 #include <stack>
7 #include <set>
8 #include <map>
9 #include <queue>
10 #include <string>
11 #include <cmath>
12
13 using namespace std;
14 const long long MOD = 1e9+7;
15
16 int N,T,M;
17 int func[200][200],vis[200];
18 long long nn;
19
20 long long qpow(long long a,long long i,long long n)
21 {
22     if(i == 0) return 1 % n;
23     long long temp = qpow(a,i>>1,n);
24         temp = temp * temp % n;
25     if( i&1 ) temp = temp * a % n;
26     return temp;
27 }
28
29 long long mi(long long a,int t)
30 {
31     long long ans = 1;
32     for(int i=0;i<t;i++) {ans *= a;ans %= MOD;}
33     return ans;
34 }
35
36 long long solve()
37 {
38     for(int i=1;i<=N;i++)
39     {
40         int ans = i;
41         for(int j=M-1;j>=0;j--)
42         {
43             ans = func[j][ans-1];
44         }
45         if(ans != i) return 0LL;
46     }
47     return 1LL;
48 }
49
50 int main()
51 {
52     while(~scanf("%d%d",&N,&M))
53     {
54         long long cnt = 0LL,ans = 0LL;
55         nn = 1LL;
56         int flag = 0;
57         for(int i=1; i <= N;i++) {nn *= i; nn %= MOD;}
58
59         for(int i=0;i<M;i++)
60         {
61             memset(vis,0,sizeof vis);
62             if(scanf("%d",&func[i][0]) && (func[i][0] == -1))
63             {
64                 cnt++;
65             }
66             else
67             {
68                 vis[func[i][0]]++;
69                 for(int j=1;j<N;j++)
70                 {
71                     scanf("%d",&func[i][j]);
72                     if( vis[func[i][j]] ) flag = 1;
73                     else vis[func[i][j]]++;
74                 }
75             }
76         }
77
78         if(flag) ans = 0LL;
79         else if(cnt > 0) { ans = mi(nn,cnt-1); ans %= MOD;}
80         else
81         {
82             ans = solve();
83         }
84
85         printf("%I64d
",ans%MOD);
86     }
87 }

• 相关阅读:
Ribbon 和 Eureka 积分
zabbix 实现curl 显示器
《算法入门经典大赛——培训指南》第二章考试
今天你还抽象？
Big Data Security Part One: Introducing PacketPig
Big Data Analytics for Security（Big Data Analytics for Security Intelligence）
CA
通过Shell和Redis来实现集群业务中日志的实时收集分析
用Maven编译Apache flume-ng 1.5.0源码及问题解决