链接:https://codeforces.com/contest/1130/problem/A

题意:

给n个数,找出一个非0整数d,使所有n个数除以整数d后,数组中正数的数量>= n/2。

如果不存在d,输出0。

思路:

记录正数和负数的数量,只有有一个满足就输出1或-1,否则为0。

代码:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

int main()
{
int n, a;
cin >> n;
int z = 0, f = 0, o = 0;
for (int i = 1;i <= n;i++)
{
cin >> a;
if (a > 0)
z++;
else if (a < 0)
f++;
else
o++;
}
if (z >= f && z >= (n + 1) / 2)
cout << 1 << endl;
else if (f >= z && f >= (n + 1) / 2)
cout << -1 << endl;
else
cout << 0 << endl; return 0;
}

  

Codeforces Round #542(Div. 2) A.Be Positive的更多相关文章

  1. Codeforces Round 542 (Div. 2)

    layout: post title: Codeforces Round 542 (Div. 2) author: "luowentaoaa" catalog: true tags ...

  2. Codeforces Round #236 (Div. 2)E. Strictly Positive Matrix(402E)

    E. Strictly Positive Matrix   You have matrix a of size n × n. Let's number the rows of the matrix f ...

  3. Codeforces Round #542(Div. 2) CDE 思维场

    C https://codeforces.com/contest/1130/problem/C 题意 给你一个\(n*m\)(n,m<=50)的矩阵,每个格子代表海或者陆地,给出在陆地上的起点终 ...

  4. Codeforces Round #542(Div. 2) B.Two Cakes

    链接:https://codeforces.com/contest/1130/problem/B 题意: 给定n和 2 * n个数,表示i位置卖ai层蛋糕, 有两个人在1号,必须严格按照1-n的顺序买 ...

  5. Codeforces Round #542(Div. 2) D1.Toy Train

    链接:https://codeforces.com/contest/1130/problem/D1 题意: 给n个车站练成圈,给m个糖果,在车站上,要被运往某个位置,每到一个车站只能装一个糖果. 求从 ...

  6. Codeforces Round #542(Div. 2) C.Connect

    链接:https://codeforces.com/contest/1130/problem/C 题意: 给一个n*n的图,0表示地面,1表示水,给出起点和终点, 现要从起点到达终点,有一次在两个坐标 ...

  7. Codeforces Round #542 (Div. 1) 题解

    开学了住校了打不了深夜场 好难受啊QwQ A 显然对于每个起点,我们只需要贪心记录这个起点出发出去的糖果数量以及离自己最近的糖果 因为这个起点最后一次装载糖果一定是装载终点离自己最近的那个糖果 $ O ...

  8. Codeforces Round #542 Div. 1

    A:显然对于起点相同的糖果,应该按终点距离从大到小运.排个序对每个起点取max即可.读题花了一年还wa一发,自闭了. #include<iostream> #include<cstd ...

  9. Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) 题解

    Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) 题目链接:https://codeforces.com/contest/1130 ...

随机推荐

  1. SCOI2017 游记(AFO)

    SCOI2017 游记(AFO) Day 0 上午模拟考,又tm用暴力a了一道题,心情舒畅.(要是省选也这样该有多好,2333) 晚上又去吃了什么不知名的东西,自己都忘了,总之好像很好吃的样子. Da ...

  2. 激活win10企业长期服务版

    win10 2016 长期服务版的ISO文件中本身就带有KMS激活KEY,不用输入任何KEY,连接网络进入CMD,只要输入:slmgr /skms kms.digiboy.irslmgr /ato这两 ...

  3. -webkit-mask-box-image给框架加个同样大小的遮罩

    很棒的css属性,可以在div上方建个同大小的遮罩,配合线性变化gradient可以实现很酷的样式,比如:时间选择的UI组件,里面有个模糊的上方遮罩 手册地址:https://developer.mo ...

  4. 关于git上传文件的一个小问题

    *** Please tell me who you are. Run git config --global user.email "you@example.com" git c ...

  5. ACM2016级新生第三周训练赛

    本次是弱校题解-比赛链接 备用链接 题目还是比较基础,比较简单.认真补题,学会学习. A -人见人爱A^B 题解: 求 A的B次方,我们可以用循环进行累乘操作,进而计算出次方.因为题目要求只需要求出最 ...

  6. hdu-5673 Robot(默次金数)

    题目链接: Robot Time Limit: 12000/6000 MS (Java/Others)  Memory Limit: 65536/65536 K (Java/Others) 问题描述 ...

  7. Python: PS 滤镜--水波特效

    本文用 Python 实现 PS 滤镜中的 水波特效 import numpy as np from skimage import img_as_float import matplotlib.pyp ...

  8. 【linux】lsof命令和{Linux下文件删除、句柄与空间释放问题}

      导读: 一.用事实说话 二.关于LSOF命令的其它用法: 三.参考文档:   正文: lsof:Finding open files with lsof 作用:查看文件被哪些进程打开 一.用事实说 ...

  9. CodeForces669E:Little Artem and Time Machine(CDQ分治)(或者用map+树状数组优美地解决)

    Little Artem has invented a time machine! He could go anywhere in time, but all his thoughts of cour ...

  10. MongoDB搭建ReplSet复制集群

    MongoDB的复制集是一个主从复制模式 又具有故障转移的集群,任何成员都有可能是master,当master挂掉用会很快的重新选举一个节点来充当master. 复制集中的组成主要成员 Primary ...