Kattis - cokolada【水】
Kattis - cokolada【水】
题意
有一个人想吃巧克力,但是巧克力都是按照 2 的幂次的数量包装的,然后他想吃一定数量块的巧克力,然后可以敲碎,每次敲碎都分成两半,比如四块装的分成两块就是二块和二块,但是只能买一块,求要买的那块的数量,和要敲几次
思路
因为数据比较小,可以先打一个 2 的幂次的表,然后二分查找最少的那个数量,然后每次都剪掉一半,然后往下找,直到减为0 就跳出 然后用 大的减最小的那个数 就可以了
AC代码
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <cstdlib>
#include <ctype.h>
#include <numeric>
#include <sstream>
using namespace std;
typedef long long LL;
const double PI = 3.14159265358979323846264338327;
const double E = 2.718281828459;
const double eps = 1e-6;
const int MAXN = 0x3f3f3f3f;
const int MINN = 0xc0c0c0c0;
const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7;
int vis[21];
int k, ans, flag;
int main()
{
for (int i = 0; i < 21; i++)
vis[i] = 1 << i;
cin >> k;
for (int i = 0; i < 21; i++)
{
if (vis[i] >= k)
{
ans = vis[i];
flag = i;
break;
}
}
if (vis[flag] == k)
printf("%d %d\n", ans, 0);
else if (k % 2)
printf("%d %d\n", ans, flag);
else
{
k -= ans/2;
int i;
for (i = flag; i >= 0; i--)
{
if (k >= vis[i])
k -= vis[i];
if (k == 0)
break;
}
printf("%d %d\n", ans, flag - i);
}
}
Kattis - cokolada【水】的更多相关文章
- Kattis - abc 【水】
题意 给出三个数,然后给出一个顺序,有ABC三个字母构成, A是最大的数字 B是中间的数字 C是最小的数字 根据 ABC的顺序 给出 数字的顺序 思路 先排序一下,然后用 MAP 双向标记一下 AC代 ...
- Kattis - register 【水】
题意 就是 有一堆容器,然后可以执行加的操作,每个容量是 2, 3, 5, 7, 11, 13, 17, 19 然后 有进位 比如第一个 容器,到2了,就会重置为0,然后 下一个容器+ 1, 但是要保 ...
- E - Emptying the Baltic Kattis - emptyingbaltic (dijkstra堆优化)
题目链接: E - Emptying the Baltic Kattis - emptyingbaltic 题目大意:n*m的地图, 每个格子有一个海拔高度, 当海拔<0的时候有水. 现在在(x ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- Openjudge 1.13-21:最大质因子序列(每日两水)
总时间限制: 1000ms 内存限制: 65536kB 描述 任意输入两个正整数m, n (1 < m < n <= 5000),依次输出m到n之间每个数的最大质因子(包括m和n ...
- [LeetCode] Container With Most Water 装最多水的容器
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- 如何装最多的水? — leetcode 11. Container With Most Water
炎炎夏日,还是呆在空调房里切切题吧. Container With Most Water,题意其实有点噱头,简化下就是,给一个数组,恩,就叫 height 吧,从中任选两项 i 和 j(i <= ...
- Codeforces 刷水记录
Codeforces-566F 题目大意:给出一个有序数列a,这个数列中每两个数,如果满足一个数能整除另一个数,则这两个数中间是有一条边的,现在有这样的图,求最大联通子图. 题解:并不需要把图搞出来, ...
- Bzoj3041 水叮当的舞步
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 132 Solved: 75 Description 水叮当得到了一块五颜六色的格子形地毯作为生日礼物 ...
随机推荐
- datagrid多复选框
<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>Ch ...
- pycharm重置设置,恢复默认设置
备忘,备忘,备忘 window 系统 找到下方目录-->删除. 再重新打开pycharm # Windows Vista, 7, 8, 10: <SYSTEM DRIVE>\User ...
- JSP页面之间传递参数的方法有哪些?
JSP页面之间传递参数的方法有哪些? 解答: 1)request 2)session 3)application 4)提交表单 5)超链接
- (转)Java锁、自旋锁、CAS机制
转自:http://www.jb51.net/article/55381.htm 转自:http://blog.csdn.net/aesop_wubo/article/details/7537278 ...
- DIV高度设置全屏
<div class="full"></div> .full{ height:100%; position:fixed; } 使用position的fixe ...
- eclipse ${user}和${date}
在Eclipse中使用类的自动注释时,@author ${user}, 这个值不会随着你更改系统用户名而改变.有的人会将这个 ${user} 变量直接替换为某个固定名称. 以下方法可以修改它的值. 在 ...
- 72、android状态栏一体化,状态栏改变颜色
只能在4.4以上版本使用. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&q ...
- python之range和xrange
range 前面小节已经说明了,range([start,] stop[, step]),根据start与stop指定的范围以及step设定的步长,生成一个序列. 比如: 1 >>> ...
- Caused by: com.mysql.cj.core.exceptions.InvalidConnectionAttributeException: The server time zone value '�й���ʱ��' is unrecognized or represents more than one time zone. You must configure either the
mysql6.0里面改成新的配置方式: hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect #old #driverClassNam ...
- [LintCode] 尾部的零
class Solution { public: // param n : description of n // return: description of return long long tr ...