1001.Is Derek lying?

简介: Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Description Derek and Alfia are good friends.

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 Input
2
3 1 3
AAA
ABC
5 5 0
ABCBC
ACBCB
Sample Output
Not lying
Lying

这几天写BFS写傻了,第一反应准备BFS直接搜过去,写着突然觉得不对,很明显得贪心啊~而且BFS应该会超内存。

//AC: 15MS  1836K
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        int N,X,Y,i,n=0,m=0,temp;
        scanf("%d%d%d",&N,&X,&Y);
        char s1[90000],s2[90000];
        scanf("%s%s",s1,s2);
        for(i=0;i<N;i++){
            if(s1[i]==s2[i])
                n++;
            else
                m++;
        }
        if(X>Y){
            temp=X;
            X=Y;
            Y=temp;
        }
        if(n<=X){
            if(X+Y-2*n<=m)
                printf("Not lying\n");
            else
                printf("Lying\n");
        }
        else{
            if(Y-X<=m)
                printf("Not lying\n");
            else
                printf("Lying\n");
        }
    }
    return 0;
}
AI 代码解读

之后自己用BFS做了交已发,果然超内存了。

//Memory Limit Exceeded: 156MS  77140K
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
struct Node{
    int a,b;
    int i,j;
};
void BFS(int n,int m,int x,int y){
    queue<Node>Q;
    Node now,next;
    now.a=0,now.b=0,now.i=0,now.j=0;
    Q.push(now);
    while(!Q.empty()){
        now=Q.front();
        Q.pop();
        if(now.a==x&&now.b==y){
            printf("Not lying\n");
            return;
        }
        if(now.i<n||now.j<m){
        for(int k=0;k<5;k++){
            if(k==0&&now.i<n){
                next.i=now.i+1;
                next.j=now.j;
                next.a=now.a+1;
                next.b=now.b+1;
                Q.push(next);
            }
            if(k==1&&now.i<n){
                next.i=now.i+1;
                next.j=now.j;
                next.a=now.a;
                next.b=now.b;
                Q.push(next);
            }
            if(k==2&&now.j<m){
                next.j=now.j+1;
                next.i=now.i;
                next.a=now.a+1;
                next.b=now.b;
                Q.push(next);
            }
            if(k==3&&now.j<m){
                next.j=now.j+1;
                next.i=now.i;
                next.a=now.a;
                next.b=now.b+1;
                Q.push(next);
            }
            if(k==4&&now.j<m){
                next.j=now.j+1;
                next.i=now.i;
                next.a=now.a;
                next.b=now.b;
                Q.push(next);
            }
        }
        }
    }
    printf("Lying\n");
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,sa,sb,i,x1=0,x2=0;
        scanf("%d%d%d",&n,&sa,&sb);
        char s1[90000],s2[90000];
        scanf("%s%s",s1,s2);
        for(i=0;i<n;i++){
            if(s1[i]==s2[i])
                x1++;
            else
                x2++;
        }
        BFS(x1,x2,sa,sb);
    }
    return 0;
}
AI 代码解读
目录
打赏
0
0
0
0
1
分享
相关文章
如何使用 Pandas 库进行数据清洗和预处理?
数据清洗和预处理是数据分析中至关重要的步骤,Pandas库提供了丰富的函数和方法来完成这些任务
438 64
物联网卡在新疆不能使用的原因
物联网卡不能在新疆使用的原因可能涉及多个方面,这通常与国家政策、网络安全、地区特殊性以及运营商的管理策略有关。以下是一些可能的解释:
物联网卡:物联网卡为什么不能使用在手机上
物联网卡(IoT SIM卡)通常是为物联网设备设计的,这些设备包括但不限于智能家居设备、可穿戴设备、工业监控设备等。它们与用于智能手机的SIM卡有所不同,主要是因为设计目标、功能限制、资费结构以及网络接入策略上的差异。以下是物联网卡不能直接在手机上使用的主要原因:
Windows 无法连接打印机,请检查打印机名并重试。如果这是网络打印机,请确保打印机已打开,并且打印机地址正确。报错代码:0x00000709
Windows 无法连接打印机,请检查打印机名并重试。如果这是网络打印机,请确保打印机已打开,并且打印机地址正确。报错代码:0x00000709
Windows 无法连接打印机,请检查打印机名并重试。如果这是网络打印机,请确保打印机已打开,并且打印机地址正确。报错代码:0x00000709
一行js弹窗代码就能设计漂亮的弹窗广告
  接到一个设计需求,要求xmyanke在网站右侧挂一个弹窗广告宣传最近的活动,找了半天都没看到合适的,自己鼓捣了一行js弹窗代码就能设计漂亮的弹窗广告,来瞧一下,欢迎拍砖提意见,js弹窗广告代码如下: document.writeln("关闭X");   把上面的代码加到js中,网址和图片路径自己修改。
1655 0
如何画好一张架构图/业务图/流程图,掌握这4个关键点
作为一个开发,日常工作中免不了要画一些图,无论是技术架构图还是业务流程图。基于个人的一些经验,作者分享了他的作图方法,给大家一点思路提供参考,希望在未来的工作、生活中都能有所帮助。
(详解及使用)import()函数和import语句
(详解及使用)import()函数和import语句
422 1
重装Win7时提示“缺少所需的CD/DVD驱动器设备驱动程序”
好多朋友都是这样,自己的电脑用的时间长了而又懒得经常去清理修复,或者因为偶尔中毒,系统运行不畅甚至崩溃。这几天每天都在网上找资料、下载资料,弄得自己的本本凌乱不堪,也懒得花时间去整理修复了,今天,终于彻底罢工不干了。
重装Win7时提示“缺少所需的CD/DVD驱动器设备驱动程序”
西门子S7-1200的程序结构,块,组织块OB,功能块FB,功能FC
在S7-1200的编程中采用了块的概念,即将程序分解为独立的自成体系的各个部件,块类似于子程序的功能,但类型更多,功能更强大。在工业控制中,程序往往是非常庞大和复杂的,采用块的概念,便于大规模的程序设计和理解,也可以设计标准化的块程序进行重复调用。在S7-1200中支持以下类型的代码块,使用他们可以创建有效的用户程序结构,组织块OB、功能FC、功能块FB、数据块DB。
西门子S7-1200的程序结构,块,组织块OB,功能块FB,功能FC
支付宝内置浏览器唤起支付方案分享
需求说明:需要使用支付宝内置浏览器来访问自己的网站,买家在网站下单,并且唤起支付宝支付。 解析:使用支付宝内置浏览器访问指定网站一般有两种方式 1.使用支付宝扫一扫功能,把网站地址生成二维码,使用支付宝扫一扫识别二维码扫码访问。
6836 11
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等

登录插画

登录以查看您的控制台资源

管理云资源
状态一览
快捷访问