buptoj 1578
题目链接:http://acm.bupt.edu.cn/onlinejudge/newoj/showProblem/show_problem.php?problem_id=1578
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <queue>
#include <vector>
#include <bitset> using namespace std;
int a,b;
int calculatenum(int num){
int ans = ;
while(num>){
num = num/;
ans++;
}
return ans;
}
int calculateone(int num){
int ans = ;
while(num>){
if(num%) ans++;
num = num/;
}
return ans;
} int main(){
// if(freopen("input.txt","r",stdin)== NULL) {printf("Error\n"); exit(0);} int T;
cin>>T;
while(T--){ cin>>a>>b; int numa = calculatenum(a);
int numb = calculatenum(b); if(a == b){
printf("%d\n",calculateone(b));
}
else if(b == (<<numb )- ){
printf("%d\n",numb);
}
else if(numa < numb) {
printf("%d\n",numb-);
}
else{
int maxnum = calculateone(b);
int temp = b;
numa--;
while(a>>numa == b>>numa){
temp = temp%(<<numa);
numa--;
}
numa++;
if(temp != (<<numa)-){
maxnum = calculateone(b / (<<numa)) + calculatenum(temp) - ;
}
printf("%d\n",maxnum);
} }
}
buptoj 1578的更多相关文章
- BZOJ 1578: [Usaco2009 Feb]Stock Market 股票市场( 背包dp )
我们假设每天买完第二天就卖掉( 不卖出也可以看作是卖出后再买入 ), 这样就是变成了一个完全背包问题了, 股票价格为体积, 第二天的股票价格 - 今天股票价格为价值.... 然后就一天一天dp... ...
- 1578: [Usaco2009 Feb]Stock Market 股票市场
1578: [Usaco2009 Feb]Stock Market 股票市场 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 414 Solved: 1 ...
- hihoCoder 1578 Visiting Peking University 【贪心】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1578 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for ...
- cogs——1578. 次小生成树初级练习题
1578. 次小生成树初级练习题 ☆ 输入文件:mst2.in 输出文件:mst2.out 简单对比时间限制:1 s 内存限制:256 MB [题目描述] 求严格次小生成树 [输入格式 ...
- COGS——T 1578. 次小生成树初级练习题
http://www.cogs.pro/cogs/problem/problem.php?pid=1578 ☆ 输入文件:mst2.in 输出文件:mst2.out 简单对比时间限制:1 ...
- 洛谷1578:[WC2002]奶牛浴场——题解
https://www.luogu.org/problemnew/show/P1578#sub 由于John建造了牛场围栏,激起了奶牛的愤怒,奶牛的产奶量急剧减少.为了讨好奶牛,John决定在牛场中建 ...
- 【BZOJ】1578: [Usaco2009 Feb]Stock Market 股票市场
[题意]给定s个股票和d天,给出价格矩阵s*d,每天可以买入或卖出整数倍股票,初始资金m,求最大利益.m<=200000,s<=50,d<=10. [算法]完全背包 [题解]关键在于 ...
- COGS 1578. 次小生成树初级练习题
☆ 输入文件:mst2.in 输出文件:mst2.out 简单对比时间限制:1 s 内存限制:256 MB [题目描述] 求严格次小生成树 [输入格式] 第一行包含两个整数N 和M,表 ...
- bzoj 1578: [Usaco2009 Feb]Stock Market 股票市场【背包】
参考:https://blog.csdn.net/mars_ch/article/details/53011234 我背包真是好不熟练啊-- 第一天买了第三天卖相当于第一天买了第二天卖第二天再买第三天 ...
随机推荐
- java 引用资源-ClassLoader.getResource()方法
如图,eclipse中我的包结构为:,我在 spt.app.MainFrame 中可以通过一下代码段使用资源: public static Object obj = ImageIconProxy.cl ...
- jQuery实现的向下推送图文信息滚动效果
HTML 我们以新浪微博信息滚动为背景,html中包含了多条微博图文信息,结构如下: <div id="con"> <ul> <li> < ...
- java 对于url地址的实体符号的处理
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 <dependency> <g ...
- Vijos1675 NOI2005 聪聪和可可 记忆化搜索
简单题,结果因为理解错题意懵逼了好久…… moveTo[x][y]表示聪聪在节点x,可可在节点y时,聪聪下一步应到达哪一个节点 dp[x][y]表示聪聪在节点x,可可在节点y,且轮到可可行动时,所需时 ...
- 【POJ2912】【并查集】Rochambeau
Description N children are playing Rochambeau (scissors-rock-cloth) game with you. One of them is th ...
- 3 - testng.xml
TestNG的调用有以下几种方式: testng.xml ant 命令行 这部分主要介绍testng.xml的格式. 当前testng.xml的DTD(文档类型定义(Document Type Def ...
- shell用if
--------- shell用if出错了,Why? shell if 实例: site=github.com/fankcoder if [ $site == github.com/fankcoder ...
- C# ToString常用技巧总结
ToString是在开发中最常用的操作,其作用是将其它类型以字符串类型表示.例如: int i=2;i.ToString() //”2″Object o = new Object();o.ToStri ...
- js基础 - 兼容代码
js基础 - 兼容代码 . scrollTop . chrome document.body.scrollTop . IE && firefox document.documentEl ...
- ffmepg命令行参数
ffmpeg使用 有些选项在每个流中都必须指定,例如比特率bitrate或编解码codec.指定流的字符串一般都会有各参数名称和参数,如编解码"-codec:a:1 ac3"表明第 ...