暴力+降复杂度 BestCoder Round #39 1002 Mutiple
/*
设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id,
若没有,默认加0,nlogn复杂度;
我用暴力竟然水过去了:)
*/
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std; const int MAXN = 1e4 + ;
const int INF = 0x3f3f3f3f;
int a[MAXN], b[MAXN]; int main(void) //BestCoder Round #39 1002 Mutiple
{
//freopen ("1002.in", "r", stdin); int n; while (scanf ("%d", &n) == )
{
memset (b, , sizeof (b));
for (int i=; i<=n; ++i) scanf ("%d", &a[i]); long long ans = ;
for (int i=n; i>=; --i)
{
ans += b[a[i]];
for (int j=; j*j<=a[i]; ++j)
{
if (a[i] % j == )
{
b[j] = i; b[a[i]/j] = i;
}
}
} printf ("%lld\n", ans);
} return ;
}
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std; const int MAXN = 1e4 + ;
const int INF = 0x3f3f3f3f;
int a[MAXN]; int main(void) //BestCoder Round #39 1002 Mutiple
{
//freopen ("1002.in", "r", stdin); int n;
long long sum = ; while (scanf ("%d", &n) == )
{
for (int i=; i<=n; ++i) scanf ("%d", &a[i]); sum = ; int k = ;
for (int i=; i<=n-; ++i)
{
k = ;
for (int j=i+; j<=n; ++j)
{
if (a[j] % a[i] == )
{
k = j; break;
}
}
sum += k;
} printf ("%lld\n", sum);
} return ;
}
brute
暴力+降复杂度 BestCoder Round #39 1002 Mutiple的更多相关文章
- Manacher BestCoder Round #49 ($) 1002 Three Palindromes
题目传送门 /* Manacher:该算法能求最长回文串,思路时依据回文半径p数组找到第一个和第三个会文串,然后暴力枚举判断是否存在中间的回文串 另外,在原字符串没啥用时可以直接覆盖,省去一个数组空间 ...
- 贪心 BestCoder Round #39 1001 Delete
题目传送门 /* 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 否则再在tot里减去多余的即为答案 用set容器也可以做,思路一样 */ # ...
- 矩阵快速幂---BestCoder Round#8 1002
当要求递推数列的第n项且n很大时,怎么快速求得第n项呢?可以用矩阵快速幂来加速计算.我们可以用矩阵来表示数列递推公式比如fibonacci数列 可以表示为 [f(n) f(n-1)] = [f(n ...
- 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II
题目传送门 /* 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 当然有可能两个数和超过p,那么an的值最优,每 ...
- 二分图判定+点染色/并查集 BestCoder Round #48 ($) 1002 wyh2000 and pupil
题目传送门 /* 二分图判定+点染色:因为有很多联通块,要对所有点二分图匹配,若不能,存在点是无法分配的,no 每一次二分图匹配时,将点多的集合加大最后第一个集合去 注意:n <= 1,no,两 ...
- hdu 5195 DZY Loves Topological Sorting BestCoder Round #35 1002 [ 拓扑排序 + 优先队列 || 线段树 ]
传送门 DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131 ...
- HDU_6016_(Bestcoder round #92 1002)_(dfs)(暴力)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6016 题意:给定男羊和女羊的朋友关系,即给定一个图,问从任意一只羊开始连续数四只不相同的羊的方法数. ...
- BestCoder Round #92 1002 Count the Sheep —— 枚举+技巧
题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=748&pid=1002 题解: 做题的时候只是想到 ...
- BestCoder Round #39
-------好久没更新博客了,发现还是需要不断总结才能进步,所以还是把最近打的一些比赛记录一下. T1:Delete (hdu 5210) 题目大意: 给出n个数,然后要删掉k个,要求剩下的数中 不 ...
随机推荐
- show processlist 其中status详解(适用于所有概况)
mysql show processlist分析 2011-04-11 16:13:00 分类: Mysql/postgreSQL mysql> show processlist; +—–+—— ...
- android edittext 去边框
EditText的background属性设置为@null就搞定了:android:background="@null" style属性倒是可加可不加 附原文:@SlumberMa ...
- git初学者这样就行了。
Create a new repository on the command line touch README.md git init git add README.md git commit -m ...
- 转:PCL+VS2010环境配置
1.下载 http://www.pointclouds.org/downloads/windows.html出下载PCL完全安装包1.6.0 all-in-one-installer,我的电脑是32位 ...
- Sphinx 增量索引更新
是基于PHP API调用,而不是基于sphinxSE.现在看来sphinxSE比API调用更简单的多,因为之前没有想过sphinxSE,现在先把API的弄明白.涉及到的:sphinx 数据源的设置,简 ...
- Rehashing
The size of the hash table is not determinate at the very beginning. If the total size of keys is to ...
- 【转】tomcat下部署 solr 5.3.1
本文转自:http://blog.csdn.net/lianghyan/article/details/49467207 solr下载: http://lucene.apache.org/solr/d ...
- ubuntu下java环境变量配置
转自:http://blog.csdn.net/tenpage/article/details/7215810 如果是配置java环境,请参照这篇,更简单:在Ubuntu 12.04 LTS上安装JD ...
- HDU1009老鼠的旅行 (贪心算法)
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- 获取4G以上的文件大小
1.DWORD dwFileSizeHigh; // 得到文件大小的高位 __int64 qwFileSize = GetFileSize(m_hSrcBigFile, &dwFileSi ...