题目链接: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. .Net集合详解

    前言 前面几篇文章讲了泛型.讲了数组,都有提到集合,这一节重点对集合进行详细解说.本文主要使用各种集合类型.以至于评估其性能,针对不同的场景选择不同的集合使用. 集合分类详解 一.列表 列表的创建 v ...

  2. 【Vue前端】Vue前端注册业务实现!!!【代码】

    用户注册前端逻辑 1. Vue绑定注册界面准备 1.导入Vue.js库和ajax请求的库 <script type="text/javascript" src="{ ...

  3. win10去除快捷方式小箭头

    切忌删除注册表项: HKEY_CLASSES_ROOT -> lnkfile -> IsShortcut 这个方法以前是可以的,但是在2018年之后更新的系统就会出现任务栏图标打不开的情况 ...

  4. 图片验证码+session

    生成随机验证码 #!/usr/bin/env python # -*- coding:utf-8 -*- import random from PIL import Image, ImageDraw, ...

  5. c#小灶——注释和代码规范

    为什么要写注释? 早上我写完了代码,我和我的朋友们都能看懂,到了晚上,我还能看懂,一周后,就只有上帝能看懂了…… 将来我们写的代码量是很大的,代码又不像我们自然语言这么好理解,可能过段时间我们就不认识 ...

  6. Linux基础文件类型

    一.文件时间 ls -l 文件名 仅看的是文件的修改时间 [root@linux ~]# ls -l /etc/passwd -rw-r--r-- root root 5月 : /etc/passwd ...

  7. Java 设置PDF文档浏览偏好

    在查看PDF文档时,可进行一些浏览偏好设置,例如是否全屏浏览.隐藏或显示菜单栏/工具栏.设置页面布局模式等,下面将通过Java编程的方式来演示如何设置. 使用工具: Free Spire.PDF fo ...

  8. maysql的自增字段

    因为mysql中的自增字段与oracle数据库是不一样的,所以在这里唠嗑一下mysql的自增字段 1.添加自增字段 1.1 在创建表时添加 create table emp( empno ) auto ...

  9. 为什么建立数据仓库需要使用ETL工具?

    在做项目时是不是时常让客户有这样的困扰: 1.开发时间太长 2.花费太多 3.需要太多资源 4.集成多个事务系统数据总是需要大量人力成本 5.找不到合适的技能和经验的人 6.一旦建立,数据仓库无法足够 ...

  10. http测试工具

    http测试工具: https://github.com/denji/awesome-http-benchmark wrk https://github.com/wg/wrk wrk2 https:/ ...