题目链接: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. MySQL-5.7.21非图形化下载、安装、连接问题记录

    1.安装包下载链接:https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.21-winx64.zip 官网:https://www.mysql.co ...

  2. 关于Unity 中对UGUI制作任务系统的编程

    版权声明: 本文原创发布于博客园"优梦创客"的博客空间(网址:http://www.cnblogs.com/raymondking123/)以及微信公众号"优梦创客&qu ...

  3. 不等"金九银十",金风八月,我早已拿下字节跳动的offer

    字节跳动,我是在网上投的简历,之前也投过一次,简历都没通过删选,后来让师姐帮我改了一下简历,重新投另一个部门,获得了面试机会.7月23日,中午HR打电话过来预约了下午4点半面试,说会在线写代码,让我准 ...

  4. 使用 OpenSSL为WindowsServer远程桌面(RDP)创建自签名证书 (Self-signed SSL certificate)

    前言 笔者查阅很多资料,才写成此文章,如有错误,请读者们及时提出. 一般大家使用远程桌面(Remote Desktop)连接Windows Server时,总会有一个警告提示,如图1 图1 出现此警告 ...

  5. 统计学习方法—SVM推导

    目录 SVM 1. 定义 1.1 函数间隔和几何间隔 1.2 间隔最大化 2. 线性可分SVM 2.1 对偶问题 2.2 序列最小最优算法(SMO) 3. 线性不可分SVM 3.1 松弛变量 3.2 ...

  6. Oracle、MySQL和Sqlserver的事务管理、分页和别名的区别

    1.在mysql中事务默认是自动提交的,只有设置autocommit为0的时候,才用自己commit(commit--rollback回滚) 2.但是在oracle中必须自己commit;不然就只能结 ...

  7. Ubuntu 17 安装Chrome浏览器

    1.进入下载文件存放目录 cd Downloads 2.下载chrome文件 2.1 32位使用如下命令 wget https://dl.google.com/linux/direct/google- ...

  8. python小白手册之字符串的私有方法和公用方法

    #字符串方法. name=input('1111') if name.isalnum(): print(是否由数字字母) isdigit isdecimal判断数字 strip去空格或者其他 name ...

  9. F#周报2019年第33期

    新闻 宣告.NET Core 3.0预览版8 新的fable.io站点伴随着更多文档发布 正在努力使你的团队相信F#的益处?Compositional IT能够提供帮助 提名2019年度F#社区英雄 ...

  10. 如何使用WorkManager执行后台任务(上)

    0x00 简述 WorkManager 是 Android Jetpack中的一部分,它主要是封装了 Android 后台任务的调度逻辑.在前文<Android后台任务处理指南>一文中知道 ...