题目链接

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. python基础(一)简单入门

    一.第一个python程序 1.交互式编程 直接在命令行里面输入python即可进入python交互式命令行,linux下一样: 在 python 提示符中输入以下文本信息,然后按 Enter 键查看 ...

  2. 控件属性和InitializeComponent()关系:

    namespace Test22 { partial class Form1 { /// <summary> /// 必需的设计器变量. /// </summary> priv ...

  3. xstream 解析xml报文

    一.xml一种格式的数据转换为对象 pom.xml引入 <!--javaBean和XML的双向转换--> <dependency> <groupId>com.tho ...

  4. NIO网络编程中重复触发读(写)事件

    一.前言 公司最近要基于Netty构建一个TCP通讯框架, 因Netty是基于NIO的,为了更好的学习和使用Netty,特意去翻了之前记录的NIO的资料,以及重新实现了一遍NIO的网络通讯,不试不知道 ...

  5. MySQL---索引算法B+/B-树原理(二)

    B+/-Tree原理 B-Tree介绍 B-Tree是一种多路搜索树(并不是二叉的):        1.定义任意非叶子结点最多只有M个儿子:且M>2:        2.根结点的儿子数为[2, ...

  6. 【Linux笔记】CentOS&RHEL YUM基础知识

    以下内容收集自网络,以作参考. 一.YUM是什么 YUM = Yellow dog Updater, Modified. 主要功能是更方便的添加/删除/更新RPM包. 它能自动解决包的倚赖性问题. 它 ...

  7. HDU4059_The Boss on Mars

    数论题. 首先我们知道公式:1^4+2^4+3^4+……+n^4=(n)*(n+1)*(2*n+1)*(3*n*n+3*n-1) /30; 然后我们要把多余的减掉.这里用到的是mobius反演. 总之 ...

  8. 深入理解JVM一垃圾回收算法

    我们都知道java语言与C语言最大的区别就是内存自动回收,那么JVM是怎么控制内存回收的,这篇文章将介绍JVM垃圾回收的几种算法,从而了解内存回收的基本原理. 一.stop the world 在介绍 ...

  9. IBatis Map报错10.1

    检查 providers.config 把没用的给关闭掉即可

  10. elasticsearch 第五篇(文档操作接口)

    INDEX API 示例: 1 2 3 4 5 PUT /test/user/1 { "name": "silence", "age": 2 ...