A. Array
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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:

  1. The product of all numbers in the first set is less than zero ( < 0).
  2. The product of all numbers in the second set is greater than zero ( > 0).
  3. The product of all numbers in the third set is equal to zero.
  4. 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.

Examples
input
3
-1 2 0
output
1 -1
1 2
1 0
input
4
-1 -2 -3 0
output
1 -1
2 -3 -2
1 0

题意:给一组数,要求将其分为三组 每组数乘积分别<0  ==0   >0  输出每组数的个数及这些数(数据满足至少一组解)

题解第一组直接输出一个负数,第二组输出一个正数或两个负数  第三组输出剩余的全部

#include<stdio.h>
#include<string.h>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#define LL long long
#define PI atan(1.0)*4
#define DD double
#define MAX 300
#define mod 100
#define dian 1.000000011
#define INF 0x3f3f3f
using namespace std;
int s[MAX],k[MAX];
int main()
{
int n,m,j,i,t,a,b,c;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
scanf("%d",&s[i]);
int flag=0;
for(i=0;i<n;i++)
{
if(s[i]>0)
{
b=i;
flag=1;
}
}
for(i=0;i<n;i++)
{
if(s[i]<0)
{
c=i;
break;
}
}
j=0;
if(!flag)
for(i=0;i<n;i++)
{
if(i!=c)
{
if(s[i]<0)
k[j++]=s[i];
}
}
printf("1 %d\n",s[c]);
if(flag)
printf("1 %d\n",s[b]);
else
printf("2 %d %d\n",k[0],k[1]);
if(flag)
{
printf("%d ",n-2);
for(i=0;i<n;i++)
{
if(s[i]!=s[c]&&s[i]!=s[b])
printf("%d ",s[i]);
}
printf("\n");
}
else
{
printf("%d ",n-3);
for(i=0;i<n;i++)
{
if(s[i]!=s[c]&&s[i]!=k[0]&&s[i]!=k[1])
printf("%d ",s[i]);
}
printf("\n");
}
}
return 0;
}

  

codeforces300A Array的更多相关文章

  1. javascript中的Array对象 —— 数组的合并、转换、迭代、排序、堆栈

    Array 是javascript中经常用到的数据类型.javascript 的数组其他语言中数组的最大的区别是其每个数组项都可以保存任何类型的数据.本文主要讨论javascript中数组的声明.转换 ...

  2. ES5对Array增强的9个API

    为了更方便的对Array进行操作,ES5规范在Array的原型上新增了9个方法,分别是forEach.filter.map.reduce.reduceRight.some.every.indexOf ...

  3. JavaScript Array对象

    介绍Js的Array 数组对象. 目录 1. 介绍:介绍 Array 数组对象的说明.定义方式以及属性. 2. 实例方法:介绍 Array 对象的实例方法:concat.every.filter.fo ...

  4. 了解PHP中的Array数组和foreach

    1. 了解数组 PHP 中的数组实际上是一个有序映射.映射是一种把 values 关联到 keys 的类型.详细的解释可参见:PHP.net中的Array数组    . 2.例子:一般的数组 这里,我 ...

  5. 关于面试题 Array.indexof() 方法的实现及思考

    这是我在面试大公司时碰到的一个笔试题,当时自己云里雾里的胡写了一番,回头也曾思考过,最终没实现也就不了了之了. 昨天看到有网友说面试中也碰到过这个问题,我就重新思考了这个问题的实现方法. 对于想进大公 ...

  6. javascript之活灵活现的Array

    前言 就如同标题一样,这篇文章将会灵活的运行Array对象的一些方法来实现看上去较复杂的应用. 大家都知道Array实例有这四个方法:push.pop.shift.unshift.大家也都知道 pus ...

  7. 5.2 Array类型的方法汇总

    所有对象都具有toString(),toLocaleString(),valueOf()方法. 1.数组转化为字符串 toString(),toLocaleString() ,数组调用这些方法,则返回 ...

  8. OpenGL ES: Array Texture初体验

    [TOC] Array Texture这个东西的意思是,一个纹理对象,可以存储不止一张图片信息,就是说是是一个数组,每个元素都是一张图片.这样免了频繁地去切换当前需要bind的纹理,而且可以节省系统资 ...

  9. Merge Sorted Array

    Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:Yo ...

随机推荐

  1. oracle lsnrctl status|start|stop

    [oracle@redhat4 ~]$ lsnrctl status LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 06-OCT-2015 ...

  2. Android开发之MD5加密

    将字符串进行MD5加密,返回加密后的字符串 public static String encode(String password) { try { StringBuffer sb = new Str ...

  3. Redis VS Memcached

    1. Redis & Memecached比较   内存管理 持久化 数据类型 客户端支持 并发性能 Memcached 预分配的内存池的方式 不支持持久化 支持简单的key-value存储 ...

  4. poj 1067 取石子游戏( 威佐夫博奕)

    题目:http://poj.org/problem?id=1067 题意:有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的 ...

  5. bzoj2788

    明显是一个差分约束系统 对于第一种限制,其实就是x[a]+1<=x[b] x[b]-1<=x[a] 根据三角不等式很容易建图 但这题他比较奇怪,问的是X最多不同取值的个数 根据这张图的特殊 ...

  6. 关于FastDFS Java客户端源码中的一个不太明白的地方

    下面代码是package org.csource.fastdfs下TrackerGroup.java文件中靠近结束的一段代码,我下载的这个源码的版本是1.24. /** * return connec ...

  7. poj 3181 Dollar Dayz

    题意:给定一个数p,要求用K种币值分别为1,2,3...K的硬币组成p,问方案数,1,2,2和2,2,1算一种方案即与顺序无关,n <= 1000,k <= 100// 用完全背包做了 这 ...

  8. 【web】web欢迎页面执行servlet

    <!-- servlet名 --> <welcome-file-list> <welcome-file>Begin_page</welcome-file> ...

  9. Spring Bean基本管理--bean注入方式汇总

    依赖注入方式:Spring支持两种依赖注入方式,分别是属性注入和构造函数注入.还有工厂方法注入方式. 依赖注入还分为:注入依赖对象可以采用手工装配或自动装配,在实际应用开发中建议使用手工装配,因为自动 ...

  10. Selenium2Library系列 keywords 之 _SelectElementKeywords 之 get_selected_list_label(self, locator)

    def get_selected_list_label(self, locator): """Returns the visible label of the selec ...