hdu 6045 Is Derek lying?

本文介绍了一个算法问题,探讨了如何判断Derek在报告考试成绩时是否对Alfia说谎。通过分析两人在多项选择题上的答案,算法能够确定Derek的说法是否可能成立,提供了一种有效的方法来验证诚实性。

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

 

           Is Derek lying?

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1197    Accepted Submission(s): 648


Problem Description
Derek and Alfia are good friends.Derek is Chinese,and Alfia is Austrian.This summer holiday,they both participate in the summer camp of Borussia Dortmund.During the summer camp,there will be fan tests at intervals.The test consists of N choice questions and each question is followed by three choices marked “A” “B” and “C”.Each question has only one correct answer and each question is worth 1 point.It means that if your answer for this question is right,you can get 1point.The total score of a person is the sum of marks for all questions.When the test is over,the computer will tell Derek the total score of him and Alfia.Then Alfiawill ask Derek the total score of her and he will tell her: “My total score is X,your total score is Y.”But Derek is naughty,sometimes he may lie to her. Here give you the answer that Derek and Alfia made,you should judge whether Derek is lying.If there exists a set of standard answer satisfy the total score that Derek said,you can consider he is not lying,otherwise he is lying.
 

 

Input
The first line consists of an integer  T,represents the number of test cases.

For each test case,there will be three lines.

The first line consists of three integers N,X,Y,the meaning is mentioned above.

The second line consists of N characters,each character is “A” “B” or “C”,which represents the answer of Derek for each question.

The third line consists of N characters,the same form as the second line,which represents the answer of Alfia for each question.

Data Range:1N80000,0X,YN,Ti=1N300000
 

 

Output
For each test case,the output will be only a line.

Please print “ Lying” if you can make sure that Derek is lying,otherwise please print “Not lying”.
 
Sample Input
2
3 1 3
AAA
ABC
5 5 0
ABCBC
ACBCB
 
Sample Output
Not lying
Lying
 
Source
 
官方题解:

首先,我们统计出Derek和Alfia答案相同的题目数量k1和答案不同的题目数量k2.

对于两人答案相同的题目,共有以下两种情况:

      a.两人都对

      b.两人都错

对于两人答案不同的题目,共有以下三种情况:

    c.Derek对Alfia错

    d.Alfia对Derek错

    e.两人都错

于是我们可以列出一些方程:k1+k2=n,a+b=k1,c+d+e=k2,a+c=x,a+d=y。又a,b,c,d,e均为非负整数,且满足a,b<=k1;c,d,e<=k2 将a,b,d,e全部用c替换后需要同时满足以下四个条件: 0<=c<=k2 x-y<=c<=k2+x-y (x-y)/2<=c<=(k2+x-y)/2 x-k1<=c<=x 我们只需要判断这四段区间存不存在公共的整数点,如果存在,则说明Derek没有说谎;如果不存在,则说明Derek在说谎。

 
/*
题意:给出n个问题,两个人的得分及其对于每道题的选择(答对一题得一分,答错不得分).
问Derek是否有可能说谎?
思路:sum记录答案相同的数目。
两种情况是说谎的:
1.二者的得分差距大于n-sum;
2.二者的得分和减去sum大于问题的总数n。
*/
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long LL;
const int N = 80000 + 100;
char d[N], a[N];
int main()
{
    int T;
    scanf("%d", &T);
    while(T--) {
        int n, x, y;
        scanf("%d%d%d", &n, &x, &y);
        scanf("%s%s", d, a);
        int sum = 0;
        for(int i = 0; i < n; i++) {
            if(d[i] == a[i])
                sum++;
        }
        if(abs(x - y) > n - sum || (x + y - sum) > n)
            printf("Lying\n");
        else
            printf("Not lying\n");
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/yu0111/p/7266932.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值