A. Array

题目连接:

http://www.codeforces.com/contest/300/problem/A

Description

Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:

The product of all numbers in the first set is less than zero ( < 0).

The product of all numbers in the second set is greater than zero ( > 0).

The product of all numbers in the third set is equal to zero.

Each number from the initial array must occur in exactly one set.

Help Vitaly. Divide the given array.

Input

The first line of the input contains integer n (3 ≤ n ≤ 100). The second line contains n space-separated distinct integers a1, a2, ..., an (|ai| ≤ 103) — the array elements.

Output

In the first line print integer n1 (n1 > 0) — the number of elements in the first set. Then print n1 numbers — the elements that got to the first set.

In the next line print integer n2 (n2 > 0) — the number of elements in the second set. Then print n2 numbers — the elements that got to the second set.

In the next line print integer n3 (n3 > 0) — the number of elements in the third set. Then print n3 numbers — the elements that got to the third set.

The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them.

Sample Input

3

-1 2 0

Sample Output

1 -1

1 2

1 0

Hint

题意

给你n个数,然后让你分成三组,要求第一组的乘积是小于0的,第二组是大于0的,第三组是等于0的

让你输出一个方案

题解:

第一组需要奇数个负数,第二组需要偶数个负数

如果负数是偶数,那么扔一个去第三组,那么就可以变成奇数了

奇数 = 奇数+偶数

所以讨论一下就好了

代码

#include<bits/stdc++.h>
using namespace std; vector<int>ans[4];
int a[400];
int main()
{
int n;
scanf("%d",&n);
int num = 0;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
if(a[i]<0)num++;
}
if(num==1)
{
for(int i=1;i<=n;i++)
{
if(a[i]<0)ans[0].push_back(a[i]);
else if(a[i]==0)ans[2].push_back(a[i]);
else ans[1].push_back(a[i]);
}
}
else if(num%2==0)
{
int k = 0;
for(int i=1;i<=n;i++)
{
if(a[i]<0&&k==0){ans[0].push_back(a[i]);k++;}
else if(a[i]<0&&k==1){ans[2].push_back(a[i]);k++;}
else if(a[i]==0)ans[2].push_back(a[i]);
else ans[1].push_back(a[i]);
}
}
else
{
int k = 0;
for(int i=1;i<=n;i++)
{
if(a[i]<0&&k==0){ans[0].push_back(a[i]);k++;}
else if(a[i]==0)ans[2].push_back(a[i]);
else ans[1].push_back(a[i]);
}
}
for(int i=0;i<3;i++)
{
printf("%d ",ans[i].size());
for(int j=0;j<ans[i].size();j++)
printf("%d ",ans[i][j]);
printf("\n");
}
}

Codeforces Round #181 (Div. 2) A. Array 构造的更多相关文章

  1. Codeforces Round #284 (Div. 1) C. Array and Operations 二分图最大匹配

    题目链接: http://codeforces.com/problemset/problem/498/C C. Array and Operations time limit per test1 se ...

  2. Codeforces Round #535 (Div. 3) E2. Array and Segments (Hard version) 【区间更新 线段树】

    传送门:http://codeforces.com/contest/1108/problem/E2 E2. Array and Segments (Hard version) time limit p ...

  3. Codeforces Round #339 (Div. 1) C. Necklace 构造题

    C. Necklace 题目连接: http://www.codeforces.com/contest/613/problem/C Description Ivan wants to make a n ...

  4. Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力

    C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ...

  5. Codeforces Round #181 (Div. 2) B. Coach 带权并查集

    B. Coach 题目连接: http://www.codeforces.com/contest/300/problem/A Description A programming coach has n ...

  6. Codeforces Round #306 (Div. 2) ABCDE(构造)

    A. Two Substrings 题意:给一个字符串,求是否含有不重叠的子串"AB"和"BA",长度1e5. 题解:看起来很简单,但是一直错,各种考虑不周全, ...

  7. Codeforces Round #298 (Div. 2) D. Handshakes 构造

    D. Handshakes Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/problem ...

  8. Codeforces Round #276 (Div. 2)C. Bits(构造法)

    这道题直接去构造答案即可. 对于l的二进制表示,从右到左一位一位的使其变为1,当不能再变了(再变l就大于r了)时,答案就是l. 这种方法既可以保证答案大于等于l且小于等于r,也可以保证二进制表示时的1 ...

  9. Codeforces Round #181 (Div. 2)

    A. Array 模拟. B. Coach 模拟. C. Beautiful Numbers good number的位和最大不超过\(10^7\),那么只要枚举a或b的个数,然后最多循环7次判断位和 ...

随机推荐

  1. JVM参数汇总

    一.java启动参数共分为三类: 其一是标准参数(-),所有的JVM实现都必须实现这些参数的功能,而且向后兼容:其二是非标准参数(-X),默认jvm实现这些参数的功能,但是并不保证所有jvm实现都满足 ...

  2. table应用之colspan与rowspan

    <table border=" borderColorDark="#66ff33"> <tr> <td rowspan=" ali ...

  3. Android 应用启动速度优化

    现在很多的应用一开始点击的时候总会出现黑屏或者白屏,甚至前段时间微信也有同样的问题.其实白屏或者黑屏还是一些其他的东西,都是因为Android 主题的问题,只要自己自定义一个启动主题,问题完美解决. ...

  4. Visual Studio下Qt调用IDL

    一.简单介绍: 1.ActiveQt包含QAxContainer和QAxServer组件. 1) QAxContainer允许使用COM对象,并且可以将ActiveX控件嵌入到Qt程序中去. QAxC ...

  5. python代码编程规范

    一.内容格式 1.注释部分:模块名及简介(一般用一行写完),模块描述(包含各类方法),其它描述(注意点,功能,示例等,可以分多段) 2.导入模块:Import XXX 3.全局变量定义:wantobj ...

  6. 【LeetCode】231 - Power of Two

    Given an integer, write a function to determine if it is a power of two. Solution:一个整数如果是2的整数次方,那么它的 ...

  7. 谈谈final、finally和finalize

    final: final为修饰符, 如果类被声明为final,则不能派生新子类. 如果变量被声明为final,则必须在声明时初始化,在以后的引用只能读取,不可修改. 如果方法被final声明,则只能使 ...

  8. log4net--帮助程序员将日志信息输出到各种目标(控制台、文件、数据库等)的工具

    1. log4net库是Apache log4j框架在Microsoft .NET平台的实现,是一个帮助程序员将日志信息输出到各种目标(控制台.文件.数据库等)的工具. 2. Log4net的结构如下 ...

  9. jQuery Mobile 页面事件总结

    一.页面初始化事件(Page initiallization) 在页面创建前,当页面创建时,以及在页面初始化之后.只在第一次加载时执行. 1. pagebeforecreate 页面创建前 [sour ...

  10. MySQL [Warning] Can’t create test file xxx lower-test(转)

    add by zhj:修改的数据库的datadir,然后数据库就无法启动了,错误如下 2014-12-11 16:22:57 26309 [Warning] Can't create test fil ...