该死的逻辑判断之“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

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

题目大意:给出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 }
时间: 2024-10-14 03:16:43

该死的逻辑判断之“Is Derek lying?”的相关文章

hdu 6045 Is Derek lying?(思维推导)

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 consist

HDU 6045 17多校2 Is Derek lying?

题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=6045 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 687    Accepted Submission(s): 389 Problem Description Derek and Alfia are good friends.Derek 

【补题】多校联合训练第二场

第二场 1001 Is Derek lying? 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 i

20.5 Shell脚本中的逻辑判断;20.6 文件目录属性判断;20.7 if特殊用法;20.8 20.9 cace判断(上下)

扩展: select用法 http://www.apelearn.com/bbs/thread-7950-1-1.html 20.5 Shell脚本中的逻辑判断 格式1:if 条件 ; then 语句; fi 1. 创建if1.sh测试脚本: [[email protected] ~]# vi if1.sh a=5,如果a大于3,满足这个条件,显示ok 添加内容: #!/bin/bash a=5 if [ $a -gt 3 ] then echo ok fi 2. 执行if1.sh脚本: [[e

大量逻辑判断优化的思路——责任链模式复习总结及其和状态模式对比

俗话说,自己写的代码,6个月后也是别人的代码……复习!复习!复习!涉及的总结知识点如下: 责任链模式概念和例子 使用的条件 和状态模式的比较分析 责任链的优缺点 纯的责任链和不纯的责任链 javax.servlet.Filter#doFilter()方法源码分析 基于AOP思想,模拟一个拦截器 前面说了一个状态模式,总结过程中发现和这个责任链的使用场景很类似,都是为了解耦大量复杂业务逻辑判断的,那么他们有什么不同呢?回忆状态模式——状态模式允许通过改变对象的内部状态而改变对象自身的行为,这个对象

Shell编程进阶 1.5 if逻辑判断

逻辑判断 vim if.sh #!/bin/bash ## ## a=5 if [ $a -gt 3 ] then echo "a>3" fi sh if.sh a>3 vim if2.sh #!/bin/bash ## ## a=5 if [ $a -gt 3 ] then echo "a>3" fi if [ $a -gt 4 ] then echo "a>4" fi sh if2.sh sh if2.sh >

openJudge C17K:Lying Island

地址:http://poj.openjudge.cn/practice/C17K/ 题目: C17K:Lying Island 查看 提交 统计 提问 总时间限制:  2000ms 内存限制:  262144kB 描述 There are N people living on Lying Island. Some of them are good guys, while others are bad. It is known that good guys are always telling t

9. PowerShell -- 条件控制和逻辑判断

PowerShell条件控制 If, else, elseif 语句 基本语法: if (条件) {代码} elseif (条件) {代码} else (条件) {代码} else {代码} 例如1: $n=10 if ($n -eq 1) {"n=1"} elseif ($n -ne 1) {"n!=1,and n=$n"} 结果:{"n!=1,and n=$n"} 例如2:查看本机的操作系统 $ComputerName = (Get-WmiO

【SSH进阶之路】一步步重构MVC实现Struts框架——彻底去掉逻辑判断(五)

目录: [SSH进阶之路]Struts基本原理 + 实现简单登录(二) [SSH进阶之路]一步步重构MVC实现Struts框架--从一个简单MVC开始(三) [SSH进阶之路]一步步重构MVC实现Struts框架--封装业务逻辑和跳转路径(四) [SSH进阶之路]一步步重构MVC实现Struts框架--彻底去掉逻辑判断(五) [SSH进阶之路]一步步重构MVC实现Struts框架--完善转向页面,大功告成(六) Struts的第二篇博客[SSH进阶之路]Struts基本原理 + 实现简单登录(二