CodeForces 300A Array
http://codeforces.com/problemset/problem/300/A
题意 :给你n个数字,让你分成3组,第一组各个数之积要小于0,第二组要大于0,第三组要等于0,符合要求的答案可能会有很多种,输出其中一种。
思路 :表示一开始以为要把n个数分成3组,第一组里的数都大于0这样子,所以一直卡在这儿。。。。因为这个题也相当于special judge了吧,所以要找一个最不容易出错的输出,把n个数排序,最小的肯定是负的(题目保证至少有一个正确答案),所以直接把它分在第一组就行,然后如果然后最大的数分在第二组,当然了,如果最大的数也不大于0,这时候就要把第二个第三个放在一起,这样乘积就是正数了,而剩下的因为包含一个0,所以就直接弄一组去就行了
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std ;
int main()
{
int n ;
while(scanf("%d",&n)!=EOF)
{
int a[] ;
for(int i = ; i < n ; i++)
scanf("%d",&a[i]) ;
sort(a,a+n) ;
printf("1 %d\n",a[]) ;
if(a[n-] > )
{
printf("1 %d\n",a[n-]);
printf("%d",n-) ;
for(int i = ; i < n- ; i++)
printf(" %d",a[i]) ;
}
else
{
printf("2 %d %d\n",a[],a[]) ;
printf("%d",n-) ;
for(int i = ; i < n ; i++)
printf(" %d",a[i]) ;
}
printf("\n") ;
}
return ;
}
CodeForces 300A Array的更多相关文章
- Codeforces 797E - Array Queries
E. Array Queries 题目链接:http://codeforces.com/problemset/problem/797/E time limit per test 2 seconds m ...
- Codeforces 1108E2 Array and Segments (Hard version) 差分, 暴力
Codeforces 1108E2 E2. Array and Segments (Hard version) Description: The only difference between eas ...
- 网络流(最大流):CodeForces 499E Array and Operations
You have written on a piece of paper an array of n positive integers a[1], a[2], ..., a[n] and m goo ...
- Codeforces 1108E2 Array and Segments (Hard version)(差分+思维)
题目链接:Array and Segments (Hard version) 题意:给定一个长度为n的序列,m个区间,从m个区间内选择一些区间内的数都减一,使得整个序列的最大值减最小值最大. 题解:利 ...
- Codeforces 623B Array GCD
Array GCD 最后的序列里肯定有a[1], a[1]-1, a[1]+1, a[n], a[n]-1, a[n]+1中的一个,枚举质因子, dp去check #include<bits/s ...
- CodeForces 57C Array 组合计数+逆元
题目链接: http://codeforces.com/problemset/problem/57/C 题意: 给你一个数n,表示有n个数的序列,每个数范围为[1,n],叫你求所有非降和非升序列的个数 ...
- codeforces A. Array 解题报告
题目链接:http://codeforces.com/problemset/problem/300/A 题目意思:给出n个数,将它们分成三批:1.所有数相乘的结果 < 0 2.所有数相乘的 ...
- CodeForces - 1175D Array Splitting(数组划分+后缀和+贪心)
You are given an array a1,a2,…,ana1,a2,…,an and an integer kk. You are asked to divide this array in ...
- codeforces#1108E2. Array and Segments (线段树+扫描线)
题目链接: http://codeforces.com/contest/1108/problem/E2 题意: 给出$n$个数和$m$个操作 每个操作是下标为$l$到$r$的数减一 选出某些操作,使$ ...
随机推荐
- Ant 命令总结
1 Ant是什么? Apache Ant 是一个基于 Java的生成工具.生成工具在软件开发中用来将源代码和其他输入文件转换为可执行文件的形式(也有可能转换为可安装的产品映像形式).随着应用程序的生成 ...
- Swift项目开发实战-基于分层架构的多版本iPhone计算器-直播公开课
Swift项目开发实战-基于分层架构的多版本iPhone计算器-直播公开课 本课程采用Q Q群直播方式进行直播,价值99元视频课程免费直播.完整的基于Swift项目实战,手把手教你做一个Swift版i ...
- Hibernate 拥有 Mybits 的SQL/HQL特性 (注解、XML两不误)
第一次写博客.文章有点渣,喜欢就看看,不喜欢路过点个赞. 效果:直接一条语句多种用法 FROM User A WHERE 1=1 <#if id??&g ...
- hibernate的运行流程
首先了解什么是对象关系映射,ORM(Object/Relationship Mapping):对象关系映射.对象关系映射是一种为了解决面向对象与关系数据库存在的互不匹配的现象的技术.是通过使用描述对象 ...
- Poj 3117 World Cup
1.Link: http://poj.org/problem?id=3117 2.Content: World Cup Time Limit: 1000MS Memory Limit: 65536 ...
- DTCMS,手机网站访问跳转到DTCMS官网解决方法
mobile\js\base.js main\js\common.js 去掉location.href = 'http://m.dtcms.net'; 也可以设定手机访问跳转到指定域名
- angularJs--$apply和$watch,$digest方法的意思
这个视图对应的控制器是 这样的话,这个date变量,是不会发生改变的,没有触发脏检查,所以这时候要$apply方法,所有自定义的方法都要用$apply来触发脏检查 这样那个日期就会变化了 $diges ...
- php 字母大小写转换的函数
分享下,在php编程中,将字母大小写进行转换的常用函数. 1.将字符串转换成小写strtolower(): 该函数将传入的字符串参数所有的字符都转换成小写,并以小定形式放回这个字符串 2.将字符转成大 ...
- php语法检查方法——命令行模式和代码形式
1. 命令行形式 php -l /path/to/file.php 2. php代码形式 function php_syntax_check($file){ $code = file_get_cont ...
- PHP加解密相关函数
openssl_public_encrypt() - Encrypts data with public keyopenssl_public_decrypt() - Decrypts data w ...