(http://leetcode.com/2011/01/ctrla-ctrlc-ctrlv.html)

Imagine you have a special keyboard with the following keys:

A

Ctrl + A

Ctrl + C

Ctrl + V

where CTRL+A, CTRL+C, CTRL+V each acts as one function key for "Select All", "Copy", and "Paste" operations respectively.

If you can only press the keyboard for N times (with the above four keys), please write a program to produce maximum numbers of A. If possible, please also print out the sequence of keys.

That is to say, the input parameter is N (No. of keys that you can press), the output is M (No. of As that you can produce).

The Code:

int findMaxK(int n)
{
int power = ;
double max = 0.0;
int maxK = ;
while (n > )
{
n -= ;
double t = (double)n/power;
double r = pow(t, (double)power);
if (r > max)
{
maxK = power;
max = r;
}
power++;
}
return maxK;
} unsigned int f(int n)
{
if (n <= )
return n;
int k = findMaxK(n); int sum = n - *(k-);
unsigned int mul = ;
while (k > )
{
int avg = sum/k;
mul *= avg;
k--;
sum -= avg;
}
assert(sum == ); return mul;
}

CTRL+A, CTRL+C, CTRL+V的更多相关文章

  1. 转--Eclipse中ctrl+shift+r与ctrl+shift+t的区别

    Eclipse中ctrl+shift+r与ctrl+shift+t的区别 标签: 快捷键工作区文件搜索打开资源文件 2016-09-13 15:44 292人阅读 评论(0) 收藏 举报  分类: e ...

  2. centos 目录结构 快捷键 ls命令,alias别名,so:动态库 a:静态库,环境变量PATH,Ctrl+z 暂停命令,Ctrl+a 光标到行首,Ctrl+e 光标到行尾,Ctrl+u 删除光标前所有字符 Ctrl+r 搜索命 hash命令 Ctrl+左箭头/右箭头 cd命令 第三节课

    centos 目录结构 快捷键 ls命令,alias别名,so:动态库 a:静态库,环境变量PATH,Ctrl+z 暂停命令,Ctrl+a 光标到行首,Ctrl+e 光标到行尾,Ctrl+u 删除光标 ...

  3. Java开发环境之------MyEclipse快捷键和排除错误第一选择ctrl+1(***重点***:ctrl+1,快速修复---有点像vs中的快速using

    using Java开发环境之------MyEclipse快捷键和排除错误第一选择ctrl+1(***重点***:ctrl+1,快速修复---有点像vs中的快速using 2015-06-29 浏览 ...

  4. ubuntu打开终端多开标签的快捷键是ctrl+ shift+ T 对比ctrl+ alt+ T 另外窗口打开一个终端

    ubuntu打开终端多开标签的快捷键是ctrl+ shift+ T 对比ctrl+ alt+ T 另外窗口打开一个终端

  5. 任务管理器 用 Ctrl + Shift + Esc 替换 Ctrl + Alt + Del

    任务管理器 用 Ctrl + Shift + Esc 替换 Ctrl + Alt + Del

  6. IntelliJ 中类似于Eclipse ctrl+q的是Ctrl+Shift+Backspace

    IntelliJ 中类似于Eclipse ctrl+q的是Ctrl+Shift+Backspace 回到刚刚编辑的地方: ctrl+alt+Left 是回到刚刚浏览的地方,不一定是编辑的地方,可能已经 ...

  7. IntelliJ 中类似于Eclipse ctrl+o的是ctrl+F12

    IntelliJ 中类似于Eclipse ctrl+o的是ctrl+F12 学习了:https://blog.csdn.net/sjzylc/article/details/47979815

  8. Spring Tool Suite4(sts)复制粘贴卡顿(ctrl+v, ctrl+c)、按住ctrl也很卡

    最近在看<Spring in Action, Fifth Edition>,下载了Spring Tool Suite4,在使用的过程中发现了一些问题: 只要在复制粘贴(ctrl+c, ct ...

  9. delphi 修改代码补全的快捷键(由Ctrl+Space 改为 Ctrl + alt + Space)(通过修改OpenTool生效)

    delphi 的IDE快捷键与输入法切换键中突,以往的解决方法是下载一个ImeTool修改 windows 系统的快捷键 在 xp win7 都好使,但在win 10经常是修改完后,重启又失效了. 本 ...

  10. delphi 修改代码补全的快捷键(由Ctrl+Space 改为 Ctrl + alt + Space)

    delphi 的IDE快捷键与输入法切换键中突,以往的解决方法是下载一个ImeTool修改 windows 系统的快捷键 在 xp win7 都好使,但在win 10经常是修改完后,重启又失效了. 本 ...

随机推荐

  1. (13)[Xamarin.Android] 不同分辨率下的图片使用概论

    原文 [Xamarin.Android] 不同分辨率下的图片使用概论 设计Android App的时候,其尺寸众多也是一个挑战之一.要针对不同尺寸设计Android App时,就要先来了一下dpi(d ...

  2. HTML标签CSS属性默认值汇总

    HTML标签CSS属性默认值,在你需要还原默认值的时候比较有用. 以前一直在找这份文档,今天偶然在网上看到了.除了inline和block的定义,主要是要注意body|h1~h6|blockquote ...

  3. at org.apache.jsp.index_jsp._jspInit(index_jsp.java:23)异常解决

    部署项目,启动tomcat一切正常.输入项目地址后 tomcat报例如以下错误: java.lang.NullPointerException at org.apache.jsp.index_jsp. ...

  4. _视图控制对象生命周期-init、viewDidLoad、viewWillAppear、viewDidAppear、viewWillDisappear等的区别及用途

    iOS视图控制对象生命周期-init.viewDidLoad.viewWillAppear.viewDidAppear.viewWillDisappear.viewDidDisappear的区别及用途 ...

  5. c# 针对不同数据库进行参数化查询

    使用参数化 DbCommand 的一个缺点是需要参数的代码将仅适用于支持相同语法的提供程序.OLEDB.SqlClient 和 Oracle 提供程序全部使用不同的语法.例如,用于命名和指定参数的 S ...

  6. 学习ExtjsFor.NET(第二个案例-Array的Every方法)

    Ext.Array.every(Array array,Function fn,Object scope)是一个遍历的方法. array是数组,fn是方法,scope是作用域.every返回true和 ...

  7. UpdatePanel + 弹出框

    ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "", "alert('操作成功!') ...

  8. C#中的ref与out参数(本文仅作为个人笔记)

    假如一个方法的参数(形参)是引用类型,那么使用那个参数来进行的任何修改都会改变参数引用的数据.但这里的关键在于,虽然引用的数据发生了变化,但参数本生没有改变——它仍然引用的是一个对象.换句话说,虽然可 ...

  9. malloc 申请得到的内存后,再 free 释放它的时候,操作系统会立即收回那块内存吗?

    stackoverflow上的回答: In many malloc/free implementations, free does normally not return the memory to  ...

  10. calltree看代码调用图

    calltree是在linux下面看c代码(尤其是复杂的内核代码)的神器. 推荐  calltree+vim + ctags + cscope + taglist [ vim: 搭建vim看代码的环境 ...