CodeForces 300A Array
2016-06-06 18:24
639 查看
CodeForces
300A Array
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d
& %I64u
Submit Status
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
Input
Output
Input
Output
300A Array
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d
& %I64u
Submit Status
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
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
AC代码:
#include<cstdio> #include<algorithm> using namespace std; int main() { int n; int a[110]; while(scanf("%d",&n)!=EOF) { for(int i=1;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+n+1); int k; for(int i=1;i<=n;i++) if(a[i]==0) { k=i; break; } if((k-1)%2!=0) { printf("1 %d\n",a[k-1]); printf("%d",n-2); for(int i 4000 =1;i<=k-2;i++) printf(" %d",a[i]); if(k!=n) { for(int j=k+1;j<n;j++) printf(" %d",a[j]); printf(" %d\n",a ); } else printf("\n"); printf("1 0\n"); } else { printf("1 %d\n",a[k-1]); printf("%d",n-3); for(int i=1;i<=k-3;i++) printf(" %d",a[i]); if(k!=n) { for(int j=k+1;j<n;j++) printf(" %d",a[j]); printf(" %d\n",a ); } else printf("\n"); printf("2 0 %d\n",a[k-2]); } } return 0; }
相关文章推荐
- JedisRedirectionException:Too many Cluster redirections
- ctags简易用法
- wifi协议-802
- RandomAccess接口
- 第二阶段冲刺第七天,6月6日。
- 第二阶段冲刺6(6月5号)
- 在PPT中插入网页技巧
- Android蓝牙与全站仪蓝牙仪器数据交互
- 安卓让自己的应用处在栈顶
- Android_Service(基础篇)
- 改版一位同学的刮刮卡效果源码
- 模仿password输入框
- document.getElementById("xx").style.xxx中的所有属性
- [整体二分 树状数组套线段树] BZOJ 2674 Attack
- bitmap的几个用法
- 『Python学习』MySQL学习
- 第二阶段冲刺第六天,6月5日。
- 获取当前应用信息
- 通过 SysVinit、Systemd 和 Upstart 管理系统自启动进程和服务
- JAVA随机:当前年月日时分秒+五位随机数