题目链接:http://codeforces.com/contest/798/problem/D

题意:给出两串长度为n的数组a,b,然后要求长度小于等于n/2+1的p数组是的以p为下表a1~ap的和乘以2

大于a数组全部数的总和,b也是同理。

题解:一看到这题一般会想到贪心,由于是二维的贪心,所以一定要想让一维有序,所以可以按照a先排一下序。

得到排序后的数组a',先加上a'然后在依次两两选择b大的加上。

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int M = 1e5 + 10;
struct TnT {
int a , b , num;
}T[M];
bool cmp(TnT x , TnT y) {
return x.a > y.a;
}
int main() {
int n;
cin >> n;
for(int i = 0 ; i < n ; i++) {
cin >> T[i].a;
T[i].num = i + 1;
}
for(int i = 0 ; i < n ; i++) {
cin >> T[i].b;
}
sort(T , T + n , cmp);
if(n % 2 == 0) {
cout << n / 2 + 1 << endl;
cout << T[0].num;
for(int i = 1 ; i < n - 2 ; i += 2) {
if(T[i].b < T[i + 1].b) {
cout << ' ' << T[i + 1].num;
}
else {
cout << ' ' << T[i].num;
}
}
cout << ' ' << T[n - 1].num << endl;
}
else {
cout << n / 2 + 1 << endl;
cout << T[0].num;
for(int i = 1 ; i < n - 1 ; i += 2) {
if(T[i].b < T[i + 1].b) {
cout << ' ' << T[i + 1].num;
}
else {
cout << ' ' << T[i].num;
}
}
cout << endl;
}
return 0;
}

codeforces 798 D. 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. Codeforces Round #546 (Div. 2) D 贪心 + 思维

    https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...

  3. codeforces 798 C. Mike and gcd problem(贪心+思维+数论)

    题目链接:http://codeforces.com/contest/798/problem/C 题意:给出一串数字,问如果这串数字的gcd大于1,如果不是那么有这样的操作,删除ai, ai + 1 ...

  4. Codeforces 798D Mike and distribution - 贪心

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

  5. 【codeforces 798D】Mike and distribution

    [题目链接]:http://codeforces.com/contest/798/problem/D [题意] 让你选一个下标集合 p1,p2,p3..pk 使得2*(a[p1]+a[p2]+..+a ...

  6. Codeforces 798 B. Mike and strings-String的find()函数

    好久好久好久之前的一个题,今天翻cf,发现这个题没过,补一下. B. Mike and strings time limit per test 2 seconds memory limit per t ...

  7. codeforces 807 E. Prairie Partition(贪心+思维)

    题目链接:http://codeforces.com/contest/807/problem/E 题意:已知每个数都能用x=1 + 2 + 4 + ... + 2k - 1 + r (k ≥ 0, 0 ...

  8. CF798D Mike and distribution 贪心

    我感觉这道题挺神的~ 假设 $a[i]=b[i]$,那么我们可以将 $a$ 降序排序,然后你发现只要你按照 $1,3,5......n$ 这么取一定是合法的. 而我们发现 $2$ 比取 $3$ 优,取 ...

  9. CodeForces 518E Arthur and Questions(贪心 + 思维)题解

    题意:给你a1~an,k,要求a1 + ... + ak < a2 + .... + ak+1 < a3 + ... + ak+2 <...,然后这里的ai有可能是?,要求你填?的数 ...

随机推荐

  1. Android 9.0 关机流程分析

    极力推荐文章:欢迎收藏 Android 干货分享 阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android 本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以 ...

  2. axios配置请求头content-type

    现在前端开发中需要通过Ajax发送请求获取后端数据是很普遍的一件事情了,鉴于我平时在撸码中用的是vue技术栈,今天这里来谈谈我们常用的发Ajax请求的一个插件—axios.> 现在网上可能发送A ...

  3. 图解SSH隧道功能

    SSH能够对SSH客户端与服务器端之间的网络通信提供加密功能,而且SSH的端口转发功能还能将其它TCP端口的网络数据通过SSH连接来转发,并且自动提供相应的加密和解密服务,这一过程也被称为“隧道”(t ...

  4. Java Web基础面试题整理

    Tomcat的缺省端口是多少,怎么修改 tomcat默认缺省端口是8080 修改方法: 找到Tomcat目录下的conf文件夹 进入conf文件夹里面找到server.xml文件 打开server.x ...

  5. Python连载30-多线程之进程&线程&线程使用举例

    一.多线程 1.我们的环境 (1)xubuntu 16.04(2)anaconda(3)pycharm(4)python 3.6 2.程序:一堆代码以文本的形式存入一个文档 3.进程:程序运行的一个状 ...

  6. Linux--shell练习题

    1.判断/etc/inittab文件是否大于100行,如果大于,则显示”/etc/inittab is a big file.”否者显示”/etc/inittab is a small file.” ...

  7. SpringCloud微服务小白入门之Eureka注册中心和服务中心搭建示例

    一.注册中心配置文件 代码复制区域: spring: application: name: spring-cloud-server server: port: 7000 eureka: instanc ...

  8. 1.Apache的配置

    1.phpStudy的目录结构 1.1phpStudy的主目录路径:F:\phpStudy 1.2Apache的主目录路径 2.Apache启动和停止方法 2.1.通过任务栏phpStudy 图片进行 ...

  9. python代码规范整理

    规范参考源: 1.pep8(python代码样式规范):中文文档      https://blog.csdn.net/ratsniper/article/details/78954852 2.pep ...

  10. Java 迭代接口:Iterator、ListIterator 和 Spliterator

    1. 简介 当我们使用 for 或 while 循环来遍历一个集合的元素,Iterator 允许我们不用担心索引位置,甚至让我们不仅仅是遍历一个集合,同时还可以改变它.例如,你如果要删除循环中的元素, ...