首页 > 代码库 > hdu 6098 Inversion
hdu 6098 Inversion
Inversion
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 339 Accepted Submission(s): 230
Problem Description
Give an array A, the index starts from 1.
Now we want to know Bi=max { Aj | i?j }, i≥2.
Now we want to know Bi=max { Aj | i?j }, 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
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: 6107 6106 6105 6104 6103
题目大意:
给你一个数组 a ,让你求出数组 b 。b[ i ] 表示 a 数组中下标不能被 i 整除的数里面的最大值。
题解:
把a数组开个结构体,存入值和标号,按值从大到小排序,然后从最大的开始询问起,如果a[i].id 此时的下标不能被b的下标 j 整除,则给 b[j] 赋值a[i].k
#include <iostream> #include<cstdio> #include<algorithm> #include<queue> #include<map> #include<vector> #include<cmath> #include<cstring> #include<bits/stdc++.h> using namespace std; long long b[100005]; int T,n; struct node { long long k; int id; }a[100005]; bool cmp(node a,node b) { return a.k>b.k; } int main() { scanf("%d",&T); while(T--) { scanf("%d",&n); memset(b,0,sizeof(b)); for(int i=1;i<=n;i++) { scanf("%lld",&a[i].k); a[i].id=i; } sort(a+1,a+n+1,cmp); int tmp=n-1; for(int i=1;i<=n && tmp>0;i++) { for(int j=2;j<=n && tmp>0;j++) { if (b[j]==0 && a[i].id%j!=0) b[j]=a[i].k,tmp--; } } for(int i=2;i<=n;i++) { if (i-2) printf(" "); printf("%d",b[i]); } printf("\n"); } return 0; }
hdu 6098 Inversion
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。