CodeForces 149C - Division into Teams(贪心)

C. Division into Teams
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).

The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).

Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:

  • Each boy plays for exactly one team (x + y = n).
  • The sizes of teams differ in no more than one (|x - y| ≤ 1).
  • The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally:

Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.

Input

The first line contains the only integer n (2 ≤ n ≤ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 ≤ ai ≤ 104), the i-th number represents the i-th boy's playing skills.

Output

On the first line print an integer x — the number of boys playing for the first team. On the second line print x integers — the individual numbers of boys playing for the first team. On the third line print an integer y — the number of boys playing for the second team, on the fourth line print y integers — the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| ≤ 1, and the condition that limits the total skills.

If there are multiple ways to solve the problem, print any of them.

The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.

Sample test(s)
input
3
1 2 1
output
2
1 2 
1
3 
input
5
2 3 3 1 1
output
3
4 1 3 
2
5 2 
Note

Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 ≤ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 ≤ 2) is fulfilled.



=============================

因为题目说队员数不能想差超过1,而且两队球员的能力不能相差超过所有球员之中最高的那个,所以对球员能力排序,再贪心一下,先不算能力最高的那个人,两个队伍交叉分配,最后把能力最高的队员加进去……我也不知道我这个想法对不对不过总之还算是A了orz


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

struct player
{
    int num;
    int value;
}s[111111];

bool cmp(player a,player b)
{
    return a.value>b.value;
}

int main()
{
    int n,va=0,vb=0,a[55555],b[55555],flag=1,ok=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&s[i].value);
        s[i].num=i+1;
    }
    sort(s,s+n,cmp);
    int j=0,k=0;
    for(int i=1;i<n;i++)
    {
        if(flag)
        {
            va+=s[i].value;
            a[j]=s[i].num;
            j++;
        }
        else
        {
            vb+=s[i].value;
            b[k]=s[i].num;
            k++;
        }
        flag=!flag;
    }
    if(flag)
    {
        if(va<vb)
        {
            a[j]=s[0].num;
            ok=1;
        }
        else b[k]=s[0].num;
    }
    else b[k]=s[0].num;
    if(ok)
    {
        cout<<(n+1)/2<<endl;
        for(int i=0;i<=j;i++)
            cout<<a[i]<<" ";
        cout<<endl;
        cout<<n/2<<endl;
        for(int i=0;i<k;i++)
            cout<<b[i]<<" ";
        cout<<endl;
    }
    else
    {
        cout<<(n+1)/2<<endl;
        for(int i=0;i<=k;i++)
            cout<<b[i]<<" ";
        cout<<endl;
        cout<<n/2<<endl;
        for(int i=0;i<j;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
    return 0;
}


从零到一:uniPush2.0全链路集成与多厂商通道配置实战 本文提供了uniPush2.0从零开始的全链路集成与多厂商通道配置实战指南。详细讲解了DCloud平台配置、uniCloud云函数开发、客户端CID获取与消息监听,并重点攻克了华为、小米、OPPO、vivo等主流厂商推送通道的配置难点与避坑技巧,帮助UniApp开发者实现“一次集成,全端覆盖”的高效消息推送方案。 阅读详情

相关推荐

ROS Navigation global_planner框架解析

ROS Navigation global_planner框架解析主要讲一下我看源码总结的框架,如果大家跟着这个框架看源码的话可能会看的比较快。主要讲解global_planner关键配置参数含义及关键函数Astar,Dijkstra,QuadraticCalculator::calculatePotential,PotentialCalculator::calculatePotential,GridPath::getPath,GradientPath::getPath.

Jeff_Lee_的博客 4694

Codeforces 149C Division Into Teams 构造

点击打开链接 题意:n个人(n 构造即可:按价值排序后 奇数号给x,偶数号给y(天平倾斜向每次选人的那一边)每轮两边差为a[i]-d d>=0 所以两边差始终 #include using namespace std; const int N=2e5+20; int n; pair a[N]; vector x,y; int main() { while(cin>>n) {

Masamiiiiii 457

频偏估计技术:从原理到5G应用的实战解析

本文深入解析了5G通信中的频偏问题及其核心技术。频偏如同调不准的旋钮,会导致信号失真与载波间干扰。文章详细拆解了整数倍与小数倍频偏估计两大核心方法,重点剖析了基于循环前缀和基于同步信号块的算法原理与优劣,并结合eMBB、mMTC、URLLC三大5G应用场景,提供了实战算法选择策略与参数调优避坑指南。

weixin_29218963的博客 262

Codeforces 149C Division into Teams(模拟)

Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).

HJY 457

ENVI-met新手必看:从零开始创建城市微气候模型(附详细步骤+底图制作技巧)

本文为ENVI-met新手提供从零开始创建城市微气候模型的详细指南,包括环境准备、参数配置、底图制作技巧和三维模型构建步骤。特别针对常见问题提供解决方案,帮助初学者快速掌握城市微气候模拟技术,提升建模效率。

weixin_29269441的博客 405

港口集装箱码头运营FlexSim仿真

列队4中的集装箱会根据不同类型的集装箱会放置在不同的堆场,因此根据前面对集装箱设置的标签Type的数值不同,设置不同的发送端口。集装箱到达列队3后,会有70%的集装箱到达堆场,30%的集装箱运出港口,因此在Queue列队3的Flow界面设置按照百分比发送端口,其中70%发送到端口1,即发送到列队4等待进入堆场,30%发送到端口2,即发送至出闸口。通过上述对比表格可以看出,当集卡数量在10的时候,岸桥和场桥的设备利用率达到了最高,当集卡数量为12的时候场桥1和场桥3的利用率有所下降,因此综合考虑。

m0_72514516的博客 1331

Codeforces149 C. Division into Teams(思维,转化为数轴上的点)

题意: 给定长度为n的序列a,要求将这n个数分成两个集合,满足一下条件: 1.两个集合大小的差值不超过1 2.设Ma=max(ai),要求两个集合中,数的和的差值不超过Ma,即: 输出划分方案。 数据范围:n<=1e5,1<=a(i)<=1e4 解法: 将数排序,奇数位置的放在一个集合,偶数位置的放在一个集合,这样一定满足条件. 证明: 将n个数转化为数轴上的点,显然相邻点的差值和=最大值-最小值<=Ma. 上面的选法,使得两个集合中,数的和的差值一定是若干对相邻点差值的和,也一

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz 195

倍福---EL2262模块飞拍配置

控制器安装了twincat3,用EL2262实现相机飞拍功能。本文档只介绍如何通过EL2262实现飞拍的触发,并不涉及视觉方面的处理 参考文章: https://author.baidu.com/home?from=bjh_article&app_id=1669190598708386 https://mp.weixin.qq.com/s/r4Iq8kOP-o4_M8vCce5M9g 1、 飞拍的应用 在大多数场合,只能当被检测工件和相机都处于静止状态下才能进行拍照,拍照完成后,再移动工件或相机,进

weixin_41883890的博客 3742

Codeforces 149C(脑洞)

问题描述: Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to h

wust_cyl的博客 433

QT实现警报应用程序

QT实现警报应用程序

希望我的博客,能帮上你解决学习中工作中所遇到的问题 2041

获取iOS设备唯一标识UUID(Swift版)

属性返回的UUID是与应用程序相关联的,也就是说,如果用户卸载并重新安装应用程序,该UUID可能会发生变化。如果您需要一个与设备相关的持久唯一标识符,您可以考虑使用Keychain或其他方法来存储和检索设备标识符。在iOS开发中,我们经常需要获取设备的唯一标识符来进行一些特定的操作,比如设备识别、数据追踪等。在本文中,我将向您展示如何使用Swift编程语言获取iOS设备的唯一标识UUID。通过上述代码,您可以在您的iOS应用程序中轻松获取设备的唯一标识符。属性来获取设备的唯一标识UUID。

BitNetO的博客 1919

Codeforces 149C Division into Teams

C. Division into Teams time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Petya loves football very much, especially when his parent...

Yuki_fx的博客 426

FISCO BCOS(一)———搭建单群组FISCO BCOS联盟链

1、安装ubuntu依赖 sudo apt install -y openssl curl 2、创建操作目录, 下载安装脚本 创建操作目录 cd ~ && mkdir -p fisco && cd fisco 下载脚本 curl -#LO https://github.com/FISCO-BCOS/FISCO-BCOS/releases/download/v2.8.0/build_chain.sh && chmod u+x build_chain.

林中有神君 6652

Codeforces 149C Division into Teams【贪心】

C. Division into Teams time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Petya loves football very much, especially whe

mengxiang000000 365

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

cf#106-C. Division into Teams-贪心

http://codeforces.com/problemset/problem/149/C 题意: 给n个数,要求平均分成两堆,(偶数则每堆n/2个数,奇数则一堆比另一堆多1个数) 要求两堆最后的总和之差的绝对值 《 max(a[i])(最大元素值) 也就是尽可能平均就好啦。直接sort,然后往两边丢,每次丢两个,哪一堆比较小,就往哪一堆丢一个大的元素 ......居然

缺氧 496

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

Codeforces 149C Division into Teams 【思维】

C. Division into Teams time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Petya loves football very much, espe

世界很大 630

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

1256 E-Yet Another Division Into Teams 划分组-dp

题目链接:https://codeforces.com/contest/1256/problem/E 题目大意:有n个人,每个人有一个能力,现在让你分组。每组至少3个人。团队的多样性是这个团队的:最大能力-最小能力。 总的多样性:所有团队的多样性的和。 让你分组:使总多样性最小。 我们尽量让能力相近的人分到一组。 我们先排个序,就会得到一个贪心的策略:每个组最多为连续的5个人。如果6个人,分成两...

H_ang的博客 392

【CodeForces 1256E --- Yet Another Division Into Teams】

【CodeForces 1256E --- Yet Another Division Into Teams】 Description There are n students at your university. The programming skill of the i-th student is ai. As a coach, you want to divide them into te...

来日浅谈的博客 738

E. Yet Another Division Into Teams

题目链接 time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output There are ???? students at your university. The programming skill of the ????-th student is ????????....

weixin_43916280的博客 316

CodeForces 165C - Another Problem on Strings

C. Another Problem on Strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A string is binary, if it con

coco430的专栏 1270

CodeForces 149B - Martian Clock

B. Martian Clock time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Having stayed home alone, Petya decided to

coco430的专栏 1077

CodeForces 165B - Burning Midnight Oil(二分)

B. Burning Midnight Oil time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day a highly important task was

coco430的专栏 1074

CodeForces 160B - Unlucky Ticket

B. Unlucky Ticket time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Each of you probably has your personal ex

coco430的专栏 947

CodeForces 204B - Little Elephant and Cards

B. Little Elephant and Cards time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The Little Elephant loves to play with c

coco430的专栏 944

CodeForces 141B - Hopscotch

B. Hopscotch time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output So nearly half of the winter is over and Maria

coco430的专栏 929

CodeForces 148C - Terse princess

C. Terse princess time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output «Next please», — the princess called and

coco430的专栏 765
上一篇: CodeForces 148B - Escape
下一篇: CodeForces 148C - Terse princess
coco430
博客等级 码龄14年 9粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值