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. Hanoi塔问题

    说明:河内之塔(Towers of Hanoi)是法国人M.Claus(Lucas)于1883年从泰国带至法国的,河内为越战时北越的首都,即现在的胡志明市:1883年法国数学家 Edouard Luc ...

  2. [转]Linux关机命令详解

    转自:http://www.jb51.net/os/RedHat/1334.html linux下常用的关机命令有:shutdown.halt.poweroff.init:重启命令有:reboot.下 ...

  3. python 数字和字符串转换问题

    一.python中字符串转换成数字 (1)import string tt='555' ts=string.atoi(tt) ts即为tt转换成的数字 转换为浮点数 string.atof(tt) ( ...

  4. vs2013下自动注释的运用

    1.首先是VAssistX,可以在VS的工具下,拓展和更新里面找到,然后下载安装即可: 以下为大家介绍一下怎么添加函数头注释:随便打开一个C++的工程,找到一个方法,右击函数名,然后依次点击“Refa ...

  5. Code-first示例

    首先创建一个空数据库 在vs2013中添加数据库类,按提示操作一直下一步   添加完以后,数据库类的代码 namespace mvctest.Models { using System; using ...

  6. rm 注意

    软连接ln -s lnfile file rm -rf lnfile只是删除lnfile ln -s lndir dir rm -rf lndir 删除链接 rm -rf lndir/删除目录下文件

  7. CentOS6.5修改mysql数据文件路径

    1.停止mysql服务      service mysql stop 2.移动数据文件位置(保留原文件权限)      cp -a /var/lib/mysql /mysqldata 3.修改/et ...

  8. Android 横屏时禁止输入法全屏

    在自己EditText的xml里加上属性 android:imeOptions="flagNoExtractUi"

  9. 配置IIS Express 7.5以允许外部访问

    默认配置文件位于:[我的文档]\IISExpress\config\applicationhost.config修改站点地址如:<binding protocol="http" ...

  10. c++面试题总结(2)

    1. C中static有什么作用 (1)隐藏. 当我们同时编译多个文件时,所有未加static前缀的全局变量和函数都具有全局可见性,故使用static在不同的文件中定义同名函数和同名变量,而不必担心命 ...