【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 ...
随机推荐
- 開始搭建第一个zookeeper
首先须要下载zookeeper的tar包.地址为http://zookeeper.apache.org,然后再linux中解压并编译tar包. # tar-xvzf zookeeper-3.4.5.t ...
- 基于ActiveMQ的消息中间件系统逻辑与物理架构设计具体解释
1. 基本介绍与组件架构图 维基百科对消息中间件的定义是"Message-oriented Middleware is software infrastructure focused on ...
- 寻找不到iframe元素
一直找不到元素,是因为有两层iframe的 找iFrame元素方法如下 1.iFrame有ID 或者 name的情况//进入id="frame1"的frame中,定位id=&quo ...
- PHP反射类的理解(代码篇)
<?php/** * Created by PhpStorm. * User: * Date: 2017/6/12 * Time: 14:34 * 关于反射类的理解 */class Person ...
- luogu2606 排列计数
题目大意 求满足下列条件的排列$P$的数量:$\forall P_i, P_i>P_{\lfloor \frac{i}{2}\rfloor}$. 思路 从下标入手 反过来想,也就是对$\fora ...
- 【撸码caffe 三】 caffe.cpp
caffe.cpp文件完成对网络模型以及模型配置参数的读入和提取,提供了网络模型训练的入口函数train和对模型的测试入口函数test.文件中使用了很多gflags和glog指令,gflags是goo ...
- Sublime Text 2 界面主题 推荐 Flatland
先搜索下THEME-FLATLAND 安装完后在preferences中选择settings-usr { "color_scheme": "Packages/Theme ...
- webpack到底怎么用?
webpack到底怎么用? https://www.zhihu.com/question/39290543
- mysql视图,索引和存储过程
一:视图 视图又叫虚表.同真实的表一样,视图包含一系列带有名称的列和行数据.但是,视图并不在数据库中以存储的数据值集形式存在.行和列数据来自由定义视图的查询所引用的表,并且在引用视图时动态生成. 具体 ...
- My first blog for java
我的第一个java程序: package com.hellojava; /** * @author 沽-名-钓-誉 */ public class HelloJava{ /** * @param 输出 ...