多校1001 HDU-6045. Is Derek lying? 逻辑题
来源:互联网 发布:打口鞋淘宝匡威能买吗 编辑:程序博客网 时间:2024/06/06 01:06
题目链接:HDU-6045
大意:
两个人分别回答一串问题,得到两个答案字符串,并且知道每个人得分,答案只有ABC三种。
现在给出两个字符串,判断其中第一个人是否说谎。
样例:
Sample Input
2
3 1 3
AAA
ABC
5 5 0
ABCBC
ACBCB
Sample Output
Not lying
Lying
思路:
马上想到要考察相同的字母,因为这些字母比较特殊,要么同错要么同对。
然后基本按照题解的思路来解。
首先,我们统计出Derek和Alfia答案相同的题目数量k1和答案不同的题目数量k2. 对于两人答案相同的题目,共有以下两种情况:a.两人都对b.两人都错 对于两人答案不同的题目,共有以下三种情况: c.Derek对Alfia错 d.Alfia对Derek错 e.两人都错 于是我们可以列出一些方程: k1+k2=n a+b=k1 c+d+e=k2 a+c=x a+d=y 又a,b,c,d,e均为非负整数,且满足a,b<=k1;c,d,e<=k2 将a,b,d,e全部用c替换后需要同时满足以下四个条件:0<=c<=k2 x-y<=c<=k2+x-y (x-y)/2<=c<=(k2+x-y)/2 x-k1<=c<=x 我们只需要判断这四段区间存不存在公共的整数点,如果存在,则说明Derek没有说谎;如果不存在,则说明Derek在说谎。
实现代码:
#include<bits/stdc++.h>using namespace std;typedef long long ll;#define mem(s,t) memset(s,t,sizeof(s))#define D(v) cout<<#v<<" "<<v<<endl#define inf 0x3f3f3f3f//#define LOCALconst int MAXN =80000+10;int main(){ int t;scanf("%d",&t); while(t--){ int n,x,y; scanf("%d%d%d",&n,&x,&y); char s1[MAXN],s2[MAXN]; scanf("%s%s",&s1,&s2); int k1=0,k2=0; for(int i=0;i<n;i++){ if(s1[i]==s2[i]){ k1++; } } k2=n-k1; double l=0; l=max(0.0,1.0*x-y);l=max(l,1.0*x-k1); double r=inf; r=min(k2*1.0,1.0*(k2+x-y)/2);r=min(r,x*1.0);r=min(r,1.0*(k2+x-y)); int temp=-1; for(int i=l;i<=r;i++){ temp=i; } if(temp*1.0>=l && temp*1.0<=r){ puts("Not lying"); }else puts("Lying"); } return 0;}
PS.一开始做是wa了几次..想简单了,虽然想到要点但是没有列出四条方程,所以遇到这种问题重要的是找出共同点,利用公式解题,简单地逻辑判断很容易漏掉情况
阅读全文
0 0
- 多校1001 HDU-6045. Is Derek lying? 逻辑题
- hdu 6045.Is Derek lying?
- Is Derek lying? HDU
- HDU 6045多校Is Derek lying?
- hdu 6054-Is Derek lying?
- HDU 6045 Is Derek lying?
- hdu 6045 Is Derek lying?
- HDU 6045 Is Derek lying?
- hdu--6045 Is Derek Lying
- hdu 6045 Is Derek lying?
- HDU 6045 Is Derek lying?【】
- HDU 6045 Is Derek lying?
- HDU-6045-Is Derek lying?
- hdu 6045 Is Derek lying?
- 2017 多校2 1001 Is Derek lying?
- HDU 2017 多校联赛2 1001 Is Derek lying?
- 2017多校联合第二场 1001题 hdu 6045 Is Derek lying?
- Is Derek lying?(HDU 6045)
- bugku Web5
- 【剑指offer】面试题51:数组中的逆序对
- 《零基础入门学习Python》学习过程笔记【021匿名函数】
- 杭电oj1157 排序 参考1040
- 一个程序来比较cuda/c在GPU/CPU的运行效率
- 多校1001 HDU-6045. Is Derek lying? 逻辑题
- 多校1006 HDU-6050. Funny Function 数学推导题
- 【剑指offer】面试题52:两个链表的第一个公共节点
- 《零基础入门学习Python》学习过程笔记【022,023,024递归】
- 解题报告: #115 Min Stack
- Ubuntu——安装搜狗拼音输入法
- C++、python、CUDA性能分析--矩阵乘法
- IA32体系32位Linux系统虚拟地址映射上
- 图像处理22:图像模糊(滤波器)