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. list排序,顺序,倒序

    Collections.sort(list); // 顺序排列 Collections.reverse(list); // 倒序排列 Collections.shuffle(list); // 无序

  2. js 处理 cookie的存储与删除

    <script> //JS操作cookies方法! //写cookies function setCookie(c_name, value, expiredays){ var exdate ...

  3. Alibaba Java Coding Guidelines

    阿里巴巴于10月14日在杭州云栖大会上,正式发布众所期待的<阿里巴巴Java开发规约>扫描插件!该插件由阿里巴巴P3C项目组研发.P3C是世界知名的反潜机,专门对付水下潜水艇,寓意是扫描出 ...

  4. 稳定获取Android设备唯一码(UUID)的解决方案

    最近做的一个项目中需要用到Android设备唯一码(UUID)来标识一台设备, Android中设备唯一码有很多,如:MAC地址.IMEI号(DeviceId).IMSI号.ANDROID_ID.序列 ...

  5. 2015-09-29 js2

    Javasript 六. 条件语句 1. 比较运算符 == .!=.>.>=.<.<= 转大/小写:toUpperCase().toLowerCase() 2. 逻辑运算符(与 ...

  6. 【转】jquery.validate.js表单验证

    一.用前必备官方网站:http://bassistance.de/jquery-plugins/jquery-plugin-validation/ API: http://jquery.bassist ...

  7. [LeetCode] 95. Unique Binary Search Trees II(给定一个数字n,返回所有二叉搜索树) ☆☆☆

    Unique Binary Search Trees II leetcode java [LeetCode]Unique Binary Search Trees II 异构二叉查找树II Unique ...

  8. I/O复用(select)——回声服务器端/客户端

    一.select 使用select函数可以将多个文件描述符集中到一起统一监视,监视事件如下: 是否存在待读取数据. 是否可传输无阻塞传输数据. 是否发生异常. 将关心上述3种事件的文件描述发分别注册到 ...

  9. LY.猜字小游戏

    猜字小游戏

  10. xadmin自定义关联菜单

    网上好多自定义xadmin后台数据很少有关怎样设置外键关联菜单的显示,如下图所示: 现有个需求根据model中status字段值,来显示关联菜单三道杠,如上图app状态只有是审核成功才会显示,未审核不 ...