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;
}
目录
相关文章
|
SQL Web App开发 Oracle
Ichunqiu云境 —— Endless(无间计划) Writeup
两个入口点,一个入口点是pboot-cms,另外一个是SQL注入
|
算法 决策智能 Windows
【论文阅读】(2017)The late acceptance Hill-Climbing heuristic
【论文阅读】(2017)The late acceptance Hill-Climbing heuristic
402 0
【论文阅读】(2017)The late acceptance Hill-Climbing heuristic
|
人工智能
upc 2021秋组队训练赛第三场 2020 Rocky Mountain Regional Contest
upc 2021秋组队训练赛第三场 2020 Rocky Mountain Regional Contest
112 0
CodeForces 1195C Basketball Exercise (线性DP)
CodeForces 1195C Basketball Exercise (线性DP)
131 0
|
决策智能
BNUOJ 44578 Monty Hall problem
BNUOJ 44578 Monty Hall problem
123 0