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. String类——StringBuilder类的源码及内存分析(java)

    相同:底层均采用字符数组value来保存字符串 区别:String类的value数组有final 修饰,指向不可改,同时private 未提供修改value数组的方法.StringBuilder类的v ...

  2. python 线程 进程

    1.进程与线程优.缺点的比较总言:使用进程和线程的目的,提高执行效率. 进程: 优点:能利用机器的多核性能,同时进行多个操作. 缺点:需要耗费资源,重新开辟内存空间,耗内存. 线程: 优点:共享内存( ...

  3. 为什么要使用oath协议?

    一.如何查看用户是否登录? 通过cookie和session来查看用户是否登录. 如果cookie对应的session中保存了用户登录信息,则判定用户已登录 Jsessionid,也就是tomcat自 ...

  4. 第 4 章 用 HTML5 建立超链接

    HTML 文件中最重要的应用之一就是超链接.—— 当鼠标单击一些文字.图片或其他网页元素时,浏览器会根据其指示载入一个新的页面或跳转到页面的其他位置. 超链接除了可链接文本外,也可链接各种媒体,如声音 ...

  5. ORM框架之SQLALchemy

    一.面向对象应用场景: 1.函数有共同参数,解决参数不断重用: 2.模板(约束同一类事物的,属性和行为) 3.函数编程和面向对象区别: 面向对象:数据和逻辑组合在一起:函数编程:数据和逻辑不能组合在一 ...

  6. Python爬虫关于多层嵌套iframe的解决

    近期由于公司资源需要,我爬取了一个视频网站,结果以为一个很容易的小爬虫,却步步是坑啊,费了一天终于都解决了(太菜了!!!). 前面导航页的爬虫就不多说了,无非就是webdriver和PhantomJS ...

  7. linux文件权限多一个+啥意思

    linux文件权限显示多了一个+,说明添加了acl权限 使用getfacl filename 能查看到 ower group other  还多了一个php 用户有rwx权限. acl详解 转: ht ...

  8. memory prefix pre,pro,penta,pseudo out _p 1

    1● pre 前的,预先   2● pro 在前,很多,赞同       3● penta 5,五     4● pseaudo   伪,假 pseudo  

  9. Linux 控制CPU使用率

    曾经看过<编程之美>上提到说使 CPU的使用率固定在百分之多少.然后这次刚好要用到这个东西,下面是一个简单的实现.基于多线程: Linux 版本: #include <iostrea ...

  10. u-boot的内存分布

    cpu会自动从NAND flash 中读取前4KB的数据放置在片内SRAM里(s3c2440是soc),同时把这段片内SRAM映射到nGCS0片选的空间(即0x00000000).cpu是从0x000 ...