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;
}
目录
相关文章
|
7月前
|
机器学习/深度学习 人工智能 BI
2019ICPCshenyang网络赛(C. Dawn-K's water)
2019ICPCshenyang网络赛(C. Dawn-K's water)
|
7月前
|
Java
hdu 1164 Eddy's research I
hdu 1164 Eddy's research I
40 0
|
7月前
|
人工智能 Java
hdu 1165 Eddy's research II
hdu 1165 Eddy's research II
43 0
The Preliminary Contest for ICPC China Nanchang National Invitational M题 Subsequence
The Preliminary Contest for ICPC China Nanchang National Invitational M题 Subsequence
79 0
upc2021秋组队训练赛第一场 ICPC North Central NA Contest 2020
upc2021秋组队训练赛第一场 ICPC North Central NA Contest 2020
95 0
upc2021秋组队训练赛第一场 ICPC North Central NA Contest 2020
|
人工智能
upc 2021秋组队训练赛第三场 2020 Rocky Mountain Regional Contest
upc 2021秋组队训练赛第三场 2020 Rocky Mountain Regional Contest
104 0
AtCoder Beginner Contest 226 E - Just one(dfs求连通块 组合数学)
AtCoder Beginner Contest 226 E - Just one(dfs求连通块 组合数学)
108 0
AtCoder Beginner Contest 133 E - Virus Tree 2(组合数学)
AtCoder Beginner Contest 133 E - Virus Tree 2(组合数学)
110 0
HDOJ 1017 A Mathematical Curiosity
HDOJ 1017 A Mathematical Curiosity
113 0