Give an array A, the index starts from 1.
Now we want to know B i =max i∤j A j  Bi=maxi∤jAj

, i≥2 i≥2

.

InputThe 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 A i  Ai

.

Limits
T≤20 T≤20

2≤n≤100000 2≤n≤100000

1≤Ai≤1000000000 1≤Ai≤1000000000

∑n≤700000 ∑n≤700000

OutputFor each test case output one line contains n-1 integers, separated by space, ith number is B i+1  Bi+1

.Sample Input

2
4
1 2 3 4
4
1 4 2 3

Sample Output

3 4 3
2 4 4

题意:对于所有的i(i!=1),找最大的a[j],满足j%i!=0;

思路:没有什么对应的算法,居然是暴力,我们从大到小排序,然后找到第一个满足题意的即可。

复杂度均摊下来是线性的,显然过得去。

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
struct in{
int id,num;
friend bool operator <(in w,in v) {return w.num>v.num;}
}s[];
int main()
{
int T,N;
scanf("%d",&T);
while(T--){
scanf("%d",&N);
rep(i,,N) scanf("%d",&s[i].num),s[i].id=i;
sort(s+,s+N+);
rep(i,,N) {
rep(j,,N){
if(s[j].id%i!=){
printf("%d ",s[j].num); break;
}
}
}
puts("");
}
return ;
}

HDU - 6098:Inversion(暴力均摊)的更多相关文章

  1. HDU 6098 - Inversion | 2017 Multi-University Training Contest 6

    /* HDU 6098 - Inversion [ 贪心,数论 ] | 2017 Multi-University Training Contest 6 题意: 求出所有B[i] = max(A[j] ...

  2. HDU 6098 Inversion

    Inversion 思路:从大到小排序后,每次找到第一个下标不整出i的输出. 代码: #include<bits/stdc++.h> using namespace std; #defin ...

  3. 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 , ...

  4. 【loj6029】「雅礼集训 2017 Day1」市场 线段树+均摊分析

    题目描述 给出一个长度为 $n$ 的序列,支持 $m$ 次操作,操作有四种:区间加.区间下取整除.区间求最小值.区间求和. $n\le 100000$ ,每次加的数在 $[-10^4,10^4]$ 之 ...

  5. Mr. Kitayuta's Colorful Graph CodeForces - 506D(均摊复杂度)

    Mr. Kitayuta has just bought an undirected graph with n vertices and m edges. The vertices of the gr ...

  6. 【uoj#228】基础数据结构练习题 线段树+均摊分析

    题目描述 给出一个长度为 $n$ 的序列,支持 $m$ 次操作,操作有三种:区间加.区间开根.区间求和. $n,m,a_i\le 100000$ . 题解 线段树+均摊分析 对于原来的两个数 $a$ ...

  7. 5.15 牛客挑战赛40 B 小V的序列 关于随机均摊分析 二进制

    LINK:小V的序列 考试的时候 没想到正解 于是自闭. 题意很简单 就是 给出一个序列a 每次询问一个x 问序列中是否存在y 使得x^y的二进制位位1的个数<=3. 容易想到 暴力枚举. 第一 ...

  8. 洛谷 P6783 - [Ynoi2008] rrusq(KDT+势能均摊+根号平衡)

    洛谷题面传送门 首先显然原问题严格强于区间数颜色,因此考虑将询问离线下来然后用某些根号级别复杂度的数据结构.按照数颜色题目的套路,我们肯定要对于每种颜色维护一个前驱 \(pre\),那么答案可写作 \ ...

  9. Chapter4 复杂度分析(下):浅析最好,最坏,平均,均摊时间复杂度

    四个复杂度分析: 1:最好情况时间复杂度(best case time complexity) 2:最坏情况时间复杂度(worst case time complexity) 3:平均情况时间复杂度( ...

随机推荐

  1. 多线程、多进程、协程、IO多路复用请求百度

    最近学习了多线程.多进程.协程以及IO多路复用,那么对于爬取数据来说,这几个方式哪个最快呢,今天就来稍微测试一下 普通方式请求百度5次 import socket import time import ...

  2. SpringBoot 加载配置文件

    1.application.properties或application.yaml是SpringBoot默认的配置文件. 可以通过@Value注解 配合 ${......}来读取配置在属性文件中的内容 ...

  3. Spring_Bean 的作用域

    beans-scope.xml <?xml version="1.0" encoding="UTF-8"?><beans xmlns=&quo ...

  4. Luogu-5004 专心OI-跳房子(矩阵快速幂)

    Luogu-5004 专心OI-跳房子(矩阵快速幂) 题目链接 题解: 先考虑最朴素的dp 设\(f[i][0/1]\)表示第\(i\)个位置跳/不跳的方案数,则: \[ \begin{cases} ...

  5. nginx+tomcat网页动静分离配置

    1.环境描述 nginx server (Proxy):192.168.1.135(作为代理服务器)WEB server1: 192.168.1.138(使用tomcat作为web容器)WEB ser ...

  6. forever让nodejs后台运行

    nodejs一般是当成一条用户命令执行的,当用户断开客户连接,运用也就停了,很烦人.如何让nodejs应用当成服务,在后台执行呢? 最简单的办法: $ nohup node app.js 但是,for ...

  7. Java 常用正则表达式 - 转载

    只能输入数字:"^[0-9]*$".只能输入n位的数字:"^\d{n}$".只能输入至少n位的数字:"^\d{n,}$".只能输入m~n位的 ...

  8. chrome关闭后还在进程中运行

    1.网上搜到信息: 设置 “即使关闭浏览器也后台运行” 取消打勾 2.然后我找了一下,应该是这个选项:“关闭 Google Chrome 后继续运行后台应用” 3. 4. 5.

  9. win7 VC6.0 安装 fatal error C1083: Cannot open include file: 'Iphlpapi.h': No such file or directory

    解决方法:   第一步 安装SDK 第二步 将包含的api放在第一项

  10. Ubuntu chrome FQ

    按照文档FQ,需要注意一下两点: 1. 在安装Chrome 下的 SwitchyOmega 插件时,拖入到浏览器不能识别,应该打开chrome://extensions/再拖入: 2.在设置时排列列表 ...