HDU 5747 Aaronson(贪心)
来源:互联网 发布:微积分教材 知乎 编辑:程序博客网 时间:2024/05/17 21:57
Description
给出两个整数n和m,求方程的所有非负解中的最小值
Input
第一行一个整数T表示用例组数,每组用例占一行包括两个整数n和m
(1<=T<=10^5,0<=n,m<=10^7)
Output
对于每组用例,输出方程所有非负解中的最小值
Sample Input
10
1 2
3 2
5 2
10 2
10 3
10 4
13 5
20 4
11 11
12 3
Sample Output
1
2
2
3
2
2
3
2
3
2
Solution
贪心,尽可能使用下标较大的x
Code
#include<cstdio>#include<iostream> using namespace std;#define maxn 111int T,n,m,a[maxn],res,num; void deal(int x){ res=num=0; while(x) { a[res++]=x%2; num+=x%2; x/=2; }}int main(){ scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); deal(n); if(m>=res-1)printf("%d\n",num); else { deal(n%(1<<m)); printf("%d\n",(n>>m)+num); } } return 0;}
0 0
- hdu 5747 Aaronson(贪心)
- HDU 5747 Aaronson(贪心)
- HDU 5747 Aaronson 贪心
- hdu 5747 Aaronson【贪心】
- 【HDU】5747 - Aaronson(位运算 & 贪心)
- hdu 5747 Aaronson贪心水
- HDU OJ 5747(Aaronson)
- HDU5747 (Aaronson 贪心)
- HDU 5747 Aaronson (lower_bound函数)
- HDU 5747 Aaronson
- hdu 5747Aaronson(暴力)
- HDU 5747 Aaronson
- HDU 5747 Aaronson [位运算]
- HDU 5747 BestCoder Round #84 Aaronson (模拟)
- HDU 5747 Aaronson(汉明距离)
- hdu 5747 Aaronson (BestCoder Round #84 1001)
- hdoj 2894 Aaronson (贪心)
- HDOJ 5747 Aaronson
- contentSize、contentInset和contentOffset区别
- java 集合详解
- Delphi异常处理的基本原则和方法
- [从头学数学] 第246节 Python实现数据结构:链表
- Android图像处理—xfermode
- HDU 5747 Aaronson(贪心)
- Thinking in Java 第18章 Java I/O 系统(18.9-18.14)
- Qt的UI布局以及控件间隔(Spacing)边距(Margins)
- js获取select标签选中的值
- 判断二叉树是否平衡
- LeetCode[343] Integer Break
- LinearLayout中的baselineAligned与layout_weight
- python inspect模块解析
- 关键字