HDU 6045 推公式
来源:互联网 发布:mac蓝光播放软件 编辑:程序博客网 时间:2024/05/20 01:13
题目
Is Derek lying?
题意
Derek 和 Alfia 是两个好朋友,他们回答三个问题,然后 Derek 会将他的成绩 X 和 Alfia 的成绩 Y 告诉 Alfia, 但是 Derek 可能会说谎。现在将这两个人的答案告诉你,请你判断 Derek 是否说谎。
题解
推公式,签到题。
我们假设 Alfia 的得分是正确的,根据他们俩的答案推出 Derek 得分的区间,然后判断 Derek 是否在此区间内。
首先定义两个变量 same 和 different 分别代表他们答案一样和不一样的数量。
然后就可以推出 左区间 l = max(y-different,0);
右区间 r = min(same,y) + (different - max(0,y-same));
代码
#include <algorithm>#include <bitset>#include <cstring>#include <cstdio>#include <cmath>#include <cstdlib>#include <climits>#include <iostream>#include <list>#include <map>#include <queue>#include <set>#include <stack>#include <string>#include <vector>using namespace std;int main(){ int t; cin >> t; while(t--){ int n,x,y; cin >> n >> x >> y; string a,b; cin >> a >> b; int same = 0; for(int i=0;i<n;i++){ if(a[i] == b[i]) same++; } int different = n - same; int l = max(y-different,0); int r = min(same,y) + (different - max(0,y-same)); if(x >= l && x <= r) cout << "Not lying" << endl; else cout << "Lying" << endl; } return 0;}
阅读全文
0 0
- HDU 6045 推公式
- HDU 3490 推公式
- HDU 6195 推公式
- HDU 6055 推公式
- HDU 6050 推公式
- HDU(2047) 递推公式
- HDU-6216 推公式+二分
- HDU-5970 推公式+分块
- hdu 4059 推公式+容斥
- hdu 3411 推公式+矩阵快速幂
- 【HDU】4919 Exclusive or 推公式+高精度
- HDU 4472 Count (线性dp 推公式)
- hdu 5073 推公式相邻质心转换
- HDU 5047 推公式+别样输出
- hdu 2064 汉诺塔III(推公式+dp)
- hdu 2077 汉诺塔IV(推公式+dp)
- hdu 1995 汉诺塔V(推公式+dp)
- HDU 4686 (推公式+矩阵快速幂)
- 机器学习之K-means聚类算法
- AngularJS ui.bootstrap.alert 消息
- Spring学习(三):初探Spring容器
- 我的递归总结
- SpringBoot学习之hello world
- HDU 6045 推公式
- 进 程 控 制
- 南阳理工学院acm 水池问题 自己的理解
- 面向对象
- JavaScript基础学习(一)
- 批量删除(特殊)
- NYOJ 237 游戏高手的烦恼 (最小点覆盖)
- 最全Pycharm教程(34)——Pycharm内置终端以及远程SSH工具的使用
- ubuntu安装google-chrome浏览器