Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round) 比赛人数5638
[codeforces 1321A] Contest for Robots 题目有些长
总目录详见https://blog.csdn.net/mrcrack/article/details/103564004
在线测评地址https://codeforces.ml/contest/1321/problem/A
Problem | Lang | Verdict | Time | Memory |
---|---|---|---|---|
A - Contest for Robots | GNU C++11 | Accepted | 31 ms | 0 KB |
比赛时,有些震撼,作为第一题,题目有些长。比赛开始阶段,还在处理一些业务,耽搁了15分钟,不过,对自己还是有充分的信心,后面的题,总是能做些出来,这还是要归功于这段时间codeforces的比赛,场场不落,铸就的信心。
题虽然长,但该题的核心体现在此句
Polycarp wants to set the values of pi in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot.
手工算法如下
BionicSolver Industries能处理的值都设置为1
Robo-Coder Inc.能处理的值之和只要比 BionicSolver Industries能处理的值之和 多1即可。
Input1:
5
1 1 1 0 0
0 1 1 1 1
Output1:
3
1 1 1 0 0
0 1 1 1 1
取值 3 1 1
Input4:
9
1 0 0 0 0 0 0 0 1
0 1 1 0 1 1 1 1 0
Output4:
4
1 0 0 0 0 0 0 0 1
0 1 1 0 1 1 1 1 0
取值 4 1 1 1 1 1 1 3
AC代码如下
#include <stdio.h>
#define maxn 105
int a[maxn],b[maxn];
int main(){
int n,i,cnt1=0,cnt2=0;//>0 cnt1;<0 cnt2
scanf("%d",&n);
for(i=1;i<=n;i++)scanf("%d",&a[i]);
for(i=1;i<=n;i++)scanf("%d",&b[i]);
for(i=1;i<=n;i++)a[i]-=b[i];
for(i=1;i<=n;i++)
if(a[i]>0)cnt1++;
else if(a[i]<0)cnt2++;
if(cnt1==0)printf("-1\n");
else printf("%d\n",cnt2/cnt1+1);
return 0;
}