【多校联合】(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 市有一条东西走 ...
随机推荐
- R 代码积累
R 代码积累不定期更新 1.阶乘.递归.reduce.sprintf #NO.1 # 阶乘函数 fact <- function(n){ if(n==0) return(1) #基例在这 els ...
- apache php 与nginx php 的区别
apache是通过mod_php来解析php nginx是通过php-fpm(fast-cgi)来解析php 1. PHP 解释器是否嵌入 Web 服务器进程内部执行 mod_php 通过嵌入 PHP ...
- HTTP请求方式中8种请求方法(简单介绍)
简单介绍 HTTP是超文本传输协议,其定义了客户端与服务器端之间文本传输的规范.HTTP默认使用80端口,这个端口指的是服务端的端口,而客户端使用的端口是动态分配的.当我们没有指定端口访问时,浏览器会 ...
- js控件设置只读属性和不可用属性
介绍js实现只读的几种方法: 设置控件只读的话,我们要先清楚哪些没有readOlny这个属性 我知道的checkbox和RadioButton没有readOlny这个属性,我上一篇已经介绍了如何设置c ...
- 【洛谷P3811】[模板]乘法逆元
乘法逆元 题目链接 求逆元的三种方式: 1.扩欧 i*x≡1 (mod p) 可以化为:x*i+y*p=1 exgcd求x即可 inline void exgcd(int a,int b,int &a ...
- 【洛谷T37388】P哥破解密码
原题图: 看到这个题,首先想到的当然是暴力打表找规律了 表: 1 2 2 4 3 7 4 13 5 24 6 44 7 81 8 149 9 274 10 504 11 927 12 1705 13 ...
- Android学习笔记_32_通过WebView实现JS代码与Java代码互相通信
webview两种实现方法,覆盖onKeyDown()方法 缓存 WebSettings应用注意的几个问题 1.要实现JS代码与Java代码互相通信,需要通过Android的WebView控件,在视图 ...
- 前端路由原理及vue-router介绍
前端路由原理本质就是监听 URL 的变化,然后匹配路由规则,显示相应的页面,并且无须刷新.目前单页面使用的路由就只有两种实现方式 hash history www.test.com/##/ 就是 Ha ...
- Spring data JPA 理解(默认查询 自定义查询 分页查询)及no session 三种处理方法
简介:Spring Data JPA 其实就是JDK方式(还有一种cglib的方式需要Class)的动态代理 (需要一个接口 有一大堆接口最上边的是Repository接口来自org.springfr ...
- Hibernate知识点小结汇总
Hibernate部分 1.为什么要使用Hibernate开发你的项目呢?Hibernate的开发流程是怎么样的? 为什么要使用 ①.对JDBC访问数据库的代码做了封装,大大简化了数据访问层繁琐的重复 ...