【多校联合】(HDU6045)Is Derek lying?
分析
之前没有想到题目解法,看了题解才会,记录一下思考过程。
这条题目的实质是,在满足合法的情况下,有没有a和d的可行解?也就是说,不要仅仅附在表面的思考逻辑条件,而是要思考实际的数学表达。
转化为数学模型,不妨设在二人答案相同的情况下,m为都对,n为都错;不同的情况下,p为D对A错,q为D错A对,r为都错。
于是我们可以建立这样的一个方程组:
可将上式变量全部用一个变量表示出来。又由题意可知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?的更多相关文章
- 2017多校联合训练2—HDU6054--Is Derek lying?(思维题)
Is Derek lying? Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- 2016暑假多校联合---Rikka with Sequence (线段树)
2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...
- 2016暑假多校联合---Windows 10
2016暑假多校联合---Windows 10(HDU:5802) Problem Description Long long ago, there was an old monk living on ...
- 2016暑假多校联合---Substring(后缀数组)
2016暑假多校联合---Substring Problem Description ?? is practicing his program skill, and now he is given a ...
- 2016暑假多校联合---To My Girlfriend
2016暑假多校联合---To My Girlfriend Problem Description Dear Guo I never forget the moment I met with you. ...
- 2016暑假多校联合---A Simple Chess
2016暑假多校联合---A Simple Chess Problem Description There is a n×m board, a chess want to go to the po ...
- HDU 5792---2016暑假多校联合---World is Exploding
2016暑假多校联合---World is Exploding Problem Description Given a sequence A with length n,count how many ...
- 2016暑假多校联合---Another Meaning
2016暑假多校联合---Another Meaning Problem Description As is known to all, in many cases, a word has two m ...
- hdu 5288||2015多校联合第一场1001题
pid=5288">http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a ar ...
- Contest1592 - 2018-2019赛季多校联合新生训练赛第二场(部分题解)
Contest1592 - 2018-2019赛季多校联合新生训练赛第二场 D 10248 修建高楼(模拟优化) H 10252 组装玩具(贪心+二分) D 传送门 题干 题目描述 C 市有一条东西走 ...
随机推荐
- winform 实现彩票功能
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/MrTraum/article/details/32702319 watermark/2/text/a ...
- 【luogu P2939 [USACO09FEB]改造路Revamping Trails】 题解
题目链接:https://www.luogu.org/problemnew/show/P2939 本来说是双倍经验题,跟飞行路线一样的,结果我飞行路线拿deque优化SPFA过了这里过不了了. 所以多 ...
- ISIS Scanner Errors codes
This section lists errors sorted by number: Error # Defined Constant String Defined In PIXDFLT 0 PIX ...
- artTemplate 根据key循环对象
artTemplate 根据key循环对象var dataObj={ data:{ a:{ name:'卡卡', age:10 }, b:{ name:'卡卡', age:10 }, c:{ name ...
- 路由器基本配置实验,静态路由和动态RIP路由
实验涉及命令以及知识补充 连线 PC和交换机FastEtherNet接口 交换机和路由器FastEtherNet接口 路由器和路由器Serial接口 serial是串行口,一般用于连接设备,不能连接电 ...
- Oracle db file parallel write 和 log file parallel write 等待事件
一. db file parallel write等待事件 引自如下blog: http://oradbpedia.com/wiki/Wait_Events_-_db_file_parallel_wr ...
- CF294C Shaass and Lights(排列组合)
题目描述 There are n n n lights aligned in a row. These lights are numbered 1 1 1 to n n n from left to ...
- UML绘制活动图--客户来电咨询活动图
选择Logic View–>New–>Activity Diagram 修改NewActivity为客户来电咨询 选择初始状态和终止状态(下图中上面是Start State,下面是End ...
- 【2018 ICPC亚洲区域赛沈阳站 L】Tree(思维+dfs)
Problem Description Consider a un-rooted tree T which is not the biological significance of tree or ...
- ABAP术语-Distribution Model
Distribution Model 原文:http://www.cnblogs.com/qiangsheng/archive/2008/01/25/1052434.html Model that d ...