【HDU】6045 - Is Derek lying?(思维)

本文介绍了一个用于判断Derek得分是否合理的算法实现。通过输入比赛的相同答案数、不同答案数及Derek给出的答案数量,算法能判断Derek是否撒谎。此算法使用C++编写,适用于竞赛编程中的相关问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接:点击打开题目


2017多校联合1001


求出Derek得分的最大最小值,然后比较即可。


代码如下:

#include<queue>
#include<cmath>
#include<stack>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
#define INF 0x3f3f3f3f
#define CLR(a,b) memset(a,b,sizeof(a))
#define PI acos(-1.0)
int main()
{
    int T;
    int same,dif;
    int n;
    string a,b;
    int ga,gb;
    scanf ("%d",&T);
    while (T--)
    {
        scanf ("%d %d %d",&n,&ga,&gb);
        cin >> a;
        cin >> b;
        same = dif = 0;
        for (int i = 0 ; i < a.size() ; i++)
        {
            if (a[i] == b[i])
                same++;
            else
                dif++;
        }
        int maxx;
        if (gb >= same)
            maxx = n - (gb-same);
        else
            maxx = gb + dif;
        if (gb > dif)
        {
            if (ga >= gb-dif && ga <= maxx)
                puts("Not lying");
            else
                puts("Lying");
        }
        else
        {
            if (ga >= 0 && ga <= maxx)
                puts("Not lying");
            else
                puts("Lying");
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值