A : Be Positive 题目地址:https://codeforces.com/problemset/problem/1130/A

题解:让你求是否满足一个d使得数列长为n的a数组的每个数除以d以后,所得数列正数的数量大于ceil(n);(除以后四舍五入,0不是正数)

注意d为负数的情况

参考代码:

 1 #include<iostream>
 2 using namespace std;
 3 int main()
 4 {
 5     int x=0,y=0;
 6     int t,a[105];
 7     cin>>t;
 8     for(int i=0;i<t;i++)
 9     {
10         scanf("%d",&a[i]);
11         if(a[i]>0) x++;
12         if(a[i]<0) y++;
13     }
14     
15     if(2*x>=t) cout<<1<<endl;
16     else if(y*2>=t) cout<<-1<<endl;
17     else cout<<0<<endl;
18     return 0;
19 } 
View Code

相关文章:

  • 2021-06-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-05
  • 2022-03-09
  • 2022-12-23
  • 2021-11-05
  • 2022-12-23
  • 2021-07-18
相关资源
相似解决方案