K - Robotopia Kattis - robotopia

题目链接
题解:题目其实类似于以前的解二元一次方程组,但是如果解出方程组后,会得到一个式子,但是如果仅仅代入式子的话是错误的因为假设是这样 5X+6Y=11,5X+6Y=11,这两个方程联立的话很明显是:X=1,Y=1,所以用这种方法不对。
下面是WA10的代码:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int l1,r1,l2,r2,l3,r3;
        cin>>l1>>r1>>l2>>r2>>l3>>r3;
        int x1=r1*l3-l1*r3;
        int y1=l2*r1-l1*r2;
        int x2=r2*l3-l2*r3;
        int y2=l1*r2-l2*r1;
       if(x1==0) printf("?\n");
       else if(y1==0) printf("?\n");
        else if(x2==0) printf("?\n");
        else if(y2==0) printf("?\n");
        else if((x2/y2*y2==x2||x1/y1*y1==x1)&&x2/y2>0&&x1/y1>0) printf("%d %d\n",x2/y2,x1/y1);
        else printf("?\n");
    }
    return 0;
}

下面是AC代码:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        vector<pair<int,int> > vec;
        int l1,r1,l2,r2,l3,r3;
        cin>>l1>>r1>>l2>>r2>>l3>>r3;
        for(int i=1;i<=10000;i++)//假设有i个l1
        {
            int k=i*l1;
            int bit=(l3-k)/l2;
            if(bit*l2!=l3-k) continue;
            else
            {
                if(bit*r2+i*r1!=r3) continue;
                else
                {
                    if(bit>0) vec.push_back({i,bit});
                    else continue;
                }
            }
        }
        if(vec.size()==0||vec.size()>1) printf("?\n");
        else
        {
            printf("%d %d\n",vec[0].first,vec[0].second);
        }
    }
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值