题目连接

一道人类智慧题。。。。

这道题目可以转化为在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. 深入浅出 Java Concurrency (19): 并发容器 part 4 并发队列与Queue简介[转]

    Queue是JDK 5以后引入的新的集合类,它属于Java Collections Framework的成员,在Collection集合中和List/Set是同一级别的接口.通常来讲Queue描述的是 ...

  2. [转]WinForm实现win7 Aero磨砂效果介绍

    WinForm实现win7 Aero磨砂效果如下: WinForm实现win7 Aero磨砂效果代码如下: using System; using System.Collections.Generic ...

  3. Javascript-循环输出菱形,并可菱形自定义大小

    var Cen = 6;//定义菱形中部为第几行(起始值为0) //for循环输出菱形 document.write("<button onclick='xh()'>点我for循 ...

  4. [Array]268. Missing Number

    Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...

  5. JS简单实现:根据奖品权重计算中奖概率实现抽奖的方法

    本文主要介绍:使用 JS 根据奖品权重计算中奖概率实现抽奖的方法. 一.示例场景 1.1.设置抽奖活动的奖项名称 奖项名称:["一等奖", "二等奖", &qu ...

  6. vue打包之部署在非根路径下的三两事

    首先,感叹一下,2019年已经过去一半,想想自己做了些什么,好像也没做什么. 今天试着配一个nginx,以前的nginx都是指向的/根路径,今天的nginx指向的非/根路径,遇到许多问题的,总结总结. ...

  7. java笔记之split

    Java split()用法 特殊情况有 * ^ : | . \ 一.单个符号作为分隔符  String address="上海\上海市|闵行区\吴中路"; String[] sp ...

  8. day38 02-Spring快速入门

    Spring的核心是IOC和AOP,其他的什么像SpEL都是对IOC的支持. Spring里面的web指的是它可以使用Spring MVC. 集成指的是整合其他的框架. schema是所有配置文件的约 ...

  9. Struts_改写客户列表练习

    1.CustomerAction修改放入ActionContext 2.list.jsp使用struts标签库

  10. Leetcode15.3Sum三数之和

    给定一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?找出所有满足条件且不重复的三元组. 注意:答案中不可以包含重复的三元组. ...