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 , 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 (模拟)的更多相关文章
- 2017ACM暑期多校联合训练 - Team 4 1003 HDU 6069 Counting Divisors (区间素数筛选+因子数)
题目链接 Problem Description In mathematics, the function d(n) denotes the number of divisors of positiv ...
- 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 ...
- 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 ...
- 2017ACM暑期多校联合训练 - Team 2 1003 HDU 6047 Maximum Sequence (线段树)
题目链接 Problem Description Steph is extremely obsessed with "sequence problems" that are usu ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 2017ACM暑期多校联合训练 - Team 8 1002 HDU 6134 Battlestation Operational (数论 莫比乌斯反演)
题目链接 Problem Description The Death Star, known officially as the DS-1 Orbital Battle Station, also k ...
随机推荐
- MMU 和 MPU的区别
S3C2440里面带的是MMU,而现在流行的Cortex-M3/4 里面带的是MPU. MMU vs MPU 内存是现代计算机最重要的组件之一.因此,它的内容不能被任何错误的应用所篡改.这个功能可以通 ...
- Jmeter 快速入门--简单的http压测
1.添加线程组 打开jmeter主窗口后,选择左侧树形结构里的"测试计划",然后右键选择添加,选择"threads(users)",选择"线程组&qu ...
- 这可能是目前最全的Redis高可用技术解决方案总结
本文主要针对 Redis 常见的几种使用方式及其优缺点展开分析. 一.常见使用方式 Redis 的几种常见使用方式包括: Redis 单副本: Redis 多副本(主从): Redis Sentine ...
- web.py 笔记
1.涉及到id=‘id’的情况,需要加入 vars=locals() ,因为id在python里有id() 函数 db.delete('entries', where = 'id = $id', ...
- 【数据库】SQL分组多列统计(GROUP BY后按条件分列统计)
select whbmbh ,zt,1 as tjsl from fyxx group by zt,whbmbh select whbmbh,sum(case zt when '有效' then 1 ...
- 出现脚本错误或者未正确调用 Page()
pages/xxxx/xxxx.js 出现脚本错误或者未正确调用 Page() 自己创建的小程序出现上面报错,可能是因为 xxxx.js是一个空文件,所以才会出现未正确调用: 如果是空文件的话,解决办 ...
- FZU2122_又见LKity
题目是说给你一个替换串和目标串.把一个长串中的所有的替换串替换为目标串而且不递归地替换. 很简单,直接做一次KMP然后直接替换. 注意替换后跳到替换串的尾部. 注意大小写的问题. #include & ...
- BZOJ 1925 地精部落(DP)
一道很经典的DP题. 题意:求n排列中波动排列的种数. 不妨考虑DP,令dp1[i][j],表示1-j的排列中,第一项为i之后递增的波动排列种数.dp2[i][j]表示1-j的排列中,第一项为i之后递 ...
- 【BZOJ1063】【NOI2008】道路设计(动态规划)
[BZOJ1063][NOI2008]道路设计(动态规划) 题面 BZOJ 题解 发现每个点最多只能被修一次等价于每个点最多只能和两条铁路相邻 考虑一个\(dp\) 设\(f[i][0/1/2]\)表 ...
- BZOJ2716:[Violet 3]天使玩偶——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=2716 样例输入 2 31 12 32 1 21 3 32 4 2 样例输出 1 2 ———————— ...