Is Derek lying?

来源:互联网 发布:青少年法制网络大赛 编辑:程序博客网 时间:2024/06/01 09:52

Is Derek lying?

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


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 ofN 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 1 point.The total score of a person is the sum of marks for all questions.When the test is over,the computer will tellDerek the total score of him and Alfia.ThenAlfia will ask Derek the total score of her and he will tell her: “My total score is X,your total score is Y.”ButDerek 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
23 1 3AAAABC5 5 0ABCBCACBCB
 

Sample Output
Not lyingLying
  

题意:

     两个人做N道单选题,其中一个人说自己得了X分,另一个人得了Y分,分别给出两个人的答案,判断这个人是否说谎。其中,只要有一种情况符合两人得分则判断为没有说谎。

思路:

     一开始的思路为判断两个字符串有多少个字符不一样,然后再将这个值与X-Y的绝对值比较,看是否相等,若相等则为没有说谎,不等则为说谎。后来发现这种思路并不对。两个字符串有多少字符不一样代表的是两个人有几个题答案是不一样的,而X-Y的绝对值则说明两人的比分差多少。比分差值并不一定等于答案不同数,可能有的题两个人答案不一样,但是都做错了。所以比分差值是小于等于字符不同数的,但是比分差值小于字符不同数不一定是没有撒谎。所以这种思路是不正确的。

     可以换一种想法,与其判断X,Y是否符合所给字符串,不如根据字符串及其中一人的得分,推断另一个人的得分取值范围,再看所给得分是否在这个范围内。如果在,则判断没有撒谎;如果不在,则判断为撒谎。下面以根据字符串和Y来推断X为例子,介绍X的取值范围max与min的求法。其中我们设A,B结果相同(字符相同)的题目个数为same,结果不同(字符不同)的题目个数为different。

   最大值max:

     假设所有的相同答案的题目A都做对了,不同答案的题目只要B做错了,就假设A做对了,这时X的值最大。即所有题目个数减去B做对的不同答案题目个数就为A的最大得分。

     当Y>=same时,即所有Y>=same的例子中,必有一例满足B做对了所有的相同答案题目,那么Y-same为B做对的不同答案题目个数。则max=N-(Y-same)。

     当Y<same时,此时所有Y<same的例子中,必有一例满足所有的不同答案题目B都没有答对,并且还有部分相同答案题目B没有答对。相同答案题目里,B没答对,则A也不会答对。此时就不符合所有相同题目A都做对的假设,这时候same-Y代表B做错了多少相同答案的题目,这些题目A也不会答对。所以最终结果应该是所有题目个数减去B(A)在相同题目里做错的题目个数。即max=N-(same-Y)。

     得出最终的公式为max=N-abs(Y-same)

   最小值min:

     假设所有的相同答案题目A都做错了,所有的不同答案题目不管B有没有做对假设A都做错了。此时为A的最小得分。

     当Y<=different时,则在所有Y<=different的例子中,必有一例满足B所有的相同答案题目都没做对,且有部分不同答案题目B没有做对。这时候相同答案的题目B都没有做对,则A也没有做对。又因为所有的不同答案题目A都没有做对,所以min=0

     当Y>different时,则在所有Y>different的例子中,必有一例满足B做对了所有的不同答案题目,且又做对了一部分相同答案的题目。相同答案题目里,B答对了,A也会答对。此时不满足所有相同答案A都做对的假设。这时候Y-different代表B做对了多少相同答案题目的个数,这些题目A也做对了。又因为所有的不同答案题目A都没有做对,所以最终结果等于A答对的相同题目个数,即min=Y-different

     得出最终的公式为min=Y-different  (min<0时,min=0)

下面贴上代码:

#include<iostream>#include<algorithm>#include<cmath>using namespace std;const int MAXN = 80000+10;char A[MAXN], B[MAXN];int main(){    int T;    cin>>T;    while (T--)    {        int N,X,Y;        cin>>N>>X>>Y;        cin>>A;        cin>>B;        int same=0,different=0;        for(int i=0; i<N; i++)            if(A[i]!=B[i])                different++;        same=N-different;        int max,min;        max=N-abs(Y-same);        min=Y-different;        if(min<0)            min=0;        if(X>max || X<min)            cout<<"Lying"<<endl;        else            cout<<"Not lying"<<endl;    }}