codeforces300A Array
2 seconds
256 megabytes
standard input
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:
- 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.
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.
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.
3
-1 2 0
1 -1
1 2
1 0
4
-1 -2 -3 0
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的更多相关文章
- javascript中的Array对象 —— 数组的合并、转换、迭代、排序、堆栈
Array 是javascript中经常用到的数据类型.javascript 的数组其他语言中数组的最大的区别是其每个数组项都可以保存任何类型的数据.本文主要讨论javascript中数组的声明.转换 ...
- ES5对Array增强的9个API
为了更方便的对Array进行操作,ES5规范在Array的原型上新增了9个方法,分别是forEach.filter.map.reduce.reduceRight.some.every.indexOf ...
- JavaScript Array对象
介绍Js的Array 数组对象. 目录 1. 介绍:介绍 Array 数组对象的说明.定义方式以及属性. 2. 实例方法:介绍 Array 对象的实例方法:concat.every.filter.fo ...
- 了解PHP中的Array数组和foreach
1. 了解数组 PHP 中的数组实际上是一个有序映射.映射是一种把 values 关联到 keys 的类型.详细的解释可参见:PHP.net中的Array数组 . 2.例子:一般的数组 这里,我 ...
- 关于面试题 Array.indexof() 方法的实现及思考
这是我在面试大公司时碰到的一个笔试题,当时自己云里雾里的胡写了一番,回头也曾思考过,最终没实现也就不了了之了. 昨天看到有网友说面试中也碰到过这个问题,我就重新思考了这个问题的实现方法. 对于想进大公 ...
- javascript之活灵活现的Array
前言 就如同标题一样,这篇文章将会灵活的运行Array对象的一些方法来实现看上去较复杂的应用. 大家都知道Array实例有这四个方法:push.pop.shift.unshift.大家也都知道 pus ...
- 5.2 Array类型的方法汇总
所有对象都具有toString(),toLocaleString(),valueOf()方法. 1.数组转化为字符串 toString(),toLocaleString() ,数组调用这些方法,则返回 ...
- OpenGL ES: Array Texture初体验
[TOC] Array Texture这个东西的意思是,一个纹理对象,可以存储不止一张图片信息,就是说是是一个数组,每个元素都是一张图片.这样免了频繁地去切换当前需要bind的纹理,而且可以节省系统资 ...
- Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:Yo ...
随机推荐
- hdu 4952 Number Transformation (找规律)
题目链接 题意:给你个x,k次操作,对于第i次操作是:要找个nx,使得nx是>=x的最小值,且能整除i,求k次操作后的数 分析: 经过打表找规律,会发现最后的x/i,这个倍数会趋于一个固定的值, ...
- Go Deeper(2010成都现场赛题)(2-sat)
G - Go Deeper Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description ...
- pfx 转 snk
最近用 fody 加在c#工程内,但是签名只认snk ,好像是mono cecil的问题,都不认pfx,重新生成snk文件,publishkey又要变了, 底层dll引用的地方太多,要改好多cspro ...
- iOS开发:记录开发中遇到的编译或运行异常以及解决方案
1.部署到真机异常 dyld`dyld_fatal_error: -> 0x120015088 <+0>: brk #0x3 dyld: Library not loaded ...
- SJ9012: IE6 IE7 不支持 JSON 对象
标准参考 JSON 是一种数据交换格式,RFC 4627 对 JSON 进行了详细描述. 根据 ECMA-262(ECMAScript)第 5 版中描述,JSON 是一个包含了函数 parse 和 s ...
- Android异常之 unable to write jarlist cache file
异常: android开发调试时候不能运行,出现 unable to write jarlist cache file 错误. 解决方法: 1.找到appcompt文件夹如下的位置.
- cocos2dx场景切换中init、onEnter、onEnterTransitionDidFinish的调用顺序
这些方法调用的先后顺序如下(使用 replaceScene 方法): 1. 第2个场景的 scene 方法 2. 第2个场景的 init 方法 3. 第2个场景的 onEnter 方法 4. 转场 5 ...
- 动态加载so文件
在开发过程中,经常会用到第三方库,比如地图.视频.文档编辑.图表之类.依赖这些库,需要添加其SDK,有时需要用到jni层的So文件,比如百度地图等. 那么问题来了,如果两个不同的库之间的so文件发生冲 ...
- border-radius 在安卓手机竟然不完美支持
如果给图片加了width:50px;height:50px;border-radius:25px;-webkit-border-radius:25px;border:3px solid #fff; 在 ...
- util-判断当前年份所处的季度,并返回当前季度开始的月份
ylbtech-funcation-util: 判断当前年份所处的季度,并返回当前季度开始的月份 判断当前年份所处的季度,并返回当前季度开始的月份. 1.A,Ylbtech.Model返回顶部 us ...