A. Be Positive

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given an array of nn integers: a1,a2,…,ana1,a2,…,an. Your task is to find some non-zero integer dd (−103≤d≤103−103≤d≤103) such that, after each number in the array is divided by dd, the number of positive numbers that are presented in the array is greater than or equal to half of the array size (i.e., at least ⌈n2⌉⌈n2⌉). Note that those positive numbers do not need to be an integer (e.g., a 2.52.5 counts as a positive number). If there are multiple values of dd that satisfy the condition, you may print any of them. In case that there is no such dd, print a single integer 00.

Recall that ⌈x⌉⌈x⌉ represents the smallest integer that is not less than xx and that zero (00) is neither positive nor negative.

Input

The first line contains one integer nn (1≤n≤1001≤n≤100) — the number of elements in the array.

The second line contains nn space-separated integers a1,a2,…,ana1,a2,…,an (−103≤ai≤103−103≤ai≤103).

Output

Print one integer dd (−103≤d≤103−103≤d≤103 and d≠0d≠0) that satisfies the given condition. If there are multiple values of dd that satisfy the condition, you may print any of them. In case that there is no such dd, print a single integer 00.

Examples

input

5
10 0 -7 2 6

output

4

input

7
0 0 1 -1 0 0 2

output

0

Note

In the first sample, n=5n=5, so we need at least ⌈52⌉=3⌈52⌉=3 positive numbers after division. If d=4d=4, the array after division is [2.5,0,−1.75,0.5,1.5][2.5,0,−1.75,0.5,1.5], in which there are 33 positive numbers (namely: 2.52.5, 0.50.5, and 1.51.5).

In the second sample, there is no valid dd, so 00 should be printed.

题解:计算出正数和负数的个数,如果正数大于(n+1)/2的话,就是随便输出一个正数,如果负数大于(n+1)/2的话,就随便输出一个负数,否则输出0.

#include<iostream>
#include<cstdio> using namespace std; int main()
{
int n,a[],cnt=,cnt2=;
cin>>n;
for(int i=;i<n;i++)
{
scanf("%d",a+i);
if(a[i]>) //找出正数的个数
cnt++;
else if(a[i]<) //找出负数的个数
cnt2++; }
if(cnt>=(n+)/)
printf("1\n");
else if(cnt2>=(n+)/)
printf("-1\n");
else
printf("0\n");
return ;
}

A. Be Positive的更多相关文章

  1. [LeetCode] First Missing Positive 首个缺失的正数

    Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0]  ...

  2. Leetcode First Missing Positive

    Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0]  ...

  3. Interleaving Positive and Negative Numbers

    Given an array with positive and negative integers. Re-range it to interleaving with positive and ne ...

  4. 【leetcode】First Missing Positive

    First Missing Positive Given an unsorted integer array, find the first missing positive integer. For ...

  5. 【leetcode】First Missing Positive(hard) ☆

    Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0]  ...

  6. LeetCode - 41. First Missing Positive

    41. First Missing Positive Problem's Link ---------------------------------------------------------- ...

  7. LeetCode题解-----First Missing Positive

    Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0]  ...

  8. hdu 5183. Negative and Positive (哈希表)

    Negative and Positive (NP) Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...

  9. Java for LeetCode 041 First Missing Positive

    Given an unsorted integer array, find the first missing positive integer. For example, Given [1,2,0] ...

  10. [LintCode] Interleaving Positive and Negative Numbers

    Given an array with positive and negative integers. Re-range it to interleaving with positive and ne ...

随机推荐

  1. spark教程(四)-SparkContext 和 RDD 算子

    SparkContext SparkContext 是在 spark 库中定义的一个类,作为 spark 库的入口点: 它表示连接到 spark,在进行 spark 操作之前必须先创建一个 Spark ...

  2. go语言坑之并发访问map

    fatal error: concurrent map read and map write 并发访问map是不安全的,会出现未定义行为,导致程序退出.所以如果希望在多协程中并发访问map,必须提供某 ...

  3. Dasha and Photos CodeForces - 761F (前缀优化)

    大意: 给定n*m初始字符矩阵, 有k个新矩阵, 第$i$个矩阵是由初始矩阵区间赋值得到的, 求选择一个新矩阵, 使得其余新矩阵到它距离和最小. 字符集比较小, 可以考虑每次区间覆盖对每个字符的贡献. ...

  4. 什么是 Serverless 应用引擎?优势有哪些?

    Serverless 应用引擎(Serverless App Engine,简称 SAE)是面向应用的 Serverless PaaS 平台,能够帮助 PaaS 层用户免运维 IaaS,按需使用,按量 ...

  5. webAapi

    学习目标: 掌握API和Web API的概念 掌握常见浏览器提供的API的调用方式 能通过Web API开发常见的页面交互功能 能够利用搜索引擎解决问题 typora-copy-images-to: ...

  6. CentOS下安装DockerCE

    title: CentOS下安装DockerCE comments: false date: 2019-09-04 09:47:58 description: 在CentOS下安装社区版Docker ...

  7. NLP采用Bert进行简单文本情感分类

    参照当Bert遇上Kerashttps://spaces.ac.cn/archives/6736此示例准确率达到95.5%+ https://github.com/CyberZHG/keras-ber ...

  8. Nginx的快速安装

    1. 准备工作 1. CenterOS7.x.vmware虚拟机,安装过程参考 https://jingyan.baidu.com/article/eae0782787b4c01fec548535.h ...

  9. ubuntu终端安装最新ss

    有时候因为加密方式比较新,比如aes-256-gcm,导致旧版本的不能用 一句命令安装ss最新版本 aes-256-gcm加密方式可以用,没毛病

  10. Spring Boot整合dubbo(注解的方式)

    一.创建项目 1.创建一个空的项目 2.在空的项目中添加两个Spring Boot模块,如下图所示 二.在provider模块中的pom文件中添加依赖 <dependency> <g ...