当前位置:网站首页>#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.
边栏推荐
- Flume面试题
- Mask wearing detection method based on yolov5
- 辅音和声母的区别?(声母与辅音的区别)
- Is PMP certificate really useful?
- [live broadcast review] the first 8 live broadcasts of battle code Pioneer have come to a perfect end. Please look forward to the next one!
- 完全注解的ssm框架搭建
- PHP reflective XSS, reflective XSS test and repair
- C中main函数的几种写法
- Show member variables and methods in classes in idea
- What is the difference between consonants and Initials? (difference between initials and consonants)
猜你喜欢
One of the basic learning of function
MySQL系列之事务日志Redo log学习笔记
"The silk road is in its youth and looks at Fujian" is in the hot collection of works in the Fujian foreign youth short video competition
【深度学习】利用深度学习监控女朋友的微信聊天?
Significance and measures of security encryption of industrial control equipment
Yan Rong looks at how to formulate a multi cloud strategy in the era of hybrid cloud
[intelligent QBD risk assessment tool] Shanghai daoning brings you leanqbd introduction, trial and tutorial
Sonic云真机学习总结6 - 1.4.1服务端、agent端部署
mysql 学习笔记-优化之SQL优化
[noip2013] building block competition [noip2018] road laying greed / difference
随机推荐
名单揭晓 | 2021年度中国杰出知识产权服务团队
Spark面试题
MySQL系列之事务日志Redo log学习笔记
Icml2022 | interventional contrastive learning based on meta semantic regularization
【MySQL】数据库优化方法
同花顺股票开户选哪个券商好手机开户是安全么?
游览器打开摄像头案例
Pytest collection (2) - pytest operation mode
Can I choose to open an account for stock trading on flush? Is it safe?
Aidl basic use
CNN卷积神经网络原理讲解+图片识别应用(附源码)[通俗易懂]
测试撤销1
[deep learning] use deep learning to monitor your girlfriend's wechat chat?
String类型转换BigDecimal、Date类型
MySQL之MHA高可用配置及故障切换
【MySQL】explain的基本使用以及各列的作用
详解Volatile关键字
Use of vscode
Is PMP certificate really useful?
工控设备安全加密的意义和措施