CF798D Mike and distribution 贪心
我感觉这道题挺神的~
假设 $a[i]=b[i]$,那么我们可以将 $a$ 降序排序,然后你发现只要你按照 $1,3,5......n$ 这么取一定是合法的.
而我们发现 $2$ 比取 $3$ 优,取 $4$ 还比取 $5$ 优.
所以,我们可以这样:
强制性取第一个元素,然后其余 $\frac{n}{2}$ 个元素每相邻两个依次考虑,不论拿哪个都是合法的.
这样做有什么好处呢?由于 $a$ 可以这样随便拿,于是每一次就取更大的 $b$ 就好了.
所以,我们按照 $a$ 从大到小排一个序,然后依次贪心选取 $b$ 即可.
code:
#include <bits/stdc++.h>
#define N 100020
#define setIO(s) freopen(s".in","r",stdin)
using namespace std;
struct node
{
int x,y,num;
}a[N];
int n,cnt,ans[N];
int cmp(node x,node y)
{
return x.x==y.x?x.y>y.y:x.x>y.x;
}
int main()
{
// setIO("input");
int i,j;
scanf("%d",&n);
for(i=1;i<=n;++i) scanf("%d",&a[i].x);
for(i=1;i<=n;++i) scanf("%d",&a[i].y);
for(i=1;i<=n;++i) a[i].num=i;
sort(a+1,a+1+n,cmp), ans[++cnt]=a[1].num;
for(i=2;i<=n;i+=2)
{
if(a[i].y>a[i+1].y) ans[++cnt]=a[i].num;
else ans[++cnt]=a[i+1].num;
}
printf("%d\n",cnt);
for(i=1;i<=cnt;++i) printf("%d ",ans[i]);
return 0;
}
CF798D Mike and distribution 贪心的更多相关文章
- CF798D Mike and distribution
CF798D Mike and distribution 洛谷评测传送门 题目描述 Mike has always been thinking about the harshness of socia ...
- [CF798D]Mike and distribution_贪心
Mike and distribution 题目链接:http://codeforces.com/problemset/problem/798/D 数据范围:略. 题解: 太难了吧这个题..... 这 ...
- Codeforces 798D Mike and distribution - 贪心
Mike has always been thinking about the harshness of social inequality. He's so obsessed with it tha ...
- Codeforces 798D Mike and distribution(贪心或随机化)
题目链接 Mike and distribution 题目意思很简单,给出$a_{i}$和$b_{i}$,我们需要在这$n$个数中挑选最多$n/2+1$个,使得挑选出来的 $p_{1}$,$p_{2} ...
- codeforces 798 D. Mike and distribution
D. Mike and distribution time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- #410div2D. Mike and distribution
D. Mike and distribution time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- D. Mike and distribution 首先学习了一个玄学的东西
http://codeforces.com/contest/798/problem/D D. Mike and distribution time limit per test 2 seconds m ...
- CF410div2 D. Mike and distribution
/* CF410div2 D. Mike and distribution http://codeforces.com/contest/798/problem/D 构造 题意:给出两个数列a,b,求选 ...
- 【算法系列学习】codeforces D. Mike and distribution 二维贪心
http://codeforces.com/contest/798/problem/D http://blog.csdn.net/yasola/article/details/70477816 对于二 ...
随机推荐
- K number(思维和后缀以及3的特性)(2019牛客暑期多校训练营(第四场))
示例1: 输入:600 输出:4 说明:'600', '0', '0', '00' are multiples of 300. (Note that '0' are counted twice bec ...
- Mybatis动态sql及分页、特殊符号
目的: mybatis动态sql(案例:万能查询) 查询返回结果集的处理 mybatis的分页运用 mybatis的特殊符号 mybatis动态sql(案例:万能查询) 根据id查询 模糊查询 (参数 ...
- CentOS7 安装 Git
环境: 系统版本:CentOS 7.5 Git 版本:2.20.1 一.安装 Git 1.下载编译工具 $ yum -y groupinstall "Development Tools&qu ...
- hdu1501 记忆化搜索。。。
Problem Description Given three strings, you are to determine whether the third string can be formed ...
- javscript函数的运用
函数,一段能够自动完成某些功能的代码块,函数的出现,既解决了重复使用重一功能的需求,又可以避免代码的臃肿性. 使用函数有两个要求:必须调用后才可以执行;函数名不要和关键字以及系统函数相同; 函数主要有 ...
- web前端如何优化自己的代码
前端的性能优化主要分为三部分: HTML优化 避免 HTML 中书写 CSS 代码,因为这样难以维护. 使用Viewport加速页面的渲染. 使用语义化标签,减少 CSS 代码,增加可读性和 SEO. ...
- python小实例——tkinter实战(计算器)
一.完美计算器实验一 import tkinter import math import tkinter.messagebox class calculator: #界面布局方法 def __init ...
- Linux 终端下的颜色
Linux 终端下颜色的输出 在命令行下也能产生五颜六色的字体和图案,只需要加上一些颜色代码,例如 echo -e "\033[41;36m 红底绿字\033[0m" 其中41的位 ...
- Thymeleaf 模板
Thymeleaf 模板布局 th:fragment.th:replace.th:insert.th:remove th:fragment 模板布局 模板片段说明 模板中,经常希望从其他模板中包含⼀ ...
- RMAN恢复数据文件
实验之前先备份数据库 RMAN>backup database; 在操作系统中删除数据文件 5 SQL> startup ORACLE 例程已经启动. Total System Globa ...