$$ \newcommand{\seq}[2]{{#1}_{1},{#1}_{2},\cdots,{#1}_{#2}} \newcommand{\num}[1]{1,2,\cdots,#1} \newcommand{\stra}[2]{\begin{bmatrix}#1 \\ #2\end{bmatrix}} \newcommand{\strb}[2]{\begin{Bmatrix}#1 \\ #2\end{Bmatrix}} \newcommand{\dw}[1]{\underline{#1}} \newcommand{\up}[1]{\overline{#1}} $$

Codeforces 1013

1013 B

题意

给你一个 \(a\) 数组和一个整数 \(x\) ,每次你可以把一个 \(a_i\) 按位与上 \(x\) ,问最少操作几次使得数组中存在相同元素 \((n,a_i\le 10^5)\)

Examples

input
4 3
1 2 3 7
output
1
input
2 228
1 1
output
0
input
3 7
1 2 3
output
-1

遍历一遍,遍历的同时将 \(a_i&x\)\(a_i\) 装桶,并判断。

1013 C

题意

给你平面上的 \(n/2\) 个点,现在把点的 \(x,y\) 坐标合并到同一个序列中,然后随机打乱作为输入给你,问能覆盖所有点的最小矩形的面积的最小可能值。 \((n\le 10^5)\)

Examples

input
4
4 1 3 2 3 2 1 3
output
1
input
3
5 8 5 5 7 5
output
0

题意等价于把一个序列分成长度皆为 \(n/2\) 的两部分。
首先肯定得排序,然后发现该序列要么被分成左、右两部分,要么被分成左、中、右三部分(其中左、右部分为同一种坐标类型)。
当分成两部分时,序列的最大和最小值被分开在两部分中,那么左边贡献为 \(a[n/2]-a[1]\) ,右边贡献为 \(a[n]-a[n/2+1]\)
当分成三部分时,序列的最大和最小值是同一种类型,那么第一种类型贡献为 \(a[n]-a[1]\) ,第二种贡献为 \(\min_{i\in [n/2+1,n]}(a_i-a_{i-n/2})\)
然后两种情况取个 \(\min\)

1013 D

题意

给你一个 \(n*m\) 的表格(元素周期表),其中有一些元素已经有了,当位于 \((x_1,y_1),(x_1,y_2),(x_2,y_1)\) 的元素都有时,可以制造出位于 \((x_2,y_2)\) 的元素。问最少从商店购买几种元素使得能拥有所有的元素。 \((1\le n,m\le 2*10^5)\)

Examples

input
2 2 3
1 2
2 2
2 1
output
0
input
1 5 3
1 3
1 1
1 5
output
2
input
4 3 6
1 2
1 3
2 2
2 3
3 1
3 3
output
1

首先建立一个二分图模型。若 \((i,j)\) 的元素已经有了,连边 \(i→j\)
然后再模拟一波,发现位置 \((x,y)\) 的元素经过若干操作能被拥有的条件为 \(x,y\) 在同一个连通块内。
于是使用并查集维护连通性,最后统计有几个连通块,答案为连通块个数-1。

1013 E

题意

n座山,需要分别选出\(1...n/2\)座建造房子(满足高于左右两边的山),每次可以把一座山降低1个高度,问最少需要多少次操作,然后分别输出。

Examples

input
5
1 1 1 1 1
output
1 2 2
input
3
1 2 3
output
0 2
input
5
1 2 3 2 2
output
0 1 3

\(n^2\;dp\)
\(dp[i][j][0/1]\) 表示枚举到 \(i\) ,有 \(j\) 座建了房子,当前这座建没建
状态转移方程:
\(dp[i][j][0]=\min(dp[i-1][j][0],dp[i-1][j][1]+\max(a[i]-a[i-1]+1,0))\)
\(dp[i][j][1]=\min(dp[i-2][j-1][0]+\max(a[i-1]-a[i]+1,0),dp[i-2][j-1][1]+\max(a[i-1]-a[i-2]+1,a[i-1]-a[i]+1,0))\)

1013 F

题意

$$\color{white}{???}$$

Examples

posted @ 2019-03-08 21:03  chc_1234567890  阅读(333)  评论(0编辑  收藏  举报