codeforses Contest for Robots 1321A

A. Contest for Robots
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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?

Input
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.

Output
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.

Examples
inputCopy
5
1 1 1 0 0
0 1 1 1 1
outputCopy
3
inputCopy
3
0 0 0
0 0 0
outputCopy
-1
inputCopy
4
1 1 1 1
1 1 1 1
outputCopy
-1
inputCopy
9
1 0 0 0 0 0 0 0 1
0 1 1 0 1 1 1 1 0
outputCopy
4
Note
In the first example, one of the valid score assignments is p=[3,1,3,1,1]p=[3,1,3,1,1]. Then the “Robo-Coder” gets 77 points, the “BionicSolver” — 66 points.

In the second example, both robots get 00 points, and the score distribution does not matter.

In the third example, both robots solve all problems, so their points are equal.
题意:n道题,两个人写,你知道两个人分别哪些题会写哪些题不会写,你要做的是给每道题设定分值(不低于1)来确保能让r赢,如果r怎么着都赢不了,输出-1,否则输出所有你设定的分值中的最大值,这个最大值是能满足r赢的最小值,也就是说不能瞎胡设分值,得让r以小比分胜出
思路:一共就四种情况,rb都会,都不会,r会b不会,b会r不会,其中都会和都不会相当于没用,拉不开差距,为了让r赢,我们把r不会b会的题全都设成1分,然后再让r一点点赢
下面是代码

#include<iostream>
#include<algorithm>
using namespace std;
int n;
int r[100007];
int b[100007];
bool check()
{
    int flag=0;
    for(int i=0;i<n;i++)
        if(r[i]==1&&b[i]==0)
            flag=1;//如果有题r会b不会
    if(flag==1)
        return false;
    else
        return true;//r没救了
}
//定义每一道题的分值使得r能赢,输出你定义的最大的分值
//定义最大的分值应该在能选的范围内选最小的
//思路:
//如果同一道题b会r不会,分值定为1
//如果同一道题br都不会,分值定为1,不影响最大值
//只要有一道题r会b不会,就能让r赢,所以只要r会的题b都会,就输出-1
//共四种情况 r会b不会() rb都会() rb都不会() r不会b会()
int main()
{
//    int n;
    int sum_r=0,sum_b=0,D_value,num=0,ans;
//    int r[100007];
//    int b[100007];
    int score[100007];
    cin>>n;
    for(int i=0;i<n;i++) cin>>r[i];
    for(int i=0;i<n;i++) cin>>b[i];
    while(check())
    {
        cout<<-1<<endl;
        return 0;
    }
    for(int i=0;i<n;i++)
    {
        if(b[i]==1&&r[i]==0)//b会r不会
        {
            score[i]=1;
            sum_b+=score[i];
        }
        if(b[i]==0&&r[i]==1)
            num++;//num为题数,也可以当做初始num分
    }//只剩下r会b不会的情况了,之后肯定b分高
    D_value=sum_b-sum_r;
    ans=num;
    if(num>D_value)
    {
        cout<<1<<endl;
        return 0;
    }
    while(ans<=D_value)
    {
        ans++;
    }
    ans=(int)ans/num;//D_value=1 num=99
    if(ans%num==0) cout<<ans<<endl;
    else      cout<<ans+1<<endl;

    return 0;
}

感谢观看!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值