解题报告 之 HDU5288 OO' s Sequence
解题报告 之 HDU5288 OO' s Sequence
Description

rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style="">



rev=2.4-beta-2" alt="" style="">



rev=2.4-beta-2" alt="" style="">

rev=2.4-beta-2" alt="" style="">
(


rev=2.4-beta-2" alt="" style="">
)
Input
In each test case:
First line: an integer n(n<=10^5) indicating the size of array
Second line:contain n numbers a i(0<a i<=10000)
Output
Sample Input
5
1 2 3 4 5
Sample Output
23
2 3 4 5,那么子区间[1,2,3]中这种数就是1。2,3三个。然后对于子区间2 3 4,这种数就仅仅有两个,由于4有因子2也在该子区间中。
。
。比方5
5 2 3 3 4 3 2 5 5。那么对于4来说,我们找到左右两个因子2之后,就能够发现从5開始和结束的子区间都不会算到4。由于有2在那里杵着。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std; typedef long long ll;
const int MAXN = 1e5 + 10;
const int MAXM = 1e4 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7; int nums[MAXN]; //序列中的数
int lb[MAXN], rb[MAXN]; //序列中的数左右离他近期的因子的位置
int latest[MAXM];//某个数字最后出现的位置 int main()
{
int n;
while(scanf( "%d", &n ) == 1)
{
memset( lb, 0, sizeof lb );
memset( rb, INF, sizeof rb );
//reset for(int i = 1; i <= n; i++)
{
scanf( "%d", &nums[i] );
}//input for(int i = 0; i < MAXM; i++) latest[i] = 0; for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= sqrt( nums[i] ); j++)
{//遍历每一个因子
if(nums[i] % j == 0)
{
lb[i] = max( lb[i], latest[j] );
lb[i] = max( lb[i], latest[nums[i] / j] );
}
}
latest[nums[i]] = i; //更新位置。注意要遍历后更新,由于本身也是自己的因子 }// tackle 1 for(int i = 0; i < MAXM; i++) latest[i] = n + 1;
for(int i = n; i >= 1; i--)
{
for(int j = 1; j <= sqrt( nums[i] ); j++)
{
if(nums[i] % j == 0)
{
rb[i] = min( rb[i], latest[j] );
rb[i] = min( rb[i], latest[nums[i] / j] );
}
}
latest[nums[i]] = i;
}// tackle 2 同理 ll ans = 0;
for(int i = 1; i <= n; i++)
{
ans = (ans + (i - lb[i])*(rb[i] - i)) % MOD;
//统计序列中每一个数被统计的次数。能够理解为范围内左边选一个数的选法*右边选一个数的选法。
}
printf( "%lld\n", ans );
}
return 0;
}
另一种方法是,记录每一个数字出现的位置,每次更新的时候用二分去找距离它近期的因子的位置。可是非常麻烦也更慢。
解题报告 之 HDU5288 OO' s Sequence的更多相关文章
- HDU 5288 OO's sequence (2015多校第一场 二分查找)
OO's Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- LeetCode解题报告—— Jump Game & Merge Intervals & Permutation Sequence
1. Jump Game Given an array of non-negative integers, you are initially positioned at the first inde ...
- 【九度OJ】题目1442:A sequence of numbers 解题报告
[九度OJ]题目1442:A sequence of numbers 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1442 ...
- USACO Section2.1 Sorting a Three-Valued Sequence 解题报告
sort3解题报告 —— icedream61 博客园(转载请注明出处)---------------------------------------------------------------- ...
- LeetCode 解题报告索引
最近在准备找工作的算法题,刷刷LeetCode,以下是我的解题报告索引,每一题几乎都有详细的说明,供各位码农参考.根据我自己做的进度持续更新中...... ...
- 【NOIP2015】提高组D1 解题报告
P1978神奇的幻方 Accepted 描述 幻方是一种很神奇的 N ∗ N 矩阵:它由数字 1,2,3, … … , N ∗ N 构成,且每行.每列及两条对角线上的数字之和都相同. 当 N 为奇数时 ...
- poj1173 解题报告
poj1173 解题报告2013-07-21 13:31 by 期待 ., 42 阅读, 0 评论, 收藏, 编辑 http://poj.org/problem?id=1173 发现此题资料甚少,斗胆 ...
- [置顶] 刘汝佳《训练指南》动态规划::Beginner (25题)解题报告汇总
本文出自 http://blog.csdn.net/shuangde800 刘汝佳<算法竞赛入门经典-训练指南>的动态规划部分的习题Beginner 打开 这个专题一共有25题,刷完 ...
- ACM-ICPC 2017 Asia HongKong 解题报告
ACM-ICPC 2017 Asia HongKong 解题报告 任意门:https://nanti.jisuanke.com/?kw=ACM-ICPC%202017%20Asia%20HongKon ...
随机推荐
- 鼠标在窗口中的坐标转换到 canvas 中的坐标
鼠标在窗口中的坐标转换到 canvas 中的坐标 由于需要用到isPointInPath函数,所以必须得将鼠标在窗口中的坐标位置转换到canvas画布中的坐标,今天发现网上这种非常常见的写法其 ...
- [Uiautomator篇][2] UiDeviceAPI介绍
1 https://developer.android.com/training/testing/ui-testing/uiautomator-testing.html http://www.cnb ...
- 2016-2017 ACM Central Region of Russia Quarterfinal Programming Contest BHanoi tower
B Hanoi tower It has become a good tradition to solve the “Hanoi tower” puzzle at programming contes ...
- Thanks for your encourage!
将近三个月的学习,我的努力换回了代表荣誉的小黄衫,这令我很开心啊...我想是不是要写点什么来表达自己的心情呢=,= 于是就有了以下文字ahhhhhh... 学习心得: (1)学习中总会有失败和成功, ...
- 【转】javascript操作Select标记中options集合
先来看看options集合的这几个方法:options.add(option)方法向集合里添加一项option对象:options.remove(index)方法移除options集合中的指定项:op ...
- 清除Jquery动画的队列
当我们在写页面效果时,有时希望当鼠标放到某个元素上,这时会有动态的效果,当鼠标移出时效果会消失.但实际中,如果快速的用鼠标指向元素并移出,反复几次.即便鼠标不再指向这个元素,但这个元素会不停的重复着动 ...
- php hash防止表单
<?php /** * Created by PhpStorm. * User: brady * Desc: * Date: 2017/7/12 * Time: 15:01 */class te ...
- Welcome-to-Swift-24高级运算符(Advanced Operators)
除了基本操作符中所讲的运算符,Swift还有许多复杂的高级运算符,包括了C语和Objective-C中的位运算符和移位运算. 不同于C语言中的数值计算,Swift的数值计算默认是不可溢出的.溢出行为会 ...
- [USACO Section 2.1]城堡 The Castle (搜索)
题目链接 Solution 比较恶心的搜索,思路很简单,直接广搜找联通块即可. 但是细节很多,要注意的地方很多.所以直接看代码吧... Code #include<bits/stdc++.h&g ...
- 【python接口自动化】获取根目录
将该方法放在根目录下面,在其他类中直接import 该方法. import os def getRootPath(): rootPath = os.path.dirname(os.path.abspa ...