hdu 6045 Is Derek lying?(思维推导)
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
Sample Input AAA
ABC ABCBC
ACBCB Sample Output Not lying
Lying
题意:
现在两个人同时回答一套题,ABC三个选项,只有一个是正确的,答对得一分,答错不得分,给出两个人的成绩和答案,判断这两个成绩是否合理。
比如一共五个题,两个人的得分都是五分,然后两个人的答案都不相同,那么表示不合理。
思路:
没什么技巧,就是推理题目。推理方法有很多种,只要合理就行。
思路一:记录两个人答案相同的个数,如果 两个人成绩的和小于等于题目总数加上相同的个数 并且 两个人的分数差小于等于题目总数减去相同的个数,则表示没说谎。
思路二:记录两人答案相同和不同的题数,如果 两个人成绩的和小于等于不同的个数加上两倍的相同的个数 并且 两个人分数差小于等于不相同的答案数,则表示没说谎
代码一:
/*
ACACBCA
BABACBB
*/
#include<stdio.h>
#include<math.h>
#include<cmath>
using namespace std;
char a1[],a2[];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,x,y,i,j;
int butong=,xiangtong=;
scanf("%d%d%d",&n,&x,&y);
scanf("%s%s",a1,a2);
for(i=;i<n;i++)//计算相同和不同的个数
{
if(a1[i]==a2[i])
xiangtong++;
else
butong++;
}
if(x+y<=n+xiangtong&&abs(x-y)<=n-xiangtong)
printf("Not lying\n");
else
printf("Lying\n");
}
}
代码二:
/*
ACACBCA
BABACBB
*/
#include<stdio.h>
#include<math.h>
#include<cmath>
using namespace std;
char a1[],a2[];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,x,y,i,j;
int butong=,xiangtong=;
scanf("%d%d%d",&n,&x,&y);
scanf("%s%s",a1,a2);
for(i=;i<n;i++)//计算相同和不同的个数
{
if(a1[i]==a2[i])
xiangtong++;
else
butong++;
}
if(abs(x-y)<=butong&&x+y<=butong+*xiangtong)
printf("Not lying\n");
else
printf("Lying\n");
}
}
hdu 6045 Is Derek lying?(思维推导)的更多相关文章
- HDU 6045 - Is Derek lying | 2017 Multi-University Training Contest 2
/* HDU 6045 - Is Derek lying [ 分析 ] 题意: 有N个问题, 每个问题有A,B,C三种答案,答对加一分,答错不加分 给出甲乙两人的答案,给出两人的分数先x, y,问分数 ...
- HDU 6045 Is Derek lying?
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=6045 题目: Is Derek lying? Time Limit: 3000/1000 MS (Ja ...
- 2017ACM暑期多校联合训练 - Team 2 1001 HDU 6045 Is Derek lying? (模拟)
题目链接 Problem Description Derek and Alfia are good friends.Derek is Chinese,and Alfia is Austrian.Thi ...
- hdu 6045: Is Derek lying? (2017 多校第二场 1001)【找规律】
题目链接 可以暴力找一下规律 比如,假设N=7,两人有5题相同,2题不同,枚举X=0->15时,Y的"Not lying"的取值范围从而找出规律 #include<bi ...
- 2017多校联合训练2—HDU6054--Is Derek lying?(思维题)
Is Derek lying? Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- 观光公交 [NOIP 2011] [思维推导]
Description 风景迷人的小城Y 市,拥有n 个美丽的景点.由于慕名而来的游客越来越多,Y 市特意安排了一辆观光公交车,为游客提供更便捷的交通服务.观光公交车在第0 分钟出现在1号景点,随后依 ...
- HDU 6187 Destroy Walls (思维,最大生成树)
HDU 6187 Destroy Walls (思维,最大生成树) Destroy Walls *Time Limit: 8000/4000 MS (Java/Others) Memory Limit ...
- HDU 6045 17多校2 Is Derek lying?
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=6045 Time Limit: 3000/1000 MS (Java/Others) Memory ...
- hdu 6045 多校签到题目
http://acm.hdu.edu.cn/showproblem.php?pid=6045 题解:遍历一遍,求出两个人答案中相同的个数,用wa表示.然后我从大的数入手,当wa的数都尽可能在两个人答案 ...
随机推荐
- Markdown: 编译pdf
在网上发布博文的时候希望能顺便在本地保存一份记录,这样总结的东西很多的时候就可以写成一本给自己看的小书了.在linux下面有两个选择latex和markdown,虽然latex非常强大,但是很少有博客 ...
- fastJson将json字符串转换为map
public class JsonUtil { /** * 将json转化成map * @param jsonStr * @return */ public static Map<String, ...
- 修改linux的系统时间
可以使用date命令.date用于打印或设置系统日期和时间.设置系统时间需要root权限.用法示例:设置系统日期成2015年08月13日,这样会把具体时间设置清空成00:00:00$ sudo dat ...
- 【Android Developers Training】 106. 创建并检测地理围栏
注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...
- P2727 Stringsobits
01串 Stringsobits 题目背景 考虑排好序的N(N<=31)位二进制数. 题目描述 他们是排列好的,而且包含所有长度为N且这个二进制数中1的位数的个数小于等于L(L<=N)的数 ...
- java项目(非ssm等框架)下的quartz定时器任务
第一步:引包 要使用Quartz,必须要引入以下这几个包: 1.log4j-1.2.16 2.quartz-2.1.7 3.slf4j-api-1.6.1.jar 4.slf4j-log4j12-1. ...
- linux虚拟机下解压文件
pscp命令上传文件到linux虚拟机 项目开发过程中,经常需要从windows向linux服务器上传下载文件.下面简单介绍一下如何上传下载文件. 下载安装putty软件:https://pan. ...
- 预编译语句(Prepared Statements)介绍,以MySQL为例
背景 本文重点讲述MySQL中的预编译语句并从MySQL的Connector/J源码出发讲述其在Java语言中相关使用. 注意:文中的描述与结论基于MySQL 5.7.16以及Connect/J 5. ...
- Centos操作系统在虚拟机VMware上的安装
1.下载centos操作系统,提供百度云盘链接:http://pan.baidu.com/s/1pLHOR03 2.打开上篇在VMware中新建好的空白虚拟机,将centos安装在此空白虚拟机上,步骤 ...
- 在线用户数-Constants
package com.pb.news.constants; public class Constants { public static int ONLINE_USER_COUNT=0;//在线用户 ...