hdu 6098
来源:互联网 发布:多台docker php-fpm 编辑:程序博客网 时间:2024/05/20 06:31
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
题解:
多校的题有点难理解啊。
i∤j’表示j%i!=0
排序优化一下,以数据大小排序,同时记录索引值,从2开始枚举,计算b数组的值,O(n)扫排序后的a数组,当遇到第一个j%i!=0,记录即可。
代码:
#include <bits/stdc++.h>using namespace std;typedef long long LL;const int maxn = 100000+10;struct node{ int id; LL data;};bool cmp(node q,node p){ return q.data>p.data;}int main(){ int T; cin>>T; LL n; node a[maxn]; vector<LL> b; while(T--) { cin>>n; LL tmp; for(int i=1;i<=n;i++) { scanf("%lld",&tmp); a[i].data=tmp; a[i].id=i; } sort(a+1,a+n+1,cmp); for(int i=2;i<=n;i++) { for(int j=1;j<=n;j++) { if(a[j].id%i!=0) { b.push_back(a[j].data); break; } } } int siz = b.size(); for(int i=0;i<siz-1;i++) { printf("%lld ",b[i]); } printf("%lld",b[siz-1]); cout<<endl; b.clear(); } return 0;}
阅读全文
0 0
- hdu 6098
- HDU 6098-Inversion
- HDU 6098-Inversion
- hdu 6098 Inversion
- HDU 6098 Inversion
- hdu-6098-Inversion
- HDU 6098 Inversion
- HDU 6098 Inversion【思维】
- HDU 6098 Inversion(RMQ)
- HDU 6098 Inversion【】
- #HDU 6098 Inversion
- HDU 6098 Inversion
- HDU 6098 Inversion
- hdu
- hdu
- HDU
- hdu ()
- hdu
- 【04】淘淘商城-Service层递归拼装ItemCatResult详解
- 字符串模式匹配
- Android开发初级00_1如何在安卓开发之发送广播
- 双色球选号及确认中几等奖
- Codeforces 788B Weird journey (欧拉回路 组合数计数)
- hdu 6098
- 关于redis
- 六分钟八法则塑造优秀程序员
- AOP的底层实现-CGLIB动态代理和JDK动态代理
- io-RandomAccessFile类
- Hadoop MapReduce初窥-wordcount示例
- windows服务器下配置memcache最大内存值
- I2C总线的简单理解
- 设计模式有什么用