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;
}

之后自己用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;
}
目录
相关文章
|
9月前
|
人工智能 运维 Serverless
Serverless + AI 让应用开发更简单
Serverless + AI 让应用开发更简单
363 2
|
9月前
|
并行计算 算法 量子技术
量子计算在金融模型中的应用:未来金融的“黑科技”
量子计算在金融模型中的应用:未来金融的“黑科技”
447 1
|
传感器 C# Android开发
深度解析Uno Platform中的事件处理机制与交互设计艺术:从理论到实践的全方位指南,助您构建响应迅速、交互流畅的跨平台应用
Uno Platform 是一款开源框架,支持使用 C# 和 XAML 开发跨平台原生 UI 应用,兼容 Windows、iOS、Android 及 WebAssembly。本文将介绍 Uno Platform 中高效的事件处理方法,并通过示例代码展示交互设计的核心原则与实践技巧,帮助提升应用的用户体验。事件处理让应用能响应用户输入,如点击、触摸及传感器数据变化。通过 XAML 或 C# 添加事件处理器,可确保及时反馈用户操作。示例代码展示了一个按钮点击事件处理过程。此外,还可运用动画和过渡效果进一步增强应用交互性。
334 57
|
人工智能 算法
AI+脱口秀,笑点能靠算法创造吗
脱口秀是一种通过幽默诙谐的语言、夸张的表情与动作引发观众笑声的表演艺术。每位演员独具风格,内容涵盖个人情感、家庭琐事及社会热点。尽管我尝试用AI生成脱口秀段子,但AI缺乏真实的情感共鸣和即兴创作能力,生成的内容显得不够自然生动,难以触及人心深处的笑点。例如,AI生成的段子虽然流畅,却少了那份不期而遇的惊喜和激情,无法真正打动观众。 简介:脱口秀是通过幽默语言和夸张表演引发笑声的艺术形式,AI生成的段子虽流畅但缺乏情感共鸣和即兴创作力,难以达到真人表演的效果。
|
测试技术 BI
性能基准测试基本流程
性能基准测试基本流程
309 1
|
前端开发 JavaScript
一行js弹窗代码就能设计漂亮的弹窗广告
  接到一个设计需求,要求xmyanke在网站右侧挂一个弹窗广告宣传最近的活动,找了半天都没看到合适的,自己鼓捣了一行js弹窗代码就能设计漂亮的弹窗广告,来瞧一下,欢迎拍砖提意见,js弹窗广告代码如下: document.writeln("关闭X");   把上面的代码加到js中,网址和图片路径自己修改。
1731 0
IDEA同一项目启动在不同端口方法
IDEA同一项目启动在不同端口方法
1850 0
|
开发者
如何画好一张架构图/业务图/流程图,掌握这4个关键点
作为一个开发,日常工作中免不了要画一些图,无论是技术架构图还是业务流程图。基于个人的一些经验,作者分享了他的作图方法,给大家一点思路提供参考,希望在未来的工作、生活中都能有所帮助。
|
网络协议 安全 网络安全
什么是 IP 欺骗?
【8月更文挑战第24天】
438 0
|
存储 运维 Prometheus
全面公测|Grafana服务:一张图表胜过千行指标&日志
Grafana 帮助运维人员轻松处理各类运维过程中遇到的各类数据可视化与分析难题。目前阿里云 Grafana 服务全面免费公测,帮助企业轻松构建运维数据可视化平台,轻松实现数据驱动运维!
2455 98
全面公测|Grafana服务:一张图表胜过千行指标&日志