HDU - 6098:Inversion(暴力均摊)
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(暴力均摊)的更多相关文章
- HDU 6098 - Inversion | 2017 Multi-University Training Contest 6
/* HDU 6098 - Inversion [ 贪心,数论 ] | 2017 Multi-University Training Contest 6 题意: 求出所有B[i] = max(A[j] ...
- HDU 6098 Inversion
Inversion 思路:从大到小排序后,每次找到第一个下标不整出i的输出. 代码: #include<bits/stdc++.h> using namespace std; #defin ...
- 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 , ...
- 【loj6029】「雅礼集训 2017 Day1」市场 线段树+均摊分析
题目描述 给出一个长度为 $n$ 的序列,支持 $m$ 次操作,操作有四种:区间加.区间下取整除.区间求最小值.区间求和. $n\le 100000$ ,每次加的数在 $[-10^4,10^4]$ 之 ...
- 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 ...
- 【uoj#228】基础数据结构练习题 线段树+均摊分析
题目描述 给出一个长度为 $n$ 的序列,支持 $m$ 次操作,操作有三种:区间加.区间开根.区间求和. $n,m,a_i\le 100000$ . 题解 线段树+均摊分析 对于原来的两个数 $a$ ...
- 5.15 牛客挑战赛40 B 小V的序列 关于随机均摊分析 二进制
LINK:小V的序列 考试的时候 没想到正解 于是自闭. 题意很简单 就是 给出一个序列a 每次询问一个x 问序列中是否存在y 使得x^y的二进制位位1的个数<=3. 容易想到 暴力枚举. 第一 ...
- 洛谷 P6783 - [Ynoi2008] rrusq(KDT+势能均摊+根号平衡)
洛谷题面传送门 首先显然原问题严格强于区间数颜色,因此考虑将询问离线下来然后用某些根号级别复杂度的数据结构.按照数颜色题目的套路,我们肯定要对于每种颜色维护一个前驱 \(pre\),那么答案可写作 \ ...
- Chapter4 复杂度分析(下):浅析最好,最坏,平均,均摊时间复杂度
四个复杂度分析: 1:最好情况时间复杂度(best case time complexity) 2:最坏情况时间复杂度(worst case time complexity) 3:平均情况时间复杂度( ...
随机推荐
- POJ 1659 Frogs' Neighborhood (Havel定理构造图)
题意:根据图的度数列构造图 分析:该题可根据Havel定理来构造图.Havel定理对可图化的判定: 把序列排成不增序,即d1>=d2>=……>=dn,则d可简单图化当且仅当d’={d ...
- ado.net(增删改)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- iOS7中彻底隐藏status bar
用Xcode5开发新游戏,发现在iOS7中按照以前的方法隐藏status bar失效了. 想要彻底隐藏status bar,需要在info.plist中添加新行“View controller-bas ...
- COS-2OS结构和硬件支持
操作系统(Operating System,简称OS),是电子计算机系统中负责支撑应用程序运行环境以及用户操作环境的系统软件,同时也是计算机系统的核心与基石.它的职责常包括对硬件的直接监管.对各种计算 ...
- object c中@property 的使用
assign: 对基础的数据类型,比如NSInteger和C数据类型(int,float,char)等 copy: 针对NSString retail: 针对NSObject及其子类 nonat ...
- unbntu修改mac地址
分享下Ubuntu下更改MAC地址的简单方法: 首先把网卡设备给 down 掉,否则会报告系统忙,无法更改. sudo ifconfig eth0 down 然后修改 MAC 地址,这一步较 Wind ...
- Your app uses or references the following non-public APIs的解决方案
之前接了一个旧的项目,代码混乱,年代久远,不得不吐槽一波,好不容易改完需求提交代码,说用到了non-public APIs,搞了好久终于找到地方了,下面是我的解决过程,让大家少走弯路: 下面的被驳回的 ...
- @WebListener 注解方式实现监听
1.创建 Dynamic Web Project ,Dynamic Web module version选择3.0 2.在自动生成 的web.xml配置,增加 metadata-complete=&q ...
- jq限制字符个数
<script> $(document).ready(function () { //限制字符个数 $(".box-right .title a").each(func ...
- 织梦导航 currentstyle 点击li添加class类 样式
<!--导航开始--> <div class="global_nav_wrap"> <ul class="nav nav-pills&quo ...