HDU 5491 The Next (二进制) 2015合肥网络赛
来源:互联网 发布:淘宝直通车的使用规则 编辑:程序博客网 时间:2024/05/01 23:59
题意: 求数的二进制位中1的个数满足[s1,s2]的下一个数
分析: 从低位到高位枚举0变成1 把之后的从最低位到当前位补够1 其他的全部置0
注意判断当前是否满足条件 不行就枚举下一个 INT_MAX下一位会炸int国际惯例开LL了
代码:
//// Created by TaoSama on 2015-09-27// Copyright (c) 2015 TaoSama. All rights reserved.////#pragma comment(linker, "/STACK:1024000000,1024000000")#include <algorithm>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iomanip>#include <iostream>#include <map>#include <queue>#include <string>#include <set>#include <vector>using namespace std;#define pr(x) cout << #x << " = " << x << " "#define prln(x) cout << #x << " = " << x << endlconst int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;long long d, s1, s2;int main() {#ifdef LOCAL freopen("in.txt", "r", stdin);// freopen("out.txt","w",stdout);#endif ios_base::sync_with_stdio(0); int t; scanf("%d", &t); int kase = 0; while(t--) { scanf("%I64d%I64d%I64d", &d, &s1, &s2); int n = __builtin_popcountll(d); int cnt = 0; for(int i = 0; i < 32; ++i) { if(d >> i & 1LL) ++cnt; else { long long ans = d, have = n - cnt + 1; ans |= 1LL << i; bool ok = false; for(int j = 0; j < i; ++j) { if(have < s1) { ans |= 1LL << j; if(++have == s1) ok = true; } else { ok = true; ans &= ~(1LL << j); } } int tmp = __builtin_popcountll(ans); ok = tmp >= s1 && tmp <= s2; if(ok) { printf("Case #%d: %I64d\n", ++kase, ans); break; } } } } return 0;}
0 0
- HDU 5491 The Next (二进制) 2015合肥网络赛
- HDU 5491 The Next (2015年合肥赛区网络赛H题)
- hdu 5491 The Next(ICPC合肥赛)
- hdu 5491 The Next 2015合肥网络赛 贪心 位运算
- hdu5491 The Next(合肥网赛)
- 2015 ACM/ICPC合肥网赛&HDU5491 The Next
- HDU 5493 Queue (线段树) 2015合肥网络赛
- hdu-5489(2015网络赛合肥赛区)***
- hdu 5493 线段树(2015年合肥网络赛)
- HDU 5493 Queue (线段树)2015合肥赛区网络赛
- HDU 5491 The Next
- hdu 5491 The Next
- HDU 5491 The Next
- HDU 5491 The Next
- HDU 5491The Next
- HDU 5491 The Next【】
- HDU 5492 Find a path (dp) 2015合肥网络赛
- HDU 5489 Removed Interval (dp+线段树) 2015合肥网络赛
- Thread.currentThread().getContextClassLoader() 和 Class.getClassLoader()区别
- JAVA 常用类
- 软件生命周期的内容以及生命周期模型比较
- 【iOS 开发】Objective - C 面向对象 - 方法 | 成员变量 | 隐藏封装 | KVC | KVO | 初始化 | 多态
- BZOJ 1502 月下柠檬树 自适应辛普森积分
- HDU 5491 The Next (二进制) 2015合肥网络赛
- How To: 5 Steps to Install phpMyAdmin on Linux
- 宏的作用域
- sendmsg和recvmsg
- android开发时的参考
- N-Queens II
- No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
- UIAlertView 警告框
- 学习之路