题目链接:

https://cn.vjudge.net/problem/34398/origin

题目比较简单,就是水题,基础贪心,大于所需的即可:

AC代码:

打表:

#include <cmath>
#include <iostream>
#include <cstdio>
#define ll long long using namespace std;
const int MX = ;
ll mp[MX]; void get_table() //打一个2^n的表即可
{
for(int i = ; i <= ; ++i)
{
mp[i] = pow(, i);
}
} int main()
{
int k = ;
get_table();
ll n;
while(scanf("%lld", &n) != EOF && (n > ))
{
k++;
for(int i = ; i <= ; ++i)
{
if(mp[i] >= n) //判断一下,如果2^i大于等于则足够copy完。
{
printf("Case %d: %d\n", k, i);
break;
} }
}
}

快速幂:

#include <iostream>
#include <cstdio>
#define ll long long using namespace std;
ll poww(ll a, ll b)
{
ll ans = , base = a;
while(b)
{
if(b& != )
ans *= base;
base *= base;
b >>= ;
}
return ans;
} int main()
{
int k = ;
ll n;
while(scanf("%lld", &n) != EOF && (n > ))
{
k++;
//printf("%lld\n", poww(2, n));
if(n == )
{
printf("Case %d: 0\n", k);
continue;
}
for(int i = ; i <= ; ++i)
{
if(poww(, i) >= n)
{
printf("Case %d: %d\n", k, i);
break;
}
}
}
}

如有疑问,欢迎评论指出!

贪心,打表(或者快速幂), UVA - 11636的更多相关文章

  1. upc.2219: A^X mod P(打表 && 超越快速幂(in some ways))

    2219: A^X mod P Time Limit: 5 Sec  Memory Limit: 128 MB Submit: 417  Solved: 68 [Submit][Status][Web ...

  2. HDU-6030 Happy Necklace 打表+矩阵快速幂

    Happy Necklace 前天个人赛规律都找出来了,n的范围是\(10^{18}\),我一想GG,肯定是矩阵快速幂,然后就放弃了. 昨天学了一下矩阵快速幂. 题意 现在小Q要为他的女朋友一个有n个 ...

  3. [原]sdut2605 A^X mod P 山东省第四届ACM省赛(打表,快速幂模思想,哈希)

    本文出自:http://blog.csdn.net/svitter 题意: f(x) = K, x = 1 f(x) = (a*f(x-1) + b)%m , x > 1 求出( A^(f(1) ...

  4. 矩阵快速幂 UVA 10870 Recurrences

    题目传送门 题意:f(n) = a1f(n − 1) + a2f(n − 2) + a3f(n − 3) + . . . + adf(n − d), for n > d,求f (n) % m.训 ...

  5. What day is that day?(快速幂,打表找周期,或者求通项公式)

    有些题怎么都解不出来,这时候可以打表,找规律,求通项公式等,这些方法让人拍手叫绝,真不错…… Description It's Saturday today, what day is it after ...

  6. HDU4887_Endless Punishment_BSGS+矩阵快速幂+哈希表

    2014多校第一题,当时几百个人交没人过,我也暴力交了几发,果然不行. 比完了去学习了BSGS才懂! 题目:http://acm.hdu.edu.cn/showproblem.php?pid=4887 ...

  7. POJ-3070Fibonacci(矩阵快速幂求Fibonacci数列) uva 10689 Yet another Number Sequence【矩阵快速幂】

    典型的两道矩阵快速幂求斐波那契数列 POJ 那是 默认a=0,b=1 UVA 一般情况是 斐波那契f(n)=(n-1)次幂情况下的(ans.m[0][0] * b + ans.m[0][1] * a) ...

  8. ACM-ICPC 2018 焦作赛区网络预赛 G. Give Candies (打表找规律+快速幂)

    题目链接:https://nanti.jisuanke.com/t/31716 题目大意:有n个孩子和n个糖果,现在让n个孩子排成一列,一个一个发糖果,每个孩子随机挑选x个糖果给他,x>=1,直 ...

  9. Codeforces1062C. Banh-mi(贪心+快速幂)

    题目链接:传送门 题目: C. Banh-mi time limit per test second memory limit per test megabytes input standard in ...

随机推荐

  1. 使用Eclipse、Tomcat遇到的一些问题

    Tomcat服务无法启动 前两天瞎搞,试着弄了弄Android的环境.结果不知道动了什么地方,Tomcat崩了,本地打开localhost:8080一直显示404,eclipse也无法使用Tomcat ...

  2. jQuery绑定或删除绑定事件

    <!DOCTYPE html><html lang="en" class="loading"><head> <meta ...

  3. jQuery筛选器常用总结

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  4. 使用Calendar获取上一月,下一月,上一年,下一年的当天日期

    Calendar的add(int field,int amount)方法 field 表示月或年,天等字段 amount 代表增量或减量 例如: 上月的当天日期  Calendar cal = Cal ...

  5. windows下使用Play框架

         play类似于Spring这里的web框架.特点:MVC.函数编程. 版本:play 2.1.3 一.play命令 #play ~compile 功能:持续编译.在cmd中运行这个命令,只要 ...

  6. 微信小程序--代码构成---JSON 配置

    在上一章中,我们通过开发者工具快速创建了一个 QuickStart 项目.你可以留意到这个项目里边生成了不同类型的文件: .json 后缀的 JSON 配置文件 .wxml 后缀的 WXML 模板文件 ...

  7. mybatis + oracle insert clob,出现ORA-01461:仅能绑定要插入LONG列的LONG值

    在网上查了很久,有可能问题是出现在当从dual中取数据时,会将clob对象的字段转为Long型 最后的解决方法用到了Begin和end语法: 1.用到begin 和end 2.用到insert int ...

  8. Python自定义-分页器

    Python自定义-分页器 分页功能在每个网站都是必要的,对于分页来说,其实就是根据用户的输入计算出应该在数据库表中的起始位置. 1.设定每页显示数据条数 2.用户输入页码(第一页.第二页...) 3 ...

  9. cmake方式使用vlfeat

    目录 environment statement compile vlfeat with cmake compile example project with cmake 1. make sure c ...

  10. Javascript \x 反斜杠x 16进制 编解码

    js 里 \x 开头的通常是16进制编码的数据,下面代码实现编解码: 解码 function decode(str){ return str.replace(/\\x(\w{2})/g,functio ...