多校 9
来源:互联网 发布:阿里云地址 编辑:程序博客网 时间:2024/05/29 09:18
Arithmetic Sequence
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 0 Accepted Submission(s): 0
Problem Description
A sequence b1,b2,⋯,bn are called (d1,d2) -arithmetic sequence if and only if there exist i(1≤i≤n) such that for every j(1≤j<i),bj+1=bj+d1 and for every j(i≤j<n),bj+1=bj+d2 .
Teacher Mai has a sequencea1,a2,⋯,an . He wants to know how many intervals [l,r](1≤l≤r≤n) there are that al,al+1,⋯,ar are (d1,d2) -arithmetic sequence.
Teacher Mai has a sequence
Input
There are multiple test cases.
For each test case, the first line contains three numbersn,d1,d2(1≤n≤105,|d1|,|d2|≤1000) , the next line contains n integers a1,a2,⋯,an(|ai|≤109) .
For each test case, the first line contains three numbers
Output
For each test case, print the answer.
Sample Input
5 2 -20 2 0 -2 05 2 32 3 3 3 3
Sample Output
125
#include <cstdio>#include <iostream>#include <cstring>using namespace std;#define N 100000 + 5#define LL long longint a[N];int D1[N], D2[N];int d1, d2;int n;int main(){ while(~scanf("%d%d%d", &n, &d1, &d2)) { for(int i = 1; i <= n; i++) scanf("%d", a + i); D1[1] = D2[1] = 1; int cn1 = 1, cn2 = 1; for(int i = 2; i <= n; i++) { if(a[i] == a[i - 1] + d1) cn1++; else cn1 = 1; D1[i] = cn1; if(a[i] == a[i - 1] + d2) cn2++; else cn2= 1; D2[i] = cn2; }// for(int i = 1; i <= n; i++)// cout<<D1[i]<<" ";// cout<<endl;//// for(int i = 1; i <= n; i++)// cout<<D2[i]<<" ";// cout<<endl; LL ans = 0; for(int i = 1; i <= n; i++) { if(D1[i] >= 2) { ans += D1[i]; } else if(D2[i] >= 2) { int t = i - D2[i] + 1; ans += (D1[t] + D2[i] - 1); //cout<<i<<": "<<D1[t] + D2[i]<<endl; } else ans += 1; } printf("%I64d\n", ans); }}/*9 1 -11 2 3 4 5 4 3 2 1*/
Too Simple
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 429 Accepted Submission(s): 83
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 hasm functions f1,f2,⋯,fm:{1,2,⋯,n}→{1,2,⋯,n} (that means for all x∈{1,2,⋯,n},f(x)∈{1,2,⋯,n} ). But Rhason only knows some of these functions, and others are unknown.
She wants to know how many different function seriesf1,f2,⋯,fm there are that for every i(1≤i≤n) ,f1(f2(⋯fm(i)))=i . Two function series f1,f2,⋯,fm and g1,g2,⋯,gm are considered different if and only if there exist i(1≤i≤m),j(1≤j≤n) ,fi(j)≠gi(j) .
Teacher Mai has
She wants to know how many different function series
Input
For each test case, the first lines contains two numbers n,m(1≤n,m≤100) .
The following arem lines. In i -th line, there is one number −1 or n space-separated numbers.
If there is only one number−1 , the function fi is unknown. Otherwise the j -th number in the i -th line means fi(j) .
The following are
If there is only one number
Output
For each test case print the answer modulo 109+7 .
Sample Input
3 31 2 3-13 2 1
Sample Output
1HintThe order in the function series is determined. What she can do is to assign the values to the unknown functions.
#include <cstdio>#include <iostream>#include <cstring>using namespace std;#define N 100 + 5#define LL long longconst int mod = 1000000000 + 7;int n, m;int f[N][N];int cnt;int mul_pow(int a, int k){ int res = 1; while(k) { if(k & 1) res = ((long long)res * a) % mod; a = ((long long)a * a) % mod; k >>= 1; } return res;}int fact(int a){ int res = 1; for(int i = 1; i <= a; i++) res = ((LL)res * i) % mod; return res;}bool h[N];int op[N];int main(){ while(~scanf("%d%d", &n, &m)) { memset(op, 0, sizeof op); int t; cnt = 0; for(int i = 1; i <= m; i++) { scanf("%d", &t); if(t == -1) { op[i] = 1; cnt++; } else { f[i][1] = t; for(int j = 2; j <= n; j++) scanf("%d", &f[i][j]); } } int flag = 0; for(int i = 1; i <= m; i++) { memset(h, false, sizeof h); if(op[i] == 0) for(int j = 1; j <= n; j++) { t = f[i][j]; if(h[t] || t > n || t <= 0) { //cout<<i<<" "<<j<<endl; flag = 1; break; } h[t] = true; } } if(flag) { printf("0\n"); continue; } flag = 0; if(cnt == 0) { for(int i = 1; i <= n; i++) { t = i; for(int j = m; j >= 1; j--) t = f[j][t]; if(t != i) { flag = 1; break; } } if(flag) printf("0\n"); else printf("1\n"); } else { t = fact(n); int ans = mul_pow(t, cnt - 1); printf("%d\n", ans); } } return 0;}
1 0
- 多校 9
- 8#9 - 多校6
- 2017多校-9
- 多校9 Numbers HDU
- HDU 6161 (2017多校9
- hdu4381Count the Building-多校9-1002-题解
- 2013 多校9 1005 EBCDIC - from lanshui_Yang
- hdu5399(2015多校9)--Too Simple
- hdu6168-多校9&stl&模拟- Numbers
- HDU 6166 Senior Pan (2017多校9
- Two strings 2017 多校 9 J
- HDU6170-Two strings 多校9 dp
- 多校
- 多校
- 多校
- hdu4389-X mod f(x)-多校9-1010题解
- hdu4389-X mod f(x)-多校9-1010题解
- 2014多校9(1007)hdu4966(最小树形图)
- 矩阵相乘优化算法实现讲解
- VS2010下libevent的如何使用
- springmvc注解
- COGS 526 又是一道模板题——左偏树
- hdu2099
- 多校 9
- 40.UITableViewController和刷新
- Android 调用已安装市场,进行软件评分的功能实现
- 王道论坛 程序员求职宝典 学习笔记
- android程序正常运行,但LogCat没有显示—解决办法
- hdu1007
- hdoj 2066 一个人的旅行(dijkstra)多源点多
- iOS操作属性列表plist(增删改查)
- i+1问题