【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

多重背包的二进制优化。
就是将数量x分成接近log2x份
然后这log2x份能组合成1..x内的所有数字。
从而将多重背包转化成01背包
1,2,4,8....贪心地选,然后不够的部分x-(1+2+4...)再作为一份就好

【代码】

#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define lson l,mid,rt<<1
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x)
#define rson mid+1,r,rt<<1|1
using namespace std; const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0}; int n; int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
scanf("%d",&n);
int now = 0,cnt = 0;
for (int i = 1; ;i*=2){
now+=i;
if (now>n) {
now-=i;
break;
}
cnt++;
}
if (now<n) cnt++;
printf("%d\n",cnt);
return 0;
}

【Manthan, Codefest 18 (rated, Div. 1 + Div. 2) A】Packets的更多相关文章

  1. 【Manthan, Codefest 18 (rated, Div. 1 + Div. 2) C】Equalize

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] Swap操作显然只能对(i-1,i)执行才有用. 不然直接将i翻转以及j翻转 显然比直接交换更优. 那么现在我们就相当于有两种操作. ...

  2. 【Manthan, Codefest 18 (rated, Div. 1 + Div. 2) B】Reach Median

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 将数组排序一下. 考虑中位数a[mid] 如果a[mid]==s直接输出0 如果a[mid]<s,那么我们把a[mid]改成s ...

  3. Manthan, Codefest 18 (rated, Div. 1 + Div. 2) C D

    C - Equalize #include<bits/stdc++.h> using namespace std; using namespace std; string a,b; int ...

  4. 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T5(思维)

    还是dfs? 好像自己写的有锅 过不去 看了题解修改了才过qwq #include <cstdio> #include <algorithm> #include <cst ...

  5. 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T4(模拟)

    随便模拟下就过了qwq 然后忘了特判WA了QwQ #include <cstdio> #include <algorithm> #include <cstring> ...

  6. 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T3(贪心)

    是一道水题 虽然看起来像是DP,但其实是贪心 扫一遍就A了 QwQ #include <cstdio> #include <algorithm> #include <cs ...

  7. 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T2(模拟)

    题目要求很简单,做法很粗暴 直接扫一遍即可 注意结果会爆int #include <cstdio> #include <algorithm> #include <cstr ...

  8. 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T1(找规律)

    就是找一下规律 但是奈何昨天晚上脑子抽 推错了一项QwQ 然后重新一想 A掉了QwQ #include <cstdio> #include <algorithm> #inclu ...

  9. Codeforces Manthan, Codefest 18 (rated, Div. 1 + Div. 2) D,E

    D. Valid BFS? time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

随机推荐

  1. Aizu/Aoj 0121 Seven Puzzle

    这题应该算是经典的八数码问题的弱化版吧:给你一个4x2的方版,上面有0-7 八个数字,每次只能让编号0的方格跟他的上下左右的方格交换:所以也就是把方格0当做空格看待,每次只有空格周围的方格能够向空格处 ...

  2. 关于ShapeDrawable应用的一些介绍(下)

    我们今天接着来看一下Shape中的stroke属性,stroke其实就是边缘的意思,当我们在定义画笔的时候,有很多时候会用到 FILL 和 STROKE,前者能够画出一个实心的形状,而后者就画出一个空 ...

  3. 软件开发 —— 重构(refactor)

    0. 代码坏味道 Large Class,过大的类:Large method,过长的(成员)函数: 1. 基本内涵 在不改变代码外在行为的前提下对代码做出修改,以改进代码的内部结构的过程. -- &l ...

  4. [.Net] 导出Excel中身份证等数字串的解决方式

    public static void DataTableToExcel(System.Data.DataTable dtData, String FileName) { GridView dgExpo ...

  5. Java基础学习分享

    一.Java介绍 Java是由原Sun公司(现已被甲骨文公司收购)于1991年开发的编程语言,初衷是为智能家电的程序设计提供一个分布式代码系统.为了使整个系统与平台无关,采用了虚拟机器码方式,虚拟机内 ...

  6. 爬虫—分析Ajax爬取今日头条图片

    以今日头条为例分析Ajax请求抓取网页数据.本次抓取今日头条的街拍关键字对应的图片,并保存到本地 一,分析 打开今日头条主页,在搜索框中输入街拍二字,打开开发者工具,发现浏览器显示的数据不在其源码里面 ...

  7. 9.18[XJOI] NOIP训练36

    ***在休息了周末两天(好吧其实只有半天),又一次投入了学车的怀抱,重新窝在这个熟悉的机房 今日9.18(今天以后决定不写打卡了) 日常一日总结 一个昏昏欲睡的早晨 打了一套不知道是谁出的题目,空间限 ...

  8. 本地sql文件导入mysql数据库

    mysql中配置my.ini interactive_timeout = 120 wait_timeout = 120 max_allowed_packet = 32M 导入sql运行命令 sourc ...

  9. RAP开发入门-布局管理

    布局类继承关系 FillLayout  new FillLayout(SWT.VERTICAL/HORIZONTAL)设置竖直/水平填充 RowLayout wrap折行显示.pack自适应布局(布局 ...

  10. RAP开发入门-开发笔记-bug记录

    NamespaceException: The alias '/rwt-resources' is already in use 该bug发生的第一种情况是: This means that more ...