HDU 6098 Inversion
来源:互联网 发布:微信矩阵是什么 编辑:程序博客网 时间:2024/06/02 05:39
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
Source
2017 Multi-University Training Contest - Team 6
Recommend
liuyiding | We have carefully selected several similar problems for you: 6119 6118 6117 6116 6115
b[i]表示a數組中下標不能被i整除的最大值。
經過排序之後,之後那麼每次找到的第一個數就是答案了,時間複雜度低於O(n*n)
#include<iostream>#include<algorithm>using namespace std;//不要小瞧人生啊const int N = 1e5 + 10;int T, n, a[N], id[N];int main() { scanf("%d", &T); for(int i=0;i<T;i++) { scanf("%d", &n); for(int i=1;i<n+1;i++) scanf("%d", a + i), id[i] = i; sort(id + 1, id + 1 + n, [&](int x, int y) { return a[x]>a[y]; });//又學習到了cmp的另一種套路 //[&](int x,int y){return a[x]>a[y]} for(int i=2;i<n+1;i++)//暴力 { int f = 0; for(int j=1;j<n+1;j++) if (id[j] % i != 0) //下標 { f = a[id[j]]; break; } printf("%d%c", f, " \n"[i == n]); } } return 0;}
- HDU 6098-Inversion
- HDU 6098-Inversion
- hdu 6098 Inversion
- HDU 6098 Inversion
- hdu-6098-Inversion
- HDU 6098 Inversion
- HDU 6098 Inversion【思维】
- HDU 6098 Inversion(RMQ)
- HDU 6098 Inversion【】
- #HDU 6098 Inversion
- HDU 6098 Inversion
- HDU 6098 Inversion
- hdu -- 6098 -- Inversion(排序)
- HDU-Inversion
- 2017多校赛6 Inversion hdu 6098
- Minimum Inversion Number HDU
- HDU Minimum Inversion Number
- hdu 4911 Inversion
- 关于web项目中的程序调试(为了记住自己遇到的问题,慢慢增加)
- stm32控制mpu9250九轴传感器
- ping——网络测试
- 《笨办法学python》加分习题11——我的答案
- tensorflow 入门
- HDU 6098 Inversion
- 递归与动态规划---最长公共子串问题
- 一种排序
- F
- 476. Number Complement--数量补语
- 剑指offer——从上往下打印二叉树
- Java集合之TreeMap源码分析
- jQuery中toggle与slideToggle以及fadeToggle之间的不同
- 函数二