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 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,∑Ti=1N≤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

Sample Input

2
3 1 3
AAA
ABC
5 5 0
ABCBC
ACBCB

Sample Output

Not lying
Lying

题意:

  现在两个人同时回答一套题,ABC三个选项,只有一个是正确的,答对得一分,答错不得分,给出两个人的成绩和答案,判断这两个成绩是否合理。

  比如一共五个题,两个人的得分都是五分,然后两个人的答案都不相同,那么表示不合理。

思路:

  没什么技巧,就是推理题目。推理方法有很多种,只要合理就行。

  思路一:记录两个人答案相同的个数,如果  两个人成绩的和小于等于题目总数加上相同的个数  并且  两个人的分数差小于等于题目总数减去相同的个数,则表示没说谎。

  思路二:记录两人答案相同和不同的题数,如果  两个人成绩的和小于等于不同的个数加上两倍的相同的个数  并且   两个人分数差小于等于不相同的答案数,则表示没说谎

代码一:

/*
ACACBCA
BABACBB
*/
#include<stdio.h>
#include<math.h>
#include<cmath>
using namespace std;
char a1[80050],a2[80050];
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n,x,y,i,j;
        int butong=0,xiangtong=0;
        scanf("%d%d%d",&n,&x,&y);
        scanf("%s%s",a1,a2);
        for(i=0;i<n;i++)//计算相同和不同的个数
        {
            if(a1[i]==a2[i])
                xiangtong++;
            else
                butong++;
        }
        if(x+y<=n+xiangtong&&abs(x-y)<=n-xiangtong)
            printf("Not lying\n");
        else
            printf("Lying\n");
    }
}

代码二:

/*
ACACBCA
BABACBB
*/
#include<stdio.h>
#include<math.h>
#include<cmath>
using namespace std;
char a1[80050],a2[80050];
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n,x,y,i,j;
        int butong=0,xiangtong=0;
        scanf("%d%d%d",&n,&x,&y);
        scanf("%s%s",a1,a2);
        for(i=0;i<n;i++)//计算相同和不同的个数
        {
            if(a1[i]==a2[i])
                xiangtong++;
            else
                butong++;
        }
        if(abs(x-y)<=butong&&x+y<=butong+2*xiangtong)
            printf("Not lying\n");
        else
            printf("Lying\n");
    }
}
时间: 2024-10-29 19:06:22

hdu 6045 Is Derek lying?(思维推导)的相关文章

HDU 6154 CaoHaha&#39;s staff 思维 找规律

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6154 题目描述: 围成一个面积不小于S的多边形, 最少需要多少根儿线段, 线段可以为单元格边或者对角线 解题思路: 最大的面积肯定是由根号2为边长的正方形围成了, 那么我们把所有正方形都遍历一遍, 找出S介于N, N+1的那个上界N+1设为max, 因为MAX所围成的多边形面积和MAX-1, MAX-2, MAX-3围成的多边形面积, 找出满足条件的最小的一个即可 代码: #include <io

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha&#39;s staff 思维

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6154 题意:在笛卡尔坐标系下,画一个面积至少为  n 的简单多边形,每次只能画一条边或者一个格子的对角线,问至少要画几条. 解法:如果一个斜着的矩形长宽分别是 a,b,那么它的面积是 2ab.最优解肯定是离 sqrt(n/2)很近的位置.想想 n=5 时答案为什么是7 然后在那个小范围内枚举一下就好了.我给一张做题时画的图 #include <bits/stdc++.h> using namesp

hdu 4710 Balls Rearrangement (数学思维)

题意:就是  把编号从0-n的小球对应放进i%a编号的盒子里,然后又买了新盒子, 现在总共有b个盒子,Bob想把球装进i%b编号的盒子里.求重置的最小花费. 每次移动的花费为y - x ,即移动前后盒子编号的差值的绝对值. 算法: 题目就是要求                  先判断  n与  lcm(a,b)的大小,每一个周期存在循环,这样把区间缩短避免重复计算. 如果n>lcm(a,b)则   ans = (n/lcm)*solve(lcm)+solve(n%lcm) 否则   ans =

hdu 4882 ZCC Loves Codefires (贪心 推导)

题目链接 做题的时候凑的规律,其实可以 用式子推一下的. 题意:n对数,每对数有e,k, 按照题目的要求(可以看下面的Hint就明白了)求最小的值. 分析:假设现在总的是sum, 有两个e1 k1 e2 k2 则先选e1 为 (sum+e1)*k1+(sum+e1+e2)*k2 先e2: (sum+e2)*k2 + (sum+e1+e2)*k1. 比较两个式子发现不同的部分分别是 e1*k2   e2*k1; 比较大小移向 e1/k1  e2/k2, 那个小,就选那个,能达到最小. 官方题解:

hdu 1452 Happy 2004 膜拜这推导过程

Happy 2004 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 920    Accepted Submission(s): 648 Problem Description Consider a positive integer X,and let S be the sum of all positive integer divis

HDU 3972 1 M possible(思维)

1 M possible Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 2048/1024 K (Java/Others) Total Submission(s): 1031    Accepted Submission(s): 343 Problem Description There are 3*N+2 nonnegative integers. Except two special integers, the rest 3

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 

hdu 6045 多校签到题目

http://acm.hdu.edu.cn/showproblem.php?pid=6045 题解:遍历一遍,求出两个人答案中相同的个数,用wa表示.然后我从大的数入手,当wa的数都尽可能在两个人答案的相同部分时,另一个人的答案中对的个数最小:当wa的数尽可能在两者答案不同的部分的时候,另一个人的答案对的个数最多. ac代码: #include <cstdio> #include <iostream> #include <queue> using namespace s

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