2015多校第九场 HDU 5400 Arithmetic Sequence 数学
来源:互联网 发布:免费超市播音软件 编辑:程序博客网 时间:2024/05/29 12:36
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5400
题意:定义(d1,d2)算术序列为:对于给定的序列b1,b2,...,bn,存在i使得bj+1=bj+d1( j∈[1,i) );bj+1=bj+d2(j∈[i,n)).现在给出d1,d2和一个序列a1,a2,...,an,找出有多少个区间[l,r]满足(d1,d2)算术序列。
解法:我们可以找出对于给定的序列,满足算术序列的所有最大子串的长度,然后对于每一个子串,找出他的所有子串即可。对于一个长度为n的序列,其所有非空子串的个数为n(n+1)/2(可以由挡板原理算出)。加了读入挂竟然跑到了HDU上面的第一名。
#include <bits/stdc++.h>using namespace std;typedef long long LL;const int maxn = 100010;int n, x, y, d1, d2, sub[maxn];struct FastIO{ static const int S = 1310720; int wpos; char wbuf[S]; FastIO() : wpos(0) {} inline int xchar() { static char buf[S]; static int len = 0, pos = 0; if (pos == len) pos = 0, len = fread(buf, 1, S, stdin); if (pos == len) exit(0); return buf[pos ++]; } inline int xuint() { int c = xchar(), x = 0; while (c <= 32) c = xchar(); for (; '0' <= c && c <= '9'; c = xchar()) x = x * 10 + c - '0'; return x; } inline int xint() { int s = 1, c = xchar(), x = 0; while (c <= 32) c = xchar(); if (c == '-') s = -1, c = xchar(); for (; '0' <= c && c <= '9'; c = xchar()) x = x * 10 + c - '0'; return x * s; } inline void xstring(char *s) { int c = xchar(); while (c <= 32) c = xchar(); for (; c > 32; c = xchar()) * s++ = c; *s = 0; } inline void wchar(int x) { if (wpos == S) fwrite(wbuf, 1, S, stdout), wpos = 0; wbuf[wpos ++] = x; } inline void wint(LL x) { if (x < 0) wchar('-'), x = -x; char s[24]; int n = 0; while (x || !n) s[n ++] = '0' + x % 10, x /= 10; while (n--) wchar(s[n]); wchar('\n'); } inline void wstring(const char *s) { while (*s) wchar(*s++); } ~FastIO() { if (wpos) fwrite(wbuf, 1, wpos, stdout), wpos = 0; }} io;int main(){ while(1) { n = io.xint(); d1 = io.xint(); d2 = io.xint(); y = io.xint(); for(int i=1; i<n; i++){ x = y; y=io.xint(); sub[i] = y-x; } sub[n] = 0x3f3f3f3f; bool flag = 1; LL ans = n; int l = 0, r = 0; for(int i=1; i<=n; i++) { if(sub[i] == d1 && flag){ l++; } else if(sub[i] == d2){ r++; flag = false; } else{ ans += 1LL*(l+r)*(l+r+1)/2; l = r = 0; flag = true; if(sub[i] == d1){ l++; } } } io.wint(ans); } return 0;}
阅读全文
0 0
- 2015多校第九场 HDU 5400 Arithmetic Sequence 数学
- 多校第九场Arithmetic Sequence题解
- Arithmetic Sequence(多校第九场)
- 多校第九场 1005 hdu 5400 Arithmetic Sequence ( dp)
- HDU-5400 Arithmetic Sequence(数学 || DP)
- HDU 5400 Arithmetic Sequence(数学,容斥)
- Hdu 5400 Arithmetic Sequence 数学推理
- HDU 5400 Arithmetic Sequence(数学)——多校练习9
- HDU 5400 Arithmetic Sequence
- hdu 5400 Arithmetic Sequence
- HDU 5400 Arithmetic Sequence
- HDU 5400 Arithmetic Sequence
- HDU 5400 Arithmetic Sequence
- hdu 5400 Arithmetic Sequence
- hdu 5400 Arithmetic Sequence
- hdu 5400 Arithmetic Sequence
- HDU 5400 Arithmetic Sequence (2015年多校比赛第9场)
- HDU 5400 Arithmetic Sequence(2015 Multi-University Training Contest 9 2015多校联合)
- Mysql运行sql文件报2013错误的原因及解决办法
- ClassLoader 原理
- 工欲善其事必先利其器之熟悉 Xcode 的使用
- Nginx之解压编译安装-yellowcong
- 剑指offer 之 树的子结构
- 2015多校第九场 HDU 5400 Arithmetic Sequence 数学
- Servlet生命周期
- MySQL删除重复记录的方法
- Java迭代器模式
- 关于stm32的串口
- WHUST 2017 Div.2 Day 9 [2017-07-29]
- 数据库锁机制
- Linux 软件安装到 /usr,/usr/local/ 还是 /opt 目录?
- MySQL数据库入门练习100句