Hdu 5288 OO’s Sequence 2015多小联赛A题
OO’s Sequence
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1751 Accepted Submission(s): 632
In each test case:
First line: an integer n(n<=10^5) indicating the size of array
Second line:contain n numbers ai(0<ai<=10000)
5
1 2 3 4 5
23
pid=5295" target="_blank" style="color:rgb(26,92,200); text-decoration:none">5295
#include<stdio.h>
int main()
{
int n,i,j,k,kk,a[100050];
while(scanf("%d",&n)!=EOF)
{
for(i=1; i<=n; i++)
scanf("%d",&a[i]);
long long suma=0;
for(i=1; i<=n; i++)
{
for(j=i; j<=n; j++)
{ for(k=i; k<=j; k++)//相当于i
{
int flag=0;
for(kk=i; kk <= j ; kk++)//相当于j
{
if(a[k]%a[kk] == 0 && k!=kk)
{
flag=1;
break;
}
}
if(flag!=1)
{
suma++;
suma%=100000007;
}
}
printf("%d %d=%d %d=%d\n",i,j,a[i],a[j],suma);
}
}
printf("%I64d\n",suma);
}
}
脑洞大开:换个思路是不是题意求的是找那些区间能满足第ai个值存在呢?
最接近他的值且值是a[i]因子的数字的位置
那么第i个数字能提供的答案就是(r[i]-i) * (l[i]-i)
事实上这样的方法有漏洞 假设我给你 10w个1 程序就跪了 ╮(╯▽╰)╭ 没有这数据 所以放心大胆的做吧
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
const int M = 10e5 + 5;
const long mod = 1e9+7;
int vis[M],a[M],l[M],r[M];
int main()
{
int n;
while(~scanf("%d",&n))
{
memset(l,0,sizeof(l));
memset(r,0,sizeof(r));
memset(vis,0,sizeof(vis)); for(int i = 1;i <= n; ++i)
{
scanf("%d",&a[i]);
r[i] = n+1;
for(int j = a[i];j <= 10000; j+=a[i]) //找到离他近期的因子
{
if(vis[j])
{
r[vis[j]] = i;
vis[j] = 0;
}
}
vis[a[i]] = i;
}
memset(vis,0,sizeof(vis));
for(int i = n;i >= 1; --i)
{
for(int j = a[i];j <= 10000; j+=a[i])
{
if(vis[j])
{
l[vis[j]] = i;
vis[j] = 0;
}
}
vis[a[i]] = i;
} long long ans = 0;
for(int i = 1;i <= n; ++i)
{
ans = ((ans + (long long)(r[i]-i)*(long long)(i-l[i])%mod)%mod);
} printf("%I64d\n",ans);
}
}
Hdu 5288 OO’s Sequence 2015多小联赛A题的更多相关文章
- hdu 5288 OO’s Sequence(2015 Multi-University Training Contest 1)
OO's Sequence Time Limit: 4000/2000 MS (Jav ...
- HDU 5288 OO’s Sequence [数学]
HDU 5288 OO’s Sequence http://acm.hdu.edu.cn/showproblem.php?pid=5288 OO has got a array A of size ...
- HDU 5288 OO‘s sequence (技巧)
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5288 题面: OO's Sequence Time Limit: 4000/2000 MS (Jav ...
- HDU 5288 OO’s Sequence 水题
OO's Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5288 Description OO has got a array A ...
- HDU 5288——OO’s Sequence——————【技巧题】
OO’s Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- hdu 5288 OO’s Sequence(2015多校第一场第1题)枚举因子
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5288 题意:在闭区间[l,r]内有一个数a[i],a[i]不能整除 除去自身以外的其他的数,f(l,r ...
- hdu 5288 OO’s Sequence 枚举+二分
Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number o ...
- hdu 5288 OO’s Sequence(计数)
Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number o ...
- HDU 5288 OO’s Sequence
题意:给一个序列,函数f(l, r)表示在[l, r]区间内有多少数字不是其他数字的倍数,求所有区间的f(l, r)之和. 解法:第一次打多校……心里还有点小激动……然而一道签到题做了俩点……呜呜呜… ...
随机推荐
- spring jpa data笔记
tomcat启动Maven项目的时候总抛出这样的错误: Error creating bean with name 'org.springframework.boot.autoconfigure.or ...
- linux 服务器信息查看
写项目总结报告,需要统计需要系统的配合 1.# uname -a (Linux查看版本当前操作系统内核信息) Linux localhost.localdomain 2.4.20-8 #1 Thu ...
- hash算法散列算法
Hash,一般翻译做“散列”,也有直接音译为“哈希”的,就是把任意长度的输入(又叫做预映射, pre-image),通过散列算法,变换成固定长度的输出,该输出就是散列值.这种转换是一种压缩映射,也就是 ...
- 基于pydash临控linux服务器
pydash项目地址:https://github.com/k3oni/pydash 一.安装过程 1.安装pip dnf install git python-pip -ypip install v ...
- tensorflow BasicRNNCell调试
运行以下代码,进入~/anaconda3/lib/python3.5/site-packages/tensorflow/python/ops/rnn.py和~/anaconda3/lib/python ...
- tomcat修改默认访问首页
找到conf下server.xml文件修改如下位置内容 <Host name="localhost" appBase="webapps" unpackWA ...
- 2017.8.1 logstash基础语法学习
数据类型 bool:debug => true string:host => "hostname" int:port => 514 array:match =&g ...
- notepad++ 在每一行最后加上逗号
1.全选缩进对齐 2.替换功能,入下全部替换 3.在入下替换 4.结果 完成!
- modal html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Win10 导航窗口不能移动文件win10 资源管理器 无法拖动文件到左侧驱动器
Win10 导航窗口不能移动文件怎么办 Win10左侧导航栏不能移动文件怎么办 win10 资源管理器 无法拖动文件到左侧驱动器怎么办 在同一个文件夹可以拖动来移动文件,拖到地址栏的面包屑也可以移动文 ...