Codeforces 149C(脑洞)
来源:互联网 发布:人工神经网络算法实例 编辑:程序博客网 时间:2024/06/12 20:08
问题描述:
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 nboys 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.
InputThe 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.
input
3
1 2 1
output
2
1 2
1
3
题目题目:题目给了n个人的足球技能值,让我们把他们分成俩队满足那三个条件。
题目分析:我们按照技能值的大小排序,然后把奇数的丢到X队,偶数丢到Y队
代码如下:
#include<iostream>#include<cstdio>#include<cmath>#include<algorithm>#include<vector>using namespace std;const int maxn=1e5+100;struct note{ int val,cnt;}a[maxn];vector<struct note> vec_x,vec_y;bool cmp(struct note a,struct note b){ return a.val<b.val;}int main(){ int n,Max; while (scanf("%d",&n)!=EOF) { Max=0; vec_x.clear(); vec_y.clear(); for (int i=0;i<n;i++) { scanf("%d",&a[i].val); a[i].cnt=i+1; Max=max(Max,a[i].val); } int sum_x=0,sum_y=0; sort(a,a+n,cmp); for (int i=0;i<n;i++) { if (i%2==0) { vec_x.push_back(a[i]); sum_x+=a[i].val; } else { vec_y.push_back(a[i]); sum_y+=a[i].val; } } printf("%d\n",vec_x.size()); for (int i=0;i<vec_x.size();i++) { if (i==vec_x.size()-1) printf("%d\n",vec_x[i].cnt); else printf("%d ",vec_x[i].cnt); } printf("%d\n",vec_y.size()); for (int i=0;i<vec_y.size();i++) { if (i==vec_y.size()-1) printf("%d\n",vec_y[i].cnt); else printf("%d ",vec_y[i].cnt); } } return 0;}
- Codeforces 149C(脑洞)
- CodeForces 146C(脑洞)
- Codeforces 160C(脑洞)
- Codeforces 197C (脑洞)
- Codeforces 635C XOR Equation (脑洞)
- Codeforces Round #403 C. Underground Lab(脑洞)
- Codeforces 149C Division into Teams 【思维】
- Codeforces 149C Division Into Teams 构造
- Codeforces 149C Division into Teams【贪心】
- Codeforces 149C Division into Teams
- Codeforces-340-C(c++)
- Codeforces-507-C(c++)
- CodeForces 731C C
- CodeForces-612C C
- CODEFORCES 265C CODEFORCES, 265C
- codeforces #78 div2 C
- Codeforces 117C Cycle
- CodeForces 209C
- 双循环链表
- Java8Stream_API详解
- 零基础掌握百度地图兴趣点获取POI爬虫(python语言爬取)(代码篇)
- SmarNC数控仿真软件v1.0.1412 官方版下载
- 模拟SSM页面分页的测试
- Codeforces 149C(脑洞)
- Leetoced 81. Search in Rotated Sorted Array II
- 【Deep Learning】win10下无GPU配置tensorflow
- 利用爬虫技术获取网页数据,以及想要的指定数据
- 如何在cmd下面启动Tomcat?
- 汉诺塔问题
- ODI配置使用日志记录streams实现表同步
- 使用VMWareWorkstation10搭建学习环境(学习笔记)
- 计算机视觉学习笔记:深度学习基础——CS231n_assignment1