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;
}
目录
相关文章
2020ICPC昆明M.Stone Games(主席树)
2020ICPC昆明M.Stone Games(主席树)
82 0
|
人工智能
upc 2021秋组队训练赛第三场 2020 Rocky Mountain Regional Contest
upc 2021秋组队训练赛第三场 2020 Rocky Mountain Regional Contest
95 0
UPC组队赛第三场——G: The Famous ICPC Team Again (主席树)
UPC组队赛第三场——G: The Famous ICPC Team Again (主席树)
100 0
|
机器学习/深度学习 存储 编解码
IEEE年度大奖揭幕!华人科学家,Yang-Kieffer算法之父杨恩辉斩获Eric E.Summer奖
IEEE 宣布将Eric E. Sumner奖发给加拿大滑铁卢大学终身教授杨恩辉教授,以表彰他在视频压缩领域的贡献。
338 0
IEEE年度大奖揭幕!华人科学家,Yang-Kieffer算法之父杨恩辉斩获Eric E.Summer奖
DayDayUp:2019.01.24马云冬季达沃斯论坛(演讲)—Machine will be smarter than human beings, but will never be wiser
DayDayUp:2019.01.24马云冬季达沃斯论坛(演讲)—Machine will be smarter than human beings, but will never be wiser
|
算法 C++
CCPC桂林
  在得知我们队伍前往桂林参加CPPC区域赛后,我是非常激动的,因为我们网络赛并没有得到名额,如果不是新都赠予我们名额,我们都没有出去打比赛的机会,同时,我们也不想浪费这个名额,我们也想打出成绩来,于是我做了一个训练计划,我们组内讨论了一个月内的时间应该着重学习一些什么算法,并整理出了一些习题进行专项训练。
1049 0
七月观荷 - 江湖一剑客
致敬普吕多姆和阿多尼斯 也如这清晨的薄雾,如它温暖的丝线—— 我的诗歌只为你灵魂的黑夜而作 一经被人窥破,便要苍白失色 万物静默如斯,唯有孤独,恒常如新 世间绝美的东西一定是转瞬即逝的——正是因为这样的转瞬即逝才造就了绝美。
1183 0