Question 给你一个长度为n的全为0的序列,让你从1-n填数,填的位置为找出最长的0序列,如序列长度为奇数,则为(l+r)/2,为偶数,则为(l+r-1)/2 Solution 运用优先队列,将[l,mid-1],[mid,r]push进去,运用重载运算符排序 Code #include <iostream> #include <cstdio> #include <fstream> #include <algorithm> #include <c…
题意:有一个长度为\(n\)元素均为\(0\)的序列,进行\(n\)次操作构造出一个新序列\(a\):每次选择最长的连续为\(0\)的区间\([l,r]\),使得第\(i\)次操作时,\(a[\frac{l+r}{2}]=i\)(下取整),求\(a\). 题解:刚开始我打算用归并分治的思想来写,但是发现左区间递归不到,然后就gg了. ​ 之后才发现这题用_优先队列_直接模拟就过了,题目就不说了,这儿讲一下优先队列. 优先队列与队列的区别在于,优先队列是按照某种优先级来决定谁在队头,C++默认它是…
链接: https://vjudge.net/problem/CodeForces-721D 题意: Recently Maxim has found an array of n integers, needed by no one. He immediately come up with idea of changing it: he invented positive integer x and decided to add or subtract it from arbitrary arr…
A. Friends Meeting time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the point x1 = a, another…
传送门 题目: Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d,m find the number of arrays a, satisfying the following constraints: The length of a is n, n≥1 1≤a1<a2<⋯…
比赛链接:https://codeforces.com/contest/1353 A - Most Unstable Array 题意 构造大小为 $n$,和为 $m$ 的非负数组 $a$,使得相邻元素之差的绝对值之和最大. 题解 稍加推导发现:将 $m$ 拆分和单独用 $m$ 结果是一样的,所以可以直接用 $0$ 和 $m$ 构造. 代码 #include <bits/stdc++.h> using namespace std; void solve() { int n, m; cin &g…
题目链接:HDU 1102 Constructing Roads Constructing Roads Problem Description There are N villages, which are numbered from 1 to N, and you should build some roads such that every two villages can connect to each other. We say two village A and B are conne…
Problem G: Array C Time Limit: 1 Sec  Memory Limit: 128 MB Description Giving two integers  and  and two arrays  and  both with length , you should construct an array  also with length  which satisfied: 1.0≤Ci≤Ai(1≤i≤n) 2. and make the value S be min…
1. 预备知识 (1) 基本概念     如图,(二叉)堆是一个数组,它可以被看成一个近似的完全二叉树.树中的每一个结点对应数组中的一个元素.除了最底层外,该树是完全充满的,而且从左向右填充.堆的数组A包括两个属性:A.length给出了数组的长度:A.heap-size表示有多少个堆元素保存在该数组中(因为A中可能只有部分位置存放的是堆的有效元素).     由于堆的这种特殊的结构,我们可以很容易根据一个结点的下标i计算出它的父节点.左孩子.右孩子的下标.计算公式如下: parent(i) =…
1.CF #374 (Div. 2)   D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优先队列 #include<bits/stdc++.h> #define F(i,a,b) for (int i=a;i<b;i++) #define FF(i,a,b) for (int i=a;i<=b;i++) #define mes(a,b) memset(a,b,sizeof(…