Is Derek lying?

DerekDerek and AlfiaAlfia are goodfriends.DerekDerek is Chinese,and AlfiaAlfia is Austrian.Thissummer holiday,they bothparticipate in the summer camp of BorussiaDortmund.During the summercamp,there will be fan tests at intervals.The testconsists of NN choice questions and each question is followed bythreechoices marked “A” “B” and “C”.Each question has only one correct answer andeachquestion is worth 11point.It means that if your answer for thisquestion is right,you canget 11point.The total score of a person is thesum of marks forall questions.When the test is over,the computer willtell DerekDerek the total score of himand AlfiaAlfia.Then AlfiaAlfia will ask DerekDerek thetotal score of her and he will tell her: “Mytotal score is XX,your totalscore is YY.”But DerekDerek is naughty,sometimes he may lie toher. Here give you theanswerthat DerekDerek and AlfiaAlfia made,you should judgewhether DerekDerekis lying.If there exists a set of standard answersatisfythe total score that DerekDerek said,you can consider he is notlying,otherwisehe is lying.

Input

The first line consists of an integer T,represents thenumberof 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 theanswer of DerekDerek for each question. 

The third line consists of N characters,thesame form as the secondline,which represents the answer of AlfiaAlfia for eachquestion. 

Data Range:1≤N≤80000,0≤X,Y≤N,∑Ti=1N≤300000

Output

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

Please print “LyingLying” if you can make sure that DerekDerek islying,otherwise please print “Not lyingNot lying”.

Sample Input

2

3 1 3

AAA

ABC

5 5 0

ABCBC

ACBCB

SampleOutput

Not lying

Lying

 

题意:

   有一道题,N个选择,X表示DerekDerek说他对的个数,Y表示AlfiaAlfia 说他对的个数。前面是DerekDerek  的答案,后面是AlfiaAlfia 的答案,问DerekDerek 说他对的个数,是不是可能的,可能输出 Not lying,不可能输出 Lying Lying。

思路:

    (用容斥原理去理解)

   主要就是在公共的答案上面,做判断。


  非常容易理解的代码如下:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;

const int mm = 8e4+100;

char a[mm], b[mm];
#define mem(a) memset(a, 0, sizeof(a))

int main()
{
    int t;
    scanf("%d",&t);
    while (t --)
    {
        mem(a), mem(b);
        int n, x, y;
        scanf("%d%d%d",&n,&x,&y);
        scanf("%s",a);
        scanf("%s",b);
        int num = 0;
        for (int i = 0; i<n; i++)
        {
            if (a[i] == b[i])   
            num ++ ;
        }
        int f = 0;
        if (x >= num && y >= num)
        {
            int x1 = x-num, y1 = y-num;
            int xx = x1+y1;
            if (xx > n-num)  f = 1; ///如果X和Y不同部分的和,大于N-num的不同部分。
        }
        else if (x >= num && y < num)
        {
            int x1 = x-y;
            if (x1 > n-num)  f = 1; ///如果X减去Y部分,大于N-num的不同部分
        }
        else if (x < num && y >= num)
        {
            int y1 = y-x;
            if (y1 > n-num)  f = 1; ///如果Y减去X部分,大于N-num的不同部分
        }
        else if (x < num && y < num)
        {
            f = 0;
        }
        if (f == 0)
            printf("Not lying\n");
        else
            printf("Lying\n");
    }
    return 0;
}

 从上面的代码进一步的推出一个缩小版的代码

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;

char a[80005],b[80005];

int main()
{
    int t;
    scanf("%d",&t);
    while (t --)
    {
        int n, x, y;
        scanf("%d%d%d",&n,&x,&y);
        scanf("%s",a);
        scanf("%s",b);
        int num = 0;
        for (int i = 0; i<n; i++)
        {
            if (a[i] != b[i])
                num ++ ;
        }
        int flag=1;
      
        if(abs(x-y) > num) flag=0;
        ///所有可能对的答案为2*N - num,num为不一样的,那么他对于XY只有对或者错
        ///不会是公共部分一样,可能全对,全错,一半对等等。
        if( x+y > 2*n-num ) flag=0;	
        if (flag == 1)
            printf("Not lying\n");
        else
            printf("Lying\n");
    }
    return 0;
}


前者代码转载:http://blog.csdn.net/joe19310/article/details/76187063

后者转载:http://www.cnblogs.com/liuzhanshan/p/7249358.html

 关键在于,你吃透了吗?

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值