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. 12、NFC技术:读写NFC标签中的Uri数据

    功能实现,如下代码所示: 读写NFC标签的Uri 主Activity import cn.read.write.uri.library.UriRecord; import android.app.Ac ...

  2. 成功BOSS的六大秘诀

    1.信念力 一个没有坚定信念的人,是不可能成为伟大企业家的.如果你认为自己行,你就一定行:如果你都认为自己不行了,那你就注定不行.在成功这条道路上,要勇敢地自我肯定和鼓励,这样才能带来巨大的创造力并最 ...

  3. Jersey搭建Restful服务器 on Ubuntu

    自己试着在Ubuntu上搭建一个 1.首先安装eclipse和tomcat sudo apt-get install eclipse tomcat7 -y 2.把tomcat的group assign ...

  4. FlatBuffers要点

    FlatBuffers发布出来一周多,周末便抽时间先研究下它的使用方法.Flatbuffers的idl的语法主要参考[http://google.github.io/flatbuffers/md__s ...

  5. [转]天龙八部的BillingServer

    从字面上看,Billing是计费的,应该处理玩家在线时间或者包月之类.但是天龙八部是免费游戏,不需要算时间来计费.从代码中看,BillingServer也比较简单,它有一个连接到Web服务器,并监听一 ...

  6. Eclipse配置信息

    1.Eclipse VM arguments的保存位置: .metadata\.plugins\org.eclipse.debug.core\.launches (使用文件比较工具找出配置信息的保存位 ...

  7. 用python产生一个好的秘钥

    import os os.urandom(24)

  8. 解决SQL Server Always 日志增大的问题-摘自网络

    配置了Alwayson之后,因为没有只能使用完全恢复模式,不能使用简单或大容量日志模式,所以日志不断增长,不能使用改变恢复模式的方式清空日志 手动操作收缩或截断日志也无效 读了一些文章后发现,有人使用 ...

  9. python oop __slots__方法

    动态语言python 可以在程序运行的情况下给class加上功能.具体为 #引入一个 from types import MethodType #方法 #然后 s.set_age = MethodTy ...

  10. 移动端rem布局

    手机页面——分辨率特别乱: 1.定宽320px——优点:简单,缺点:不能适应 2.百分比——优点:能适应各种分辨率,缺点:太麻烦 3.rem——优点:方便.适应各种分辨率(首先定义一个“根大小”htm ...