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)之和. 解法:第一次打多校……心里还有点小激动……然而一道签到题做了俩点……呜呜呜… ...
随机推荐
- 洛谷——2871[USACO07DEC]手链Charm Bracelet——01背包
题目描述 Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like t ...
- 注册表数据提取工具RegRipper
注册表数据提取工具RegRipper 注册表是Windows操作系统一个数据库,用来存储系统和应用程序设置信息.注册表信息分别保存在操作系统中的6个Hive文件中.获取这几个文件,就可以从中提取注 ...
- Mybatis中的XML中需要用到的转义符号整理
使用这么久的Mybatis中需要转义的符号整理一下,小结一下: 1. < 小于符号 < 2. <= 小于等于 ...
- Bean的实例化--构造器
1,编写Bean对象 package com.songyan.ico; public class Bean1 { } 2,配置xml <?xml version="1.0" ...
- XP右键菜单添加“打开所在文件夹”功能
把以下文字保存为add.reg文件,双击后确定就可以了. REGEDIT4 [HKEY_CLASSES_ROOT\*\Shell\打开所在文件夹(&O)] [HKEY_CLASSES_ROOT ...
- python virtualenv virtualenvwrapper
python中的virtualenv模块能够将项目环境分隔开,而不是使用全局的环境,非常实用. 首先pip install virtualenv 如何创建一个环境virtualenv testvir ...
- GPU hang
最近做新项目 初期一直遇到个gpu hang的问题 就是command 提交过去gpu 就一直在那里 直到time out 也没什么别的错误提示 gpu debugger还抓不了 解决方案是 缩小之后 ...
- JSONUtil.bean2Json()报Property 'key' of class has no read method. SKIPPED的问题处理
错误警告信息描述: net.sf.json.JSONObject.defaultBeanProcessing(JSONObject.java:) Property 'handler' of class ...
- ES6中的Map集合(与java里类似)
Set类型可以用来处理列表中的值,但是不适用于处理键值对这样的信息结构.ES6也添加了Map集合来解决类似的问题 一.Map集合 JS的对象(Object),本质上是键值对的集合(Hash结构),但是 ...
- 使用websocket进行消息推送服务
Websocket主要做消息推送,简单,轻巧,比comet好用 入门了解:https://www.cnblogs.com/xdp-gacl/p/5193279.html /** * A Web Soc ...