标签:注意 data- clip font cond absolute tput ++ ted
Polycarp is preparing the first programming contest for robots. There are nn problems in it, and a lot of robots are going to participate in it. Each robot solving the problem ii gets pipi points, and the score of each robot in the competition is calculated as the sum of pipi over all problems ii solved by it. For each problem, pipi is an integer not less than 11 .
Two corporations specializing in problem-solving robot manufacturing, "Robo-Coder Inc." and "BionicSolver Industries", are going to register two robots (one for each corporation) for participation as well. Polycarp knows the advantages and flaws of robots produced by these companies, so, for each problem, he knows precisely whether each robot will solve it during the competition. Knowing this, he can try predicting the results — or manipulating them.
For some reason (which absolutely cannot involve bribing), Polycarp wants the "Robo-Coder Inc." robot to outperform the "BionicSolver Industries" robot in the competition. Polycarp wants to set the values of pipi in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot. However, if the values of pipi will be large, it may look very suspicious — so Polycarp wants to minimize the maximum value of pipi over all problems. Can you help Polycarp to determine the minimum possible upper bound on the number of points given for solving the problems?
The first line contains one integer nn (1≤n≤1001≤n≤100 ) — the number of problems.
The second line contains nn integers r1r1 , r2r2 , ..., rnrn (0≤ri≤10≤ri≤1 ). ri=1ri=1 means that the "Robo-Coder Inc." robot will solve the ii -th problem, ri=0ri=0 means that it won‘t solve the ii -th problem.
The third line contains nn integers b1b1 , b2b2 , ..., bnbn (0≤bi≤10≤bi≤1 ). bi=1bi=1 means that the "BionicSolver Industries" robot will solve the ii -th problem, bi=0bi=0 means that it won‘t solve the ii -th problem.
If "Robo-Coder Inc." robot cannot outperform the "BionicSolver Industries" robot by any means, print one integer −1−1 .
Otherwise, print the minimum possible value of maxi=1npimaxi=1npi , if all values of pipi are set in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot.
5 1 1 1 0 0 0 1 1 1 1
3
3 0 0 0 0 0 0
-1
4 1 1 1 1 1 1 1 1
-1
9 1 0 0 0 0 0 0 0 1 0 1 1 0 1 1 1 1 0
4
思维题,我用了几个if-else判断,有点啰嗦了...
#include <bits/stdc++.h> using namespace std; int main() { int n,x=0,y=0; int a[105],b[105]; cin>>n; int i; 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++)//都会做或者都不会做的没有影响就不用统计 { if(a[i]&&(!b[i]))x++;//x为a会做的题数 else if((!a[i])&&b[i])y++; } if(x==y)//相等 { if(x)cout<<2;//不为零的话有一个取2就能保证a获胜 else cout<<-1;//都为0的话不可行 } else if(x>y)//x>y全取1就行 { cout<<1; } else//x<y { if(x==1) { cout<<y+1;//a做出来的那个题直接取y+1就能保证总分上a获胜 } else if(x==0)cout<<-1;//不可能 else { cout<<y/x+1;//可以理解为一个x能顶多少y,再加上1就能保证稳赢(注意题目要求x尽可能小,所以要y/x) } } return 0; }
Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round) A. Contest for Robots(思维题)
标签:注意 data- clip font cond absolute tput ++ ted
原文地址:https://www.cnblogs.com/lipoicyclic/p/12399226.html