分析

之前没有想到题目解法,看了题解才会,记录一下思考过程。

这条题目的实质是,在满足合法的情况下,有没有a和d的可行解?也就是说,不要仅仅附在表面的思考逻辑条件,而是要思考实际的数学表达。

转化为数学模型,不妨设在二人答案相同的情况下,m为都对,n为都错;不同的情况下,p为D对A错,q为D错A对,r为都错。

于是我们可以建立这样的一个方程组:

⎧⎩⎨⎪⎪⎪⎪⎪⎪⎪⎪m+p=x,m+q=y,m+n=Nsame,p+q+r=Ndiff.

可将上式变量全部用一个变量表示出来。又由题意可知0≤m,n≤Nsame,0≤m,n≤Ndiff 从而带入不等式组,可得单个变量的取值范围,检查是否有可行解即可。

代码实现时,注意int型除法的整除给运算造成的影响,调了半天- -

代码

#include <iostream>
#include <bits/stdc++.h>
using namespace std; typedef long long ll; int main()
{
int T; cin>>T;
while(T--)
{
int n,x,y;
cin>>n>>x>>y;
string a,d;
cin>>a>>d;
int same=0,diff=0;
for(int i=0;i!=n;++i)
{
if(a[i]==d[i]) same++;
else diff++;
}
double bmin=0;
bmin=max(bmin,double(same-x));
bmin=max(bmin,double(same-y));
bmin=max(bmin,double(((2*same)-x-y)/2.0));
double bmax=same;
bmax=min(bmax,double(diff-x+same));
bmax=min(bmax,double(diff-y+same));
bmax=min(bmax,double((diff+(2*same)-x-y)/2.0));
//cout<<bmin<<" "<<bmax<<endl;
if(ceil(bmin)<=floor(bmax)) cout<<"Not lying"<<endl;
else cout<<"Lying"<<endl;
}
return 0;
}

【多校联合】(HDU6045)Is Derek lying?的更多相关文章

  1. 2017多校联合训练2—HDU6054--Is Derek lying?(思维题)

    Is Derek lying? Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  2. 2016暑假多校联合---Rikka with Sequence (线段树)

    2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...

  3. 2016暑假多校联合---Windows 10

    2016暑假多校联合---Windows 10(HDU:5802) Problem Description Long long ago, there was an old monk living on ...

  4. 2016暑假多校联合---Substring(后缀数组)

    2016暑假多校联合---Substring Problem Description ?? is practicing his program skill, and now he is given a ...

  5. 2016暑假多校联合---To My Girlfriend

    2016暑假多校联合---To My Girlfriend Problem Description Dear Guo I never forget the moment I met with you. ...

  6. 2016暑假多校联合---A Simple Chess

    2016暑假多校联合---A Simple Chess   Problem Description There is a n×m board, a chess want to go to the po ...

  7. HDU 5792---2016暑假多校联合---World is Exploding

    2016暑假多校联合---World is Exploding Problem Description Given a sequence A with length n,count how many ...

  8. 2016暑假多校联合---Another Meaning

    2016暑假多校联合---Another Meaning Problem Description As is known to all, in many cases, a word has two m ...

  9. hdu 5288||2015多校联合第一场1001题

    pid=5288">http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a ar ...

  10. Contest1592 - 2018-2019赛季多校联合新生训练赛第二场(部分题解)

    Contest1592 - 2018-2019赛季多校联合新生训练赛第二场 D 10248 修建高楼(模拟优化) H 10252 组装玩具(贪心+二分) D 传送门 题干 题目描述 C 市有一条东西走 ...

随机推荐

  1. BZOJ 2763: [JLOI2011]飞行路线 【分层图模板】

    任意门:https://www.lydsy.com/JudgeOnline/problem.php?id=2763 2763: [JLOI2011]飞行路线 Time Limit: 10 Sec  M ...

  2. Visual Studio 发布 Windows Service小记

    第一步:新建一个Window服务 第二步:添加安装程序 第三步,配置属性信息(Account选择LocalService) 第四步,在 OnStart和OnStop方法中写上你要干的事情吧.我这里用Q ...

  3. vue---组件引入及使用的几种方式

    在vue的项目开发过程中,基本都是基于组件化开发项目,总结下使用组件的几个点: 一.@符号的使用 在vue项目中 @ 符号代表的是根目录,即 src 目录. 二.组件的放置位置 在项目中,公用的组件放 ...

  4. 打开eclipse出现an error has occurred.see the loh file

    解决方案: 1,打开eclipse安装目录下的eclipse.ini文件:2,打开的文本文件最后添加一行--add-modules=ALL-SYSTEM3,保存重新打开Eclipse. 测试过已经ok

  5. 【luogu P3879 [TJOI2010]阅读理解】 题解

    题目链接:https://www.luogu.org/problemnew/show/P3879 我先说一句: 我永远都喜欢StellaSTL 这个题,很明显就是 trie树 hash map+vec ...

  6. Flask—04-文件上传与邮件发送(自带优化)

    文件上传与邮件发送 可以按照标题分别直接粘贴对应的文件夹,运行直接用: 原生上传 模板文件 <form method="post" enctype="multipa ...

  7. Aaliyun Linux 64 安装jdk+mysql+tomcat

    参考: http://www.blogjava.net/amigoxie/archive/2013/02/22/395605.html http://bbs.aliyun.com/read/17704 ...

  8. webpack中使用vue

    1.安装vue cnpm i install -S 2.由于在 webpack 中,推荐使用 .vue 的文件模板文件定义组件 , 所以 ,需要安装 能解析这种文件的 loader cnpm i vu ...

  9. 使用 form 和 iframe 实现图片上传回显

    主要利用 form 的 target 属性,在提交表单之后 response 返回到 iframe 中 form 的 action 可以自己写,也可以直接利用 富文本编辑器的接口实现上传 <fo ...

  10. ABAP术语-Database Rollback

    Database Rollback 原文:http://www.cnblogs.com/qiangsheng/archive/2008/01/24/1051238.html Operation tha ...