题目链接

Problem Description

Give an array A, the index starts from 1.

Now we want to know Bi=maxi∤jAj , i≥2.

Input

The 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 Ai.

Limits

T≤20

2≤n≤100000

1≤Ai≤1000000000

∑n≤700000

Output

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

Sample Input

2

4

1 2 3 4

4

1 4 2 3

Sample Output

3 4 3

2 4 4

题意:

有一个有n个元素的数组,数组的下标从1到n,现在要求的就是从下标2开始的,下标不是它倍数的数值中的最大值。

分析:

因为要找的数值要与下标联系在一起,我们循环的往后找的话时间肯定会超的。

定义一个结构体,一个保存下标,一个保存对应的值,将结构体里面的元素对应的值按照从大到小的顺序排列好之后,循环数组只要找到第一个结构体里的下标不是当前要找的下标的倍数,就把对应的值输出来即可。

代码:

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn = 1e5+10;
struct node
{
ll m;///保存值
int x;///保存下标
} a[maxn];
inline bool cmp(node a, node b)
{
return a.m > b.m;
}
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int n;
ll maxn,mm;
scanf("%d", &n);
for(int i = 1; i <= n; i++)
{
scanf("%lld", &mm);
a[i].x = i;
a[i].m = mm;
}
maxn = 0;
sort(a + 1,a + n + 1, cmp);
for(int i = 2; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
if(a[j].x % i != 0)
{
if(i==2)
printf("%lld",a[j].m);
else
printf(" %lld",a[j].m);
break;
}
}
}
printf("\n");
}
return 0;
}

2017ACM暑期多校联合训练 - Team 6 1003 HDU 6098 Inversion (模拟)的更多相关文章

  1. 2017ACM暑期多校联合训练 - Team 4 1003 HDU 6069 Counting Divisors (区间素数筛选+因子数)

    题目链接 Problem Description In mathematics, the function d(n) denotes the number of divisors of positiv ...

  2. 2017ACM暑期多校联合训练 - Team 3 1003 HDU 6058 Kanade's sum (模拟)

    题目链接 Problem Description Give you an array A[1..n]of length n. Let f(l,r,k) be the k-th largest elem ...

  3. 2017ACM暑期多校联合训练 - Team 1 1003 HDU 6035 Colorful Tree (dfs)

    题目链接 Problem Description There is a tree with n nodes, each of which has a type of color represented ...

  4. 2017ACM暑期多校联合训练 - Team 2 1003 HDU 6047 Maximum Sequence (线段树)

    题目链接 Problem Description Steph is extremely obsessed with "sequence problems" that are usu ...

  5. 2017ACM暑期多校联合训练 - Team 4 1004 HDU 6070 Dirt Ratio (线段树)

    题目链接 Problem Description In ACM/ICPC contest, the ''Dirt Ratio'' of a team is calculated in the foll ...

  6. 2017ACM暑期多校联合训练 - Team 9 1005 HDU 6165 FFF at Valentine (dfs)

    题目链接 Problem Description At Valentine's eve, Shylock and Lucar were enjoying their time as any other ...

  7. 2017ACM暑期多校联合训练 - Team 9 1010 HDU 6170 Two strings (dp)

    题目链接 Problem Description Giving two strings and you should judge if they are matched. The first stri ...

  8. 2017ACM暑期多校联合训练 - Team 8 1006 HDU 6138 Fleet of the Eternal Throne (字符串处理 AC自动机)

    题目链接 Problem Description The Eternal Fleet was built many centuries ago before the time of Valkorion ...

  9. 2017ACM暑期多校联合训练 - Team 8 1002 HDU 6134 Battlestation Operational (数论 莫比乌斯反演)

    题目链接 Problem Description The Death Star, known officially as the DS-1 Orbital Battle Station, also k ...

随机推荐

  1. 怎么用JavaScript实现tab切换

    先看一下代码实现后的最终效果: 用JavaScript实现思路很简单,就是先把所有的内容隐藏,点击标题对应的内容显示, css代码如下: <style type="text/css&q ...

  2. iOS 关于MVC和MVVM设计模式的那些事

    一.概述 在 iOS 开发中,MVC(Model View Controller)是构建iOS App的标准模式,是苹果推荐的一个用来组织代码的权威范式.Apple甚至是这么说的.在MVC下,所有的对 ...

  3. struct和class的联系与区别

    C++支持另一个关键字struct,它也可以定义类类型.struct关键字是从C语言继承过来的. 默认初始访问级别不同: 如果使用class关键字来定义类,那么定义在第一个访问标号前的任何成员都隐式指 ...

  4. Visual Studio 中设置npm

    VS2017自带的npm会去国外的镜像下载文件, 奇慢无比, 还是马云家淘宝的镜像适合国内用户. 淘宝npm镜像地址:  https://registry.npm.taobao.org VS中使用淘宝 ...

  5. ZOJ3529_A Game Between Alice and Bob

    题目的意思是给你若干个数字,两个游戏者轮流操作,每次可以将该数变为一个小于当前的一个约数,无法操作的游戏者fail. 和其他的博弈题目大同小异吧. 不同点有两个,逐一分析吧. 一.每次改变一个数只能改 ...

  6. Qt中父子widget的事件传递

    以前我一直以为:在父widget上摆一个子widget后,当click子widget时:只会进入到子widget的相关事件处理函数中,比如进入到mousePressEvent()中, 而不会进入到父w ...

  7. @Resource 和 @Autowired 区别

    spring不但支持自己定义的@Autowired注解,还支持几个由JSR-250规范定义的注解,它们分别是@Resource.@PostConstruct以及@PreDestroy. @Resour ...

  8. 【Python3的命名空间与作用域,闭包函数,装饰器】

    一.命名空间与作用域 命名空间是名字和对象的映射,就像是字典,key是变量名,value是变量的值 1.命名空间的定义 name='egon' #定义变量 def func(): #定义函数 pass ...

  9. 【bzoj2318】game with probability

    Portal -->bzoj2318 Description Alice和Bob在玩一个游戏.有n个石子在这里,Alice和Bob轮流投掷硬币,如果正面朝上,则从n个石子中取出一个石子,否则不做 ...

  10. [JLOI2014] 松鼠的新家 (lca/树上差分)

    [JLOI2014]松鼠的新家 题目描述 松鼠的新家是一棵树,前几天刚刚装修了新家,新家有n个房间,并且有n-1根树枝连接,每个房间都可以相互到达,且俩个房间之间的路线都是唯一的.天哪,他居然真的住在 ...