本文主要是介绍HDU6045 Is Derek lying?(规律,2017 HDU多校联赛 第2场),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目:
Is Derek lying?
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 501 Accepted Submission(s): 302
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
Please print “ Lying ” if you can make sure that Derek is lying,otherwise please print “ Not lying ”.
2 3 1 3 AAA ABC 5 5 0 ABCBC ACBCB
Not lying Lying
有两个人在进行考试,有n道题,A和B分别回答自己做对了几道,A回答X道的是正确的,B回答Y道可能有错,题目问B有没有撒谎
我们先计算出A和B的回答有多少道是相同的,记为cnt,那么如果B没有撒谎,那么应该满足:
x+y≤n+cnt(两个人一共做对的题数一定小于等于总题数+答案相同的题数)
|x-y|≤n-cnt(两个人所作的题数之差,一定小于等于总题数-答案相同的题数)
代码:
#include <cstdio>
#include <cstring>
#include <cctype>
#include <string>
#include <set>
#include <iostream>
#include <stack>
#include <cmath>
#include <queue>
#include <vector>
#include <algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define N 80000+20
#define ll long long
using namespace std;
char s1[N],s2[N];
int main()
{int t,n,x,y;scanf("%d",&t);while(t--){scanf("%d%d%d%s%s",&n,&x,&y,s1,s2);int cnt=0;for(int i=0; i<n; i++)if(s1[i]==s2[i])cnt++;if(x+y<=(n+cnt)&&abs(x-y)<=(n-cnt))puts("Not lying");elseputs("Lying");}return 0;
}
这篇关于HDU6045 Is Derek lying?(规律,2017 HDU多校联赛 第2场)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!