acm Array
来源:互联网 发布:jquery ajax json解析 编辑:程序博客网 时间:2024/06/18 08:33
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 -11 21 0
4-1 -2 -3 0
1 -12 -3 -2
思考:一定存在解决方案,则必有0和至少一个负数且不同整数//最简单的,第一列只有一个负数,第二列最多两个,其余归到第三列//可以没有正数,必须有负数//= =哪里用栈和队列啊?
#include<stdio.h>#include<algorithm>using namespace std;bool cmp(int a,int b){return a>b;}int a[100],b[100],c[100];int main(){int n,i,m[100];while(scanf("%d",&n)!=EOF){int l=0,s=0;for(i=0;i<n;i++){scanf("%d",&m[i]);if(m[i]<0){a[i]=m[i];l++;}else if(m[i]>0) { b[i]=m[i]; s++;}}sort(a,a+n);sort(b,b+n,cmp);int q=0,w=0;if(l>2)q=s+2;else//l=1,2 q=s;w=1; printf("%d ",1); printf("%d\n",a[0]); if(l>2) { printf("%d ",q); for(i=1;i<3;i++) printf("%d ",a[i]); if(s>0) { for(i=0;i<s-1;i++) printf("%d ",b[i]); printf("%d",b[s-1]);} printf("\n");printf("%d ",n-q-w); for(i=3;i<l;i++) printf("%d ",a[i]); printf("0\n"); }else//l<2 { printf("%d ",q);for(i=0;i<s-1;i++) printf("%d ",b[i]); printf("%d\n",b[s-1]); printf("%d ",n-q-w); if(l==2) printf("%d ",a[1]); printf("0\n");}}return 0;}
- acm Array
- ACM-水题 Beauty of Array
- 2017 ACM/ICPC Asia Regional Shenyang Online//array array array
- ACM UVA 11536 Smallest Sub-Array
- 2017 ACM/ICPC Asia Regional Shenyang Online 1004 & hdu6197:array array array
- 2017 ACM/ICPC Asia Regional Shenyang Online 1004 array array array
- HDU-2017 ACM/ICPC Asia Regional Shenyang Online-1004-array array array
- array array array-- 2017 ACM/ICPC Asia Regional Shenyang Online
- 【2017 ACM/ICPC Asia Regional Shenyang Online 1004】hdu 6197 array array array
- 2017 ACM/ICPC Asia Regional Shenyang Online 1004 array array array
- hdu 2441-ACM(Array Complicated Manipulation)(数学)
- F--Almost Sorted Array(2015-ACM-ICPC长春站)
- “玲珑杯”ACM比赛 Round #4 E -- array(dp)
- 玲珑杯”ACM比赛 Round #4 E -- array【DP】
- 2017 ACM/ICPC Asia Regional Shenyang Online array
- array array array (2017 ACM/ICPC Asia Regional Shenyang Online 1004)简单DP,最长公共子序列(Ologn)
- array
- Array#-
- hpu暑期训练:E
- ant的安装和环境配置
- this关键字
- 【bzoj3280】小R的烦恼
- Realm数据库的简单使用
- acm Array
- qt creator 切换到界面语言(切换到英语)
- Java 并发专题 :闭锁 CountDownLatch
- HDU 2017 多校联赛 1011 KazaQ's Socks
- 计算整型数组中的最大值
- Javascript学习小结(1)
- 在windows 7下安装unbuntu16.04 虚拟机进行tensorflow 的编译安装。
- JavaScript中的运算符和表达式
- UVA