HDU 5211 Mutiple 水题
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5211
题解:
1、筛法:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std; const int maxn=+;
const int INF=0x3f3f3f3f; int n;
int a[maxn],mmp[maxn];
vector<int> mat[maxn]; void init(){
for(int i=;i<maxn;i++) mat[i].clear();
memset(mmp,-,sizeof(mmp));
} int main(){
while(scanf("%d",&n)==&&n){
init();
int maxa=-;
for(int i=;i<=n;i++){
scanf("%d",a+i);
maxa=max(maxa,a[i]);
mmp[a[i]]=i;
}
int ans=;
for(int i=;i<=n;i++){
int minm=INF;
for(int j=;j*a[i]<=maxa;j++){
if(mmp[j*a[i]]!=-&&mmp[j*a[i]]>i){
minm=min(minm,mmp[j*a[i]]);
}
}
if(minm==INF) minm=;
ans+=minm;
}
printf("%d\n",ans);
}
return ;
}
2、倒着扫回来,不断刷新约数的值
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std; const int maxn=+;
const int INF=0x3f3f3f3f; int n;
int a[maxn],mmp[maxn]; void init(){
memset(mmp,,sizeof(mmp));
} int main(){
while(scanf("%d",&n)==&&n){
init();
for(int i=;i<=n;i++) scanf("%d",a+i);
int ans=;
for(int i=n;i>=;i--){
ans+=mmp[a[i]];
for(int j=;j*j<=a[i];j++){
if(a[i]%j==){
mmp[j]=i;
mmp[a[i]/j]=i;
}
}
}
printf("%d\n",ans);
}
return ;
}
HDU 5211 Mutiple 水题的更多相关文章
- hdu 5210 delete 水题
Delete Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5210 D ...
- hdu 1251 (Trie水题)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- hdu 5211 Mutiple 数学
Mutiple Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5211 ...
- HDU 5703 Desert 水题 找规律
已知有n个单位的水,问有几种方式把这些水喝完,每天至少喝1个单位的水,而且每天喝的水的单位为整数.看上去挺复杂要跑循环,但其实上,列举几种情况之后就会发现是找规律的题了= =都是2的n-1次方,而且这 ...
- HDU 4493 Tutor 水题的收获。。
题目: http://acm.hdu.edu.cn/showproblem.php?pid=4493 题意我都不好意思说,就是求12个数的平均数... 但是之所以发博客,显然有值得发的... 这个题最 ...
- hdu 4802 GPA 水题
GPA Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4802 Des ...
- hdu.5211.Mutiple(数学推导 && 在logn的时间内求一个数的所有因子)
Mutiple Accepts: 476 Submissions: 1025 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 6553 ...
- hdu 4493 Tutor 水题
Tutor Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4493 D ...
- hdu 5495 LCS 水题
LCS Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5495 Descr ...
随机推荐
- HTML5常用标签及特殊字符表
*http://html5doctor.com/nav*http://html5doctor.com/article*http://html5doctor.com/section*http://htm ...
- Redis全方位讲解--哨兵模式(Sentinel模式)
前言 当按照上一篇<redis主从复制>部署好之后,我们会想,一旦redis的master出现了宕机,并且我们并没有及时发现,这时候就可能会出现数据丢失或程序无法运行.此时,redis的哨 ...
- 大数据学习--day17(Map--HashMap--TreeMap、红黑树)
Map--HashMap--TreeMap--红黑树 Map:三种遍历方式 HashMap:拉链法.用哈希函数计算出int值. 用桶的思想去存储元素.桶里的元素用链表串起来,之后长了的话转红黑树. T ...
- 微信小程序-js为object添加属性
代码如下: var my_set = result.attributes.my_set; if (my_set == undefined) { my_set = { is_be_agree: e.de ...
- 数据结构与算法之排序(3)插入排序 ——in dart
插入排序的思想比冒泡.选择要复杂,效率也比前两者更高.插入排序算法中运用了分治.逆向冒泡等思想,假设i之前的都是排好序的,i之后的都是待比较并排序的,然后逐次逆向向前比较,若小于前值,则将前值循环依次 ...
- Linux入门进阶第二天——软件安装管理(上)
一.大纲介绍 这里介绍的仅仅是两大家族之一的RPM,关于Debian家族的DPKG,请参考:http://justcoding.iteye.com/blog/1937171 二.简介 软件包分类: 源 ...
- vagrant boxes
vagrant box add hashicorp/precise64
- mysql导入报错【The MySQL server is running with the --event-scheduler=DISABLED】
一.问题: 在进行mysql操作导入库的时候,报出了[The MySQL server is running with the --event-scheduler=DISABLED] 查看后台日志是事 ...
- python 多线程笔记(3)-- 线程的私有命名空间
线程的私有命名空间实现: threading_namespace = threading.local() import threading import time import random thre ...
- 【BZOJ4008】[HNOI2015]亚瑟王
[BZOJ4008][HNOI2015]亚瑟王 题面 bzoj 洛谷 题解 由期望的线性性 可以知道,把所有牌打出的概率乘上它的伤害加起来就是答案 记第$i$张牌打出的概率为$fp[i]$ 则 $$ ...