题目连接

一道人类智慧题。。。。

这道题目可以转化为在a,b中的选出一些位置,使得这些位置处的值加起来大于没有选的位置的值

我们按照a的权值排序,选择第一个元素,其与元素两两分组,每组选择b更大的那一个

很显然这样对于数组b是满足要求的,然后我们发现第i组的a权值肯定大于第i+1组的没有选的位置的权值,

在加上我们选择了第一个元素,所以a数组也是满足要求的

# include<iostream>
# include<cstdio>
# include<cmath>
# include<cstring>
# include<algorithm>
using namespace std;
const int mn = 1e5 + ;
int n,m,ans[mn],tot;
struct node{int a,b,pos;};
node da[mn];
bool cmp(node x,node y)
{
return x.a>y.a;
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&da[i].a),da[i].pos=i;
for(int i=;i<=n;i++)
scanf("%d",&da[i].b);
sort(da+,da++n,cmp);
ans[++tot]=da[].pos;
for(int i=;i<=n;i+=)
{
if(i==n)
{
ans[++tot]=da[i].pos;
break;
}
if(da[i].b>da[i+].b) ans[++tot]=da[i].pos;
else ans[++tot]=da[i+].pos;
}
printf("%d\n",tot);
for(int i=;i<=tot;i++)
printf("%d ",ans[i]);
return ;
}

CF789D Mike and distribution的更多相关文章

  1. codeforces 798 D. Mike and distribution

    D. Mike and distribution time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  2. #410div2D. Mike and distribution

    D. Mike and distribution time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  3. D. Mike and distribution 首先学习了一个玄学的东西

    http://codeforces.com/contest/798/problem/D D. Mike and distribution time limit per test 2 seconds m ...

  4. Codeforces 798D Mike and distribution(贪心或随机化)

    题目链接 Mike and distribution 题目意思很简单,给出$a_{i}$和$b_{i}$,我们需要在这$n$个数中挑选最多$n/2+1$个,使得挑选出来的 $p_{1}$,$p_{2} ...

  5. CF410div2 D. Mike and distribution

    /* CF410div2 D. Mike and distribution http://codeforces.com/contest/798/problem/D 构造 题意:给出两个数列a,b,求选 ...

  6. CF798D Mike and distribution

    CF798D Mike and distribution 洛谷评测传送门 题目描述 Mike has always been thinking about the harshness of socia ...

  7. Codeforces 798D Mike and distribution - 贪心

    Mike has always been thinking about the harshness of social inequality. He's so obsessed with it tha ...

  8. 【算法系列学习】codeforces D. Mike and distribution 二维贪心

    http://codeforces.com/contest/798/problem/D http://blog.csdn.net/yasola/article/details/70477816 对于二 ...

  9. Mike and distribution CodeForces - 798D (贪心+思维)

    题目链接 TAG: 这是我近期做过最棒的一道贪心思维题,不容易想到,想到就出乎意料. 题意:给定两个含有N个正整数的数组a和b,让你输出一个数字k ,要求k不大于n/2+1,并且输出k个整数,范围为1 ...

随机推荐

  1. TFS2013 微软源代码管理工具 安装与使用图文教程

    最近公司新开发一个项目要用微软的TFS2013进行项目的源代码管理,以前只是用过SVN,从来没有用过TFS,所以在网上百度.谷歌了好一阵子来查看怎么安装和配置,还好花了一天时间总算是初步的搞定了,下面 ...

  2. SQL Server数据库存储过程的异常处理

    SQL Server数据库存储过程的异常处理是非常重要的,明确的异常提示能够帮助我们快速地找到问题的根源,节省很多时间.本文我们就以一个插入数据为例来说明SQL Server中的存储过程怎么捕获异常的 ...

  3. php函数基础(一)

    一.函数结构   1.构成部分:             关键字 function        

  4. 使用gRPC-Gateway快速构建微服务-双向认证下rpc-gateway使用(同时提供rpc和http接口)

    https://github.com/grpc-ecosystem/grpc-gateway 在grpc之上加一层代理并转发,转变成protobuf格式来访问grpc服务 安装 go get -u g ...

  5. 原生JS制作验证码(优化)

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  6. PAT甲级——A1040 Longest Symmetric String

    Given a string, you are supposed to output the length of the longest symmetric sub-string. For examp ...

  7. JasperReport查看和打印报告7

    报表填充过程JasperPrint对象的输出可以使用内置的浏览器组件来查看,打印或导出到更多的流行的文件格式,如PDF,HTML,RTF,XLS,ODT,CSV或XML.Jasper文件查看和打印将包 ...

  8. 【python之路34】面向对象作业之学生选课系统

    一.需求: 1.可以注册管理员账号,管理员账号可以创建老师和课程 2.学生可以注册和登陆,学生可以从课程列表选课,可以进行上课登记查看 二.代码 1.文件目录 bin 存放可执行文件 config 存 ...

  9. poj 1041 John's trip——欧拉回路字典序输出

    题目:http://poj.org/problem?id=1041 明明是欧拉回路字典序输出的模板. 优先队列存边有毒.写跪.学习学习TJ发现只要按边权从大到小排序连边就能正常用邻接表了! 还有一种存 ...

  10. H5C3--盒子模型

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...