一、Javabeans

原题:

Description

Javabeans are delicious. Javaman likes to eat javabeans very much.

Javaman has n boxes of javabeans. There are exactly i javabeans in thei-th box (i = 1, 2, 3,...n). Everyday Javaman chooses an integerx. He also chooses several boxes where the numbers of javabeans are all at leastx. Then he eats x javabeans in each box he has just chosen. Javaman wants to eat all the javabeans up as soon as possible.  So how many days it costs for him to eat all the javabeans?

Input

There are multiple test cases. The first line of input is an integer T ≈ 100 indicating the number of test cases.

Each test case is a line of a positive integer 0 < n < 231.

Output

For each test case output the result in a single line.

Sample Input

4 1 2 3 4 

Sample Output

1 2 2 3 

分析:

找规律问题~~~

原码:

#include<stdio.h> #include<math.h> int p(int x) {     int sum=0;     while(x/=2)     {         sum++;     }     return sum; } int main() {     int m,n,f;
    scanf("%d",&m);     while(m--)     {         scanf("%d",&n);         f=p(n);         printf("%d\n",f);     }     return 0; }   

二、water-easy

原题:

Description

Problem A
Hello World!
Input:
Standard Input

Output: Standard Output

When you first made the computer to print the sentence “Hello World!”, you felt so happy, not knowing how complex and interesting the world of programming and algorithm will turn out to be. Then you did not know anything about loops, so to print 7 lines of “Hello World!”, you just had to copy and paste some lines. If you were intelligent enough, you could make a code that prints “Hello World!” 7 times, using just 3 paste commands. Note that we are not interested about the number of copy commands required. A simple program that prints “Hello World!” is shown in Figure 1. By copying the single print statement and pasting it we get a program that prints two “Hello World!” lines. Then copying these two print statements and pasting them, we get a program that prints four “Hello World!” lines. Then copying three of these four statements and pasting them we can get a program that prints seven “Hello World!” lines (Figure 4). So three pastes commands are needed in total and Of course you are not allowed to delete any line after pasting. Given the number of “Hello World!” lines you need to print, you will have to find out the minimum number of pastes required to make that program from the origin program shown in Figure 1.

Figure 1

Figure 2

Figure3

Figure 4

Input

The input file can contain up to 2000 lines of inputs. Each line contains an integer N (0<N<10001) that denotes the number of “Hello World!” lines are required to be printed.

Input is terminated by a line containing a negative integer.

Output

For each line of input except the last one, produce one line of output of the form “Case X: Y” where X is the serial of output and Y denotes the minimum number of paste commands required to make a program that prints N lines of “Hello World!”.

 

 

Sample Input                             Output for Sample Input

2

10

-1

Case 1: 1

Case  2: 4

原码:

#include<stdio.h> #include<math.h> int p(int x) {     int n=0;     while(x/=2)     {         n++;     }     return n; } int main() {     int t,n,count=1;     while(scanf("%d",&t)!=EOF&&t>=0)     {         n=p(t);         int m=pow(2,n);         if(m!=t)             printf("Case %d: %d\n",count++,n+1);         else printf("Case %d: %d\n",count++,n);     }     return 0; } 

转载于:https://blog.51cto.com/bingsanchun/1271356

两道相似题——water-easyJavabeans相关推荐

  1. BAT七年经验,却抵不过外企面试的两道算法题?

    整理| 琥珀 出品| AI科技大本营 又遇年底跳槽季,如果你曾在 BAT 等互联网大厂有过较为丰富的工作经验,想要换份工作,面试时会主要考虑哪些因素? 面试外企,却被两道算法题难住? 近日,一位网友在 ...

  2. 两道概率题-供大家周末把玩

    两道概率题-供大家周末把玩 题目 1.给定一个函数rand5(),该函数能等概率生成1-5之间的整数(包括1和5),如何用该函数等概率生成整数1-7? 解法 本以为很简单,做了以后才发现其实并不简单, ...

  3. BAT 七年经验,却抵不过外企面试的两道算法题?

    整理| 琥珀 出品| AI科技大本营 又遇年底跳槽季,如果你曾在 BAT 等互联网大厂有过较为丰富的工作经验,想要换份工作,面试时会主要考虑哪些因素? 面试外企,却被两道算法题难住? 近日,一位网友在 ...

  4. 【算法】两道算法题根据提供字母解决解码方法和城市的天际线天际线问题

    算法目录 解码方法 Java解答参考: 天际线问题 Java解答参考: 大家好,我是小冷. 上一篇了解了项目相关的知识点 接下来看下两道算法题吧,用Java解答,可能更能激发一下大脑思考. 解码方法 ...

  5. 51信用卡两道编程题

    51信用卡两道编程题 1>输入一串字符,判断第二个字符串的字符是否都存在于第一个字符串,返回true,否则false,两个串中间有;号连接 如输入: ABCNB51;51NB 输出:true 解 ...

  6. 2016恒生电子秋招笔试两道算法题

    2016恒生电子笔试两道算法题 1.求出1到100之间所有素数,要求时间复杂度最优. 我的最优解决方案是吧素数一个个放入一个素数数组里面(初始吧2放进去),后面的数只要判断是否能够整除这个素数数组里面 ...

  7. 【蓝桥杯】每日四道填空题(两道真题+两道模拟题)| 第三天

    专栏: 蓝桥杯--每日四道填空题(两道真题+两道模拟题) &离蓝桥杯已经不到一个月时间了,赶快刷起来吧,填空题一定别丢分!! ୧꒰•̀ᴗ•́꒱୨ 另一个专栏是: 蓝桥杯--编程题刷题营(每日四 ...

  8. 2014年阿里巴巴校园招聘两道算法题

    昨天阿里巴巴校园招聘在线测试,总的来说算法题比较简单,至于前面的选择题不是本人的强项,个人感觉比较难.下面我们说说两道算法题: 第一题大意是有一个quary和text要求找出两者匹配最长的字符串的长度 ...

  9. 这两道大厂题,让我偶然发现百度的小彩蛋

    点击上方"程序员黑叔",选择"置顶或者星标" 你的关注意义重大! 文/黑叔 阅读本文需要 3分钟 前言 最近,好像面试文满天飞,瞄了一眼后,动不动就手写各类函数 ...

  10. lucky前面加a还是an_“不可数”名词前何时加a/an,何时不加?来自本站教师群的两道典型题问答,揭示了规律 白话英语201931...

    白话英语系列文章2018年总目录(含2017.2016年总目录)以下问答,均来自由我主持的"研究型中学英语教师"和"研究型小学英语教师"两个微信群的日常探讨.问 ...

最新文章

  1. max_semi_space_size 设置值与实际值不一致的原因分析
  2. Spring的Java配置方式
  3. springboot Serving Web Content with Spring MVC
  4. 网银安全恐慌“后遗症”凸显 肉鸡检测器下载量近百万
  5. Linux进程终止命令kill或killall​笔记
  6. 页面滚动事件无效小记
  7. 链表反转的两种实现方法,后一种击败了100%的用户
  8. ack过来服务器未响应,DHCP服务器问题:抓不到ACK包
  9. 如何启动一个Vue3.x项目
  10. 我的世界学园都市java_我的世界学园都市地图
  11. ADS仿真学习:s2p文件导入ADS
  12. 蜂窝教育:果粉们,上班玩手机的注意了
  13. 蚂蚁金服2019实习生面经总结(已拿口头offer)
  14. js-原生Js汉语拼音首字母匹配城市名
  15. OA(二)编写基本的CURD
  16. 好看的个人网站源码_新手想建个人网站,都要注意哪些关于自助建站源码的坑?...
  17. 移动互联网时代必读十大图书
  18. Excl2016密码忘记 破解办法
  19. “最牛愤青教授”郑强叫板当代教育
  20. 哈尔滨工业大学计算机系统大作业

热门文章

  1. BUGKU 密码题:这不是摩斯密码
  2. Docker for Linux 安装
  3. 无法找到“XXX.exe”的调试信息,或者调试信息不匹配。未使用调试信息生成二进制文件...
  4. 第一个使用Spring Tool Suite(STS)和Maven建立的Spring mvc 项目
  5. Checked ==true ? Y:N ;
  6. 《Code Complete》ch.15 使用条件语句
  7. 百度PRNN:增强GPU伸缩性,RNN训练最高提速30倍(源码下载)
  8. 残差学习,152层网络,微软夺冠2015 ImageNet计算机视觉识别挑战
  9. Linux的notifier机制在TP中的应用【转】
  10. Windows Service方式启动的Tomcat如何配置PermGen Space