首页 > 代码库 > 该死的逻辑判断之“Is Derek lying?”
该死的逻辑判断之“Is Derek lying?”
题目:
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 1 point.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 Alfia will 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:1≤N≤80000 ,0≤X,Y≤N, ∑T(i=1)(N)≤300000
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:1≤N≤80000 ,0≤X,Y≤N, ∑T(i=1)(N)≤300000
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 ”.
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
题目大意:给出3个整数分别代表“题目数”,“Derek回答正确的数量”以及“Alfia回答正确的数量“;然后给出两组只含有‘A‘,‘B‘,‘C‘三个选项的字符串代表两人的回答。问这种情况可不可能出现。
解题思路:这也是一顿神推导,排除说谎的情况。说谎只存在两种可能。
其一:两人不同的答案数量 > (两人正确数量之和或之差);(比如AAA和ABC,不同的答案数量就是2,相同的答案数量就是1);
其二:在两人正确数量和两人相同的答案数量这三个数之间取最小值,如果两人正确的数量任意一个或全部都小于这个最小值,那么就是说谎;
总结的不是很好,具体还是看代码。
AC代码:
1 import java.util.*; 2 3 public class test { 4 public static void main(String[] args) { 5 Scanner sc = new Scanner(System.in); 6 String t = sc.nextLine(); 7 int tt = Integer.valueOf(t); 8 while(tt > 0){ 9 int n = sc.nextInt(); 10 int x = sc.nextInt(); 11 int y = sc.nextInt(); 12 String enter = sc.nextLine(); 13 String aa = sc.nextLine(); 14 String bb = sc.nextLine(); 15 char a[] = aa.toCharArray(); 16 char b[] = bb.toCharArray(); 17 int same = 0;int diff = 0; 18 for(int i = 0;i < n;i ++){ 19 if(a[i] == b[i]) same++; 20 else diff ++; 21 } 22 int flag = 0; 23 int Min = Math.min(same,Math.min(x,y)); 24 x = x - Min;y = y - Min; 25 if(x < 0 || y < 0){flag = 1;} 26 if(diff < Math.abs(x-y) || diff < (x + y)){flag = 1;} 27 if(flag == 0){ 28 System.out.println("Not lying"); 29 } 30 else{System.out.println("Lying");} 31 tt --; 32 } 33 } 34 }
该死的逻辑判断之“Is Derek lying?”
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。