【Manthan, Codefest 18 (rated, Div. 1 + Div. 2) A】Packets
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
多重背包的二进制优化。
就是将数量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的更多相关文章
- 【Manthan, Codefest 18 (rated, Div. 1 + Div. 2) C】Equalize
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] Swap操作显然只能对(i-1,i)执行才有用. 不然直接将i翻转以及j翻转 显然比直接交换更优. 那么现在我们就相当于有两种操作. ...
- 【Manthan, Codefest 18 (rated, Div. 1 + Div. 2) B】Reach Median
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 将数组排序一下. 考虑中位数a[mid] 如果a[mid]==s直接输出0 如果a[mid]<s,那么我们把a[mid]改成s ...
- 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 ...
- 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T5(思维)
还是dfs? 好像自己写的有锅 过不去 看了题解修改了才过qwq #include <cstdio> #include <algorithm> #include <cst ...
- 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T4(模拟)
随便模拟下就过了qwq 然后忘了特判WA了QwQ #include <cstdio> #include <algorithm> #include <cstring> ...
- 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T3(贪心)
是一道水题 虽然看起来像是DP,但其实是贪心 扫一遍就A了 QwQ #include <cstdio> #include <algorithm> #include <cs ...
- 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T2(模拟)
题目要求很简单,做法很粗暴 直接扫一遍即可 注意结果会爆int #include <cstdio> #include <algorithm> #include <cstr ...
- 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T1(找规律)
就是找一下规律 但是奈何昨天晚上脑子抽 推错了一项QwQ 然后重新一想 A掉了QwQ #include <cstdio> #include <algorithm> #inclu ...
- 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 ...
随机推荐
- hdoj1051Wooden Sticks
/*这道题目是先要排序的,依照长度或者重量排都能够. 当长度(重量)同样时就依照重量(长度)排, 从大到小或从小到大都能够! 这里我懂的.没有问题! 排序之后,问题就能够简化,(如果依照长度不等 ...
- 项目PMO工作
算起来.这是第一次以项目PMO人员的身份參与项目,尽管非常可惜没有从头參与,也没有參与到项目结束,仅仅有短短的两个月.但对项目PMO也可略窥一斑.如今就当个流水账写一写吧. 进项目组的时候,是中 ...
- 国产芯片任重道远 国科微SSD主控芯片的“追赶之路”(不能只提供一颗芯片,而是要将芯片、国密算法、固件Firmware、BIOS和操作系统紧密联系在一起,变成完整解决方案交给行业用户,才能真正体现自身的价值)
集微网消息,“中国芯”战略之路道阻且长,踏入这个赛道的攻坚者们需要十年如一日的技术突破,需要集合产业势能,共同协作,方能建立中国核心技术真正的竞争力. 国产化之路任重道远,SSD芯片初见成效 信息时代 ...
- 安装eclipse maven插件m2eclipse No repository found containing
m2eclipse插件是Eclipse的一款Maven插件. 安装m2eclipse插件的步骤例如以下: 启动Eclipse,在菜单条中选择Help,然后选择Install New Software- ...
- package-org.springframework.ui-interface:Model.class
ylbtech-package-org.springframework.ui-interface:Model.class 1.返回顶部 1. /* * Copyright 2002-2012 the ...
- [JavaEE] 20141228_Java类文章搜集
http://www.blogjava.net/jiangshachina 博客园java频道 Maven入门--概念与实例(原) Maven入门--较复杂的实例(原) Maven插件使用收集(原) ...
- shp系列(五)——利用C++进行shp文件的写(创建)
之前介绍了shp文件.dbf文件和shx文件的的读取,接下来将分别介绍它们的创建过程.一般来说,读和写的一一对应的,写出的文件就是为了保存数据供以后读取的.写的文件要符合shapefile的标准.之前 ...
- LVS十种调度算法介绍
1.轮叫调度(Round Robin)(简称rr) 轮叫调度(Round Robin Scheduling)算法就是以轮叫的方式依次将请求调度不同的服务器,即每次调度执行i = (i + 1) mod ...
- iOS 应用开发入门指南
前言:http://www.guomii.com/posts/20250安装工具:http://www.guomii.com/posts/20255工具:http://www.guomii.com/p ...
- Map初始化
转载至:http://blog.csdn.net/dujianxiong/article/details/54849079 第一种方法:static块初始化 public class Demo{ pr ...