日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > java >内容正文

java

两道相似题——water-easyJavabeans

發(fā)布時(shí)間:2025/7/14 java 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 两道相似题——water-easyJavabeans 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

一、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

?

分析:

找規(guī)律問題~~~

原碼:

#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; }


轉(zhuǎn)載于:https://blog.51cto.com/bingsanchun/1271356

總結(jié)

以上是生活随笔為你收集整理的两道相似题——water-easyJavabeans的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。