Give an array A, the index starts from 1.
Now we want to know B i =max i∤j A j  Bi=maxi∤jAj

, i≥2 i≥2

.

InputThe first line of the input gives the number of test cases T; T test cases follow.
Each case begins with one line with one integer n : the size of array A.
Next one line contains n integers, separated by space, ith number is A i  Ai

.

Limits
T≤20 T≤20

2≤n≤100000 2≤n≤100000

1≤Ai≤1000000000 1≤Ai≤1000000000

∑n≤700000 ∑n≤700000

OutputFor each test case output one line contains n-1 integers, separated by space, ith number is B i+1  Bi+1

.Sample Input

2
4
1 2 3 4
4
1 4 2 3

Sample Output

3 4 3
2 4 4

题意:对于所有的i(i!=1),找最大的a[j],满足j%i!=0;

思路:没有什么对应的算法,居然是暴力,我们从大到小排序,然后找到第一个满足题意的即可。

复杂度均摊下来是线性的,显然过得去。

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
struct in{
int id,num;
friend bool operator <(in w,in v) {return w.num>v.num;}
}s[];
int main()
{
int T,N;
scanf("%d",&T);
while(T--){
scanf("%d",&N);
rep(i,,N) scanf("%d",&s[i].num),s[i].id=i;
sort(s+,s+N+);
rep(i,,N) {
rep(j,,N){
if(s[j].id%i!=){
printf("%d ",s[j].num); break;
}
}
}
puts("");
}
return ;
}

HDU - 6098:Inversion(暴力均摊)的更多相关文章

  1. HDU 6098 - Inversion | 2017 Multi-University Training Contest 6

    /* HDU 6098 - Inversion [ 贪心,数论 ] | 2017 Multi-University Training Contest 6 题意: 求出所有B[i] = max(A[j] ...

  2. HDU 6098 Inversion

    Inversion 思路:从大到小排序后,每次找到第一个下标不整出i的输出. 代码: #include<bits/stdc++.h> using namespace std; #defin ...

  3. 2017ACM暑期多校联合训练 - Team 6 1003 HDU 6098 Inversion (模拟)

    题目链接 Problem Description Give an array A, the index starts from 1. Now we want to know Bi=maxi∤jAj , ...

  4. 【loj6029】「雅礼集训 2017 Day1」市场 线段树+均摊分析

    题目描述 给出一个长度为 $n$ 的序列,支持 $m$ 次操作,操作有四种:区间加.区间下取整除.区间求最小值.区间求和. $n\le 100000$ ,每次加的数在 $[-10^4,10^4]$ 之 ...

  5. Mr. Kitayuta's Colorful Graph CodeForces - 506D(均摊复杂度)

    Mr. Kitayuta has just bought an undirected graph with n vertices and m edges. The vertices of the gr ...

  6. 【uoj#228】基础数据结构练习题 线段树+均摊分析

    题目描述 给出一个长度为 $n$ 的序列,支持 $m$ 次操作,操作有三种:区间加.区间开根.区间求和. $n,m,a_i\le 100000$ . 题解 线段树+均摊分析 对于原来的两个数 $a$ ...

  7. 5.15 牛客挑战赛40 B 小V的序列 关于随机均摊分析 二进制

    LINK:小V的序列 考试的时候 没想到正解 于是自闭. 题意很简单 就是 给出一个序列a 每次询问一个x 问序列中是否存在y 使得x^y的二进制位位1的个数<=3. 容易想到 暴力枚举. 第一 ...

  8. 洛谷 P6783 - [Ynoi2008] rrusq(KDT+势能均摊+根号平衡)

    洛谷题面传送门 首先显然原问题严格强于区间数颜色,因此考虑将询问离线下来然后用某些根号级别复杂度的数据结构.按照数颜色题目的套路,我们肯定要对于每种颜色维护一个前驱 \(pre\),那么答案可写作 \ ...

  9. Chapter4 复杂度分析(下):浅析最好,最坏,平均,均摊时间复杂度

    四个复杂度分析: 1:最好情况时间复杂度(best case time complexity) 2:最坏情况时间复杂度(worst case time complexity) 3:平均情况时间复杂度( ...

随机推荐

  1. java发送http请求和多线程

    0 概述 在写app后台的时候,需要调用另一个服务器上的算法服务,所以需要发送http请求来获取结果. 考虑到一个功能(比如智能中医)需要调用好几个接口(人脸识别,舌苔识别,饮食推荐),大部分时间花在 ...

  2. CSS流体(自适应)布局下宽度分离原则

    CSS流体(自适应)布局下宽度分离原则 这篇文章发布于 2011年02月28日,星期一,00:48,归类于 css相关. 阅读 73990 次, 今日 5 次 by zhangxinxu from h ...

  3. xx-net***简明使用教程

    简介 继psiphon3.lantern.shadowsocks后,翻 土啬 界就来个新角色:xx-net 这张图是.2016.8.30日Google最新的搜索结果,还是可以看出这款工具的火爆程度的, ...

  4. Spark机器学习7·降维模型(scala&python)

    PCA(主成分分析法,Principal Components Analysis) SVD(奇异值分解法,Singular Value Decomposition) http://vis-www.cs ...

  5. Forward Proxy vs Reverse Proxy

    Overview We've talked about reverse proxy servers and how they can really be good at protecting the ...

  6. GIT使用—安装配置及工作流程

    一.Git 与 SVN 区别 GIT不仅仅是个版本控制系统,它也是个内容管理系统(CMS),工作管理系统等. 1.GIT是分布式的,SVN不是:这是GIT和其它非分布式的版本控制系统,例如SVN,CV ...

  7. require和require_once经济性能对比

    require和require_once都是PHP函数,开发人员可以使用它们在某个特定的脚本中导入外部PHP文件.你可以根据应用程序的复杂度调用一次或若干次require_once/require.使 ...

  8. 使用MyCat分表分库原理分析

    Mycat可以实现 读写分离 分表分库 主从复制是MySQL自带的哈~ 关于分片取模算法:  根据id进行取模  根据数据库集群的数量(或者说是表数量,mycat里面一个表对应一个库) 使用MyCat ...

  9. spark学习12(Wordcount程序之spark-shell)

    在目录/home/hadoop/2016113012下有文件words.txt hello scala hello java hello python hello wujiadong 上传该文件到hd ...

  10. 【Node.js】'readline' 逐行读取、写入文件内容

    [转]运用readline逐行读取的两种实现 效果图如下: 左边1.log 为源文件 右边1.readline.log为复制后的文件 下边为命令行输出 实现方式一: [javascript] view ...