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
 
题意:给出a序列,求b序列,bj=max(ai)(i%j!=0)
题解:对a排序后,直接查找TLE。因此将排序后的最大值,将b中可以取它的值先赋值赋好。然后剩余数再去查找,就会节省很多时间。应该有更好的方法?
 
 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<cstring> using namespace std;
int t,n;
struct node
{
long long k;
int pos;
}a[];
int b[];
bool cmp(node a,node b)
{
return a.k>b.k;
} int main()
{
scanf("%d",&t);
for(;t>;t--)
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%lld",&a[i].k);
a[i].pos=i;
}
sort(a+,a++n,cmp);
memset(b,-,sizeof(b));
for(int j=;j<=n;j++)
{
if(a[].pos%j!=)
b[j]=a[].k;
}
for(int i=;i<=n;i++)
{
if(b[i]!=-)
continue;
for(int j=;j<=n;j++)
if (a[j].pos%i!=)
{
b[i]=a[j].k;
break;
}
}
printf("%d",b[]);
for(int j=;j<=n;j++)
printf(" %d",b[j]);
printf("\n");
}
return ;
}
 

HDU 6098 17多校6 Inversion(思维+优化)的更多相关文章

  1. HDU 6140 17多校8 Hybrid Crystals(思维题)

    题目传送: Hybrid Crystals Problem Description > Kyber crystals, also called the living crystal or sim ...

  2. HDU 6124 17多校7 Euler theorem(简单思维题)

    Problem Description HazelFan is given two positive integers a,b, and he wants to calculate amodb. Bu ...

  3. HDU 3130 17多校7 Kolakoski(思维简单)

    Problem Description This is Kolakosiki sequence: 1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1……. This seq ...

  4. HDU 6034 17多校1 Balala Power!(思维 排序)

    Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He want ...

  5. HDU 6092 17多校5 Rikka with Subset(dp+思维)

    Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...

  6. HDU 6090 17多校5 Rikka with Graph(思维简单题)

    Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...

  7. HDU 6095 17多校5 Rikka with Competition(思维简单题)

    Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...

  8. HDU 6049 17多校2 Sdjpx Is Happy(思维题difficult)

    Problem Description Sdjpx is a powful man,he controls a big country.There are n soldiers numbered 1~ ...

  9. HDU 6143 17多校8 Killer Names(组合数学)

    题目传送:Killer Names Problem Description > Galen Marek, codenamed Starkiller, was a male Human appre ...

随机推荐

  1. 【Java】【4】关于Java中的自增自减

    摘要:理解j = j++与j = ++j的区别:正确用法:直接用j++,不要用前两种 正文: import java.util.*; public class Test{ public static ...

  2. ireport部署到Linux服务器上遇到的问题解决

    ireport报表在本地Windows环境运行正常,一旦部署到Linux环境上出现了如下问题: 1.打开报表,后台直接报net.sf.jasperreports.engine.util.JRFontN ...

  3. SQL - 数据查询

    数据查询是数据库的核心操作.SQL 提供了 select 语句进行数据查询,该语句的一般格式为: select  [ ALL | distinct ] <目标列表达式>  [ ,<目 ...

  4. Tomcat禁用SSLv3和RC4算法

    1.禁用SSLv3(SSL 3.0 POODLE攻击信息泄露漏洞(CVE-2014-3566)[原理扫描]) 编缉$CATALINA_HOEM/conf/server.xml配置文件,找到https端 ...

  5. date命令说明

    基本使用格式: date [-d "time-to-display"] +"format-to-display" -d指定要显示的时间,如果不指定默认为当前时间 ...

  6. Kali配置教程

    1.配置软件源 所有操作没有说明,都是以root身份执行. 打开一个终端执行: cat >> /etc/apt/sources.list <<EOF deb http://mi ...

  7. MySql查询最近一个月,一周,一天

    最近一个月 SELECT * FROM table WHERE DATE_SUB(CURDATE(), INTERVAL 1 MONTH) <= date(time); 本月.当前月 SELEC ...

  8. latex 公式距离

    \setlength{\abovedisplayshortskip}{0cm} 公式和文本之间的间距 \setlength{\belowdisplayshortskip}{0cm} \setlengt ...

  9. Win10系列:VC++ Direct3D模板介绍2

    (3)CreateDeviceResources函数 CreateDeviceResources函数默认添加在CubeRenderer.cpp源文件中,此函数用于创建着色器和立体图形顶点.接下来分别介 ...

  10. java this的用法

    this 含义:代表当前对象 用法: 用于返回对象的引用 示例代码 public class Test { public Test f() { return this;//获取当前对象的引用 } pu ...