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:平均情况时间复杂度( ...
随机推荐
- html 基础--一般标签
<html> --开始标签 <head> 网页上的控制信息 <title>页面标题</title> </head> <body& ...
- Sublime Text Shortcuts
Keyboard Shortcuts - Windows/Linux Warning This topic is a draft and may contain wrong information. ...
- redis 笔记04 服务器、复制
服务器 1. 一个命令请求从发送到完成主要包括以下步骤: 1). 客户端将命令请求发送给服务器 2). 服务器读取命令请求,并分析出命令参数 3). 命令执行器根据参数查找命令的实现函数,然后执行实现 ...
- Java基础之冒泡排序
冒泡排序 基本介绍 冒泡排序是比较相邻的两个元素,通过不停的比较,较大的数往下沉,较小的往上冒,这也是冒泡排序名字的来源 第一趟从数组下标为0的数字开始,arr[0]大于arr[1]就交换他们的位置, ...
- 关于camera 构架设计的一点看法
camera的构架目前来看有两种,一种是集中式管理,比如说建立一个引擎,引擎向上提供接口,向下管理所有模块.把camera的所有功能划分为不同的模块,又引擎统一管理.模块的结构就比较随意了,可以统一接 ...
- python django model filter 条件过滤,及多表连接查询、反向查询,某字段的distinct[转]
1.多表连接查询:当我知道这点的时候顿时觉得django太NX了. class A(models.Model): name = models.CharField(u'名称') clas ...
- Sort Colors,颜色排序
问题描述:Given an array with n objects colored red, white or blue, sort them so that objects of the same ...
- crontab 参数详解
crontab 参数 用户所建立的crontab文件中,每一行都代表一项任务,每行的每个字段代表一项设置,它的格式共分为六个字段,前五段是时间设定段,第六段是要执行的命令段,格式如下: minute ...
- istringstream 用法
istringstream 类用于执行C++风格的串流的输入操作 istringstream用空格作为字符串分隔符 #include <iostream>#include <sstr ...
- bootstrap框架:常用内容一
<!DOCTYPE html><html lang="zh-CN"> <head> <meta charset="utf-8&q ...