HDU6098 Inversion -2017多校联盟6 第3题
来源:互联网 发布:程序员需要出差吗 编辑:程序博客网 时间:2024/06/04 18:10
Inversion
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 30 Accepted Submission(s): 18
Problem Description
Give an array A, the index starts from 1.
Now we want to knowBi=maxi∤jAj , i≥2 .
Now we want to know
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 isAi .
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
Limits
Output
For each test case output one line contains n-1 integers, separated by space, ith number isBi+1 .
Sample Input
241 2 3 441 4 2 3
Sample Output
3 4 32 4 4
Source
2017 Multi-University Training Contest - Team 6
题意
给定ai , i∈[1,n] 定义bi , i∈[2,n+1]
i不是j的因子
将ai排序,倒着找,第一个不是i的倍数的j对应的aj就是bi
代码:
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;typedef long long LL;const int maxn = 100000 + 10;struct data{ LL val; int pos;}a[maxn];int cmp1(const data a,const data b){ return a.val < b.val;}LL b[maxn];int main(){ int t; scanf("%d", &t); while (t > 0) { t--; int n; scanf("%d",&n); for(int i = 0;i<n;++i){ scanf("%lld",&a[i].val); a[i].pos = i+1; } sort(a,a+n, cmp1); for(int i = 2;i<=n;++i){ for(int j = n-1;j>=0;--j){ if(a[j].pos%i) {b[i] = a[j].val;break;} } } for(int i = 2;i<=n;++i){ if(i!=2) printf(" "); printf("%lld",b[i]); } puts(""); } return 0;}
阅读全文
1 0
- HDU6098 Inversion -2017多校联盟6 第3题
- HDU6098 Inversion(RMQ,2017 HDU多校联赛 第6场)
- hdu6098 Inversion 2017多校第六场1003 埃氏筛法
- Hdu6098 Inversion(2017多校第6场)
- HDU6098-2017多校6-贪心&水-Inversion
- 2017杭电多校联赛6-Inversion-排序-hdu6098
- HDU6098 Inversion
- HDU6098(Inversion)
- HDU6098-Inversion
- HDU6098 Inversion
- HDU6098-Inversion
- hdu6098--Inversion
- HDU6098 Inversion 签到
- HDU 6069 Counting Divisors -质因子个数-2017多校联盟4 第3题
- hdu6098
- HDU6034 Balala Power! -2017多校联盟1 第2题
- HDU 6077 Time To Get Up -暴力枚举-2017多校联盟4 第11题
- HDU 6095 Rikka with Competition -2017多校联盟5 第11题
- 16 个 Linux 服务器监控命令和watch
- Java+opencv3.2.0之图像尺寸调整
- itk中的图像分割算法(二)
- POJ
- 进度条图片匀速旋转
- HDU6098 Inversion -2017多校联盟6 第3题
- 一来文无
- Android studio导入网络下载工程很慢
- sparkSql中udf的应用
- Servlet与JSP的区别
- 编辑最短距离
- C#向数组列表中添加数据,以及判断数组中是否包含某元素
- dataimport.scheduler 源码
- 南阳OJ 题目100:一的个数