当前位置:网站首页>#yyds干货盘点# 解决名企真题:扭蛋机
#yyds干货盘点# 解决名企真题:扭蛋机
2022-07-01 21:44:00 【51CTO】
1.简述:
描述
22娘和33娘接到了小电视君的扭蛋任务:
一共有两台扭蛋机,编号分别为扭蛋机2号和扭蛋机3号,22娘使用扭蛋机2号,33娘使用扭蛋机3号。
扭蛋机都不需要投币,但有一项特殊能力:
扭蛋机2号:如果塞x(x范围为>=0整数)个扭蛋进去,然后就可以扭到2x+1个
扭蛋机3号:如果塞x(x范围为>=0整数)个扭蛋进去,然后就可以扭到2x+2个
22娘和33娘手中没有扭蛋,需要你帮她们设计一个方案,两人“轮流扭”(谁先开始不限,扭到的蛋可以交给对方使用),用“最少”的次数,使她们能够最后恰好扭到N个交给小电视君。
输入描述:
输入一个正整数,表示小电视君需要的N个扭蛋。
输出描述:
输出一个字符串,每个字符表示扭蛋机,字符只能包含"2"和"3"。
示例1
输入:
输出:
2.代码实现:
import java.util.*;
import java.io.*;
public class Main{
public static void main(String[] args){
Scanner cin = new Scanner(new BufferedInputStream(System.in));
int n = cin.nextInt();
StringBuilder ans = new StringBuilder();
while(n!=0){
if((n&1)==1){
n=(n-1)/2;
ans.append('2');
}else{
n=(n-2)/2;
ans.append('3');
}
}
System.out.println(ans.reverse());
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
边栏推荐
- PHP reflective XSS, reflective XSS test and repair
- AIDL基本使用
- Difference and use between require and import
- Chapter 9 Yunji datacanvas company has been ranked top 3 in China's machine learning platform market
- 信标委云原生专题组组长,任重道远!
- 从MLPerf谈起:如何引领AI加速器的下一波浪潮
- 名单揭晓 | 2021年度中国杰出知识产权服务团队
- 91.(cesium篇)cesium火箭发射模拟
- 【深度学习】利用深度学习监控女朋友的微信聊天?
- Why does blocprovider feel similar to provider?
猜你喜欢

Introduction à l'ingénierie logicielle (sixième édition) notes d'examen de Zhang haifan

上半年暂停考试要补考?包含监理工程师、建筑师等十项考试

手动实现function isInstanceOf(child,Parent)

Chapter 9 Yunji datacanvas company has been ranked top 3 in China's machine learning platform market

pytest合集(2)— pytest运行方式

Manually implement function isinstanceof (child, parent)

Spark interview questions

Classify boost libraries by function
![[NOIP2013]积木大赛 [NOIP2018]道路铺设 贪心/差分](/img/d1/a56231cd4eb3cc1d91d8a55048ccfe.png)
[NOIP2013]积木大赛 [NOIP2018]道路铺设 贪心/差分

MIT|256KB 内存下的设备上训练
随机推荐
地图其他篇总目录
[STM32] stm32cubemx tutorial II - basic use (new projects light up LED lights)
Can I choose to open an account for stock trading on flush? Is it safe?
MIT|256KB 内存下的设备上训练
linux下清理系统缓存并释放内存
List announced | outstanding intellectual property service team in China in 2021
Mask wearing detection method based on yolov5
一次调试去了解redis集群的slot机制
Which securities company should we choose to open an account for flush stock? Is it safe to open an account with a mobile phone?
burpsuite简单抓包教程[通俗易懂]
统计字符中每个字符出现的个数
CNN convolution neural network principle explanation + image recognition application (with source code) [easy to understand]
面试题:MySQL的union all和union有什么区别、MySQL有哪几种join方式(阿里面试题)[通俗易懂]
Do you want to make up for the suspended examination in the first half of the year? Including ten examinations for supervision engineers, architects, etc
Pytest Collection (2) - mode de fonctionnement pytest
Go - exe corresponding to related dependency
Yan Rong looks at how to formulate a multi cloud strategy in the era of hybrid cloud
MQ learning notes
[intelligent QBD risk assessment tool] Shanghai daoning brings you leanqbd introduction, trial and tutorial
Application of real estate management based on 3D GIS