首页
题库
公司真题
专项练习
面试题库
在线编程
面试
面试经验
AI 模拟面试
简历
求职
学习
基础学习课
实战项目课
求职辅导课
专栏&文章
竞赛
我要招人
发布职位
发布职位、邀约牛人
更多企业解决方案
AI面试、笔试、校招、雇品
HR免费试用AI面试
最新面试提效必备
登录
/
注册
_南柯_
南阳理工学院 Java
发布于河南
关注
已关注
取消关注
@牛客451475731号:
2023·8·26京东笔试
import java.util.*;class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()) { int n = in.nextInt(); int[] nums = new int[n]; for (int i = 0; i < n; i++) { nums[i] = in.nextInt(); } get(nums); } in.close(); } public static void get(int[] nums) { HashSet<Integer> set = new HashSet<>(); int n = nums.length; int[] ans = new int[n]; for (int i = 0; i < n; i++) { int j = i + 1; int q = nums[i] % j; int tp = j - q; while (set.contains(tp)) { tp += j; } set.add(tp); ans[i] = tp; } for (int i = 0; i < n; i++) { System.out.print(ans[i] + " "); } }}// 第二题class Main2 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int num = in.nextInt(); int route = in.nextInt(); boolean[] isHuman = new boolean[num]; long[] nums = new long[num]; for (int i = 0; i < num; i++) { String tp = in.next(); if (tp.equals("human")) { isHuman[i] = true; } nums[i] = in.nextInt(); } boolean[] deads = new boolean[num]; // 开始战斗 for (int i = 0; i < route; i++) { // 输入好像有问题 try { int a = in.nextInt() - 1; int b = in.nextInt() - 1; String ac = in.next(); String bc = in.next(); // 首先判断两方阵营相同不占斗 if (isHuman[a] == isHuman[b]) { continue; } // 一方死亡也不战斗 if (deads[a] || deads[b]) { continue; } // 判断是否战斗,切换人兽,a为人,b为兽 if (isHuman[b]) { int tp = a; a = b; b = tp; String tps = ac; ac = bc; bc = tps; } // 如果人公布角色 if ("Y".equals(ac)) { // 战斗 if (nums[a] < nums[b]) { deads[a] = true; } else if (nums[a] == nums[b]) { deads[a] = true; deads[b] = true; } else { deads[b] = true; } } else if ("Y".equals(bc)) { // 手公布角色 if (nums[a] > nums[b]) { deads[b] = true; } } } catch (Exception ex) { break; } } for (int i = 0; i < num; i++) { System.out.print(deads[i] ? "N" : "Y"); } }}// 第三题class Main3 { public static void main1(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()) { int n = in.nextInt(); int t = in.nextInt(); int[][] cost = new int[n][4]; for (int i = 0; i < n; i++) { for (int j = 0; j < 4; j++) { cost[i][j] = in.nextInt(); } } get(cost, t); } in.close(); } public static void get(int[][] cost, int t) { // 01背包 // cost ct,cs,false,fs int n = cost.length; int[] old = new int[t + 1]; int[][] count = new int[n + 1][t + 1]; String[][] bi = new String[n + 1][t + 1]; for (int i = 0; i < n; i++) { int[] news = new int[t + 1]; for (int j = 0; j <= t; j++) { news[j] = old[j]; if (j >= cost[i][0]) { // 当前时间大于智力时间 int score = old[j - cost[i][0]] + cost[i][1]; int score1 = old[j - cost[i][2]] + cost[i][3]; int max = Math.max(score, score1); if (max > old[j]) { news[j] = max; if (score > score1) { count[i][j] = j - cost[i][0]; bi[i][j] = "A"; } else { count[i][j] = j - cost[i][2]; bi[i][j] = "B"; } } else { count[i][j] = j; bi[i][j] = "F"; } } else if (j >= cost[i][2]) { // 当前大于暴力需要的时间 int score = old[j - cost[i][2]] + cost[i][3]; if (score > old[j]) { news[j] = score; count[i][j] = j - cost[i][2]; bi[i][j] = "B"; } else { count[i][j] = j; bi[i][j] = "F"; } } else { count[i][j] = j; bi[i][j] = "F"; } } old = news; } StringBuilder sb = new StringBuilder(); int idx = t; for (int i = n - 1; i >= 0; i--) { sb.append(bi[i][idx]); idx = count[i][idx]; } System.out.println(sb.reverse().toString()); }}
点赞 3
评论 0
全部评论
推荐
最新
楼层
暂无评论,快来抢首评~
相关推荐
07-15 14:09
门头沟学院 产品经理
总结我的奇葩面试经历
点赞
评论
收藏
分享
不愿透露姓名的神秘牛友
07-15 17:32
副总,请您自重哦
你想干啥捏,小心实名给你挂网上,劳资还没入职就整这出
我是超级菜狗:
这还敢入职吗 哈人
点赞
评论
收藏
分享
06-26 16:46
广东海洋大学 Java
牛友们为什么我的简历投出去看都没人看双飞java毕业真的只能送外卖了吗
程序员小白条:
找的太晚,别人都是大三实习,然后大四秋招春招的,你大四下了才去实习,晚1年
点赞
评论
收藏
分享
07-17 13:45
北京交通大学 机械工程师
小鹏二面,面试官笑了,我也笑了
问我对小鹏了解多少,我....呃.....嗯....
小鹏汽车二面14人在聊
点赞
评论
收藏
分享
评论
点赞成功,聊一聊 >
点赞
收藏
分享
评论
提到的真题
返回内容
全站热榜
更多
1
...
0实习0面试, 速通拼多多
1.4W
2
...
秋招腾讯TEG提前批(三面挂)
1.1W
3
...
玛勒戈壁得秋天到了吗就秋招。恨不得搁产房外面招聘
6643
4
...
我和妈妈讲以后我可能给不了她一个月1500
5209
5
...
后端实习到底该干什么啊
4497
6
...
双非本应届是如何拿到30
3846
7
...
明天五场面试,加油
3464
8
...
怎么准备实习
3175
9
...
王侯将相宁有种乎!
3144
10
...
实习,别太较真
3060
创作者周榜
更多
正在热议
更多
#
26届的你们有几段实习?
#
32605次浏览
388人参与
#
机械人,你拿到几个offer啦
#
38232次浏览
318人参与
#
你被哪些公司秒挂过?
#
24812次浏览
219人参与
#
面试体验感最好的是哪家?
#
222920次浏览
2378人参与
#
如何提高实习转正率?
#
9495次浏览
147人参与
#
双非能在秋招上岸吗?
#
219810次浏览
1163人参与
#
哪些公司校招卡第一学历
#
63376次浏览
240人参与
#
初创公司值得加入吗?
#
25974次浏览
189人参与
#
大疆的机械笔试比去年难吗
#
74774次浏览
636人参与
#
月薪多少能在一线城市生存
#
16190次浏览
227人参与
#
你后悔自己读研吗?
#
13286次浏览
212人参与
#
大家每天通勤多久?
#
48206次浏览
353人参与
#
当下环境,你会继续卷互联网,还是看其他行业机会
#
116140次浏览
804人参与
#
你认为哪些项目算烂大街?
#
13173次浏览
252人参与
#
你以为的实习VS真实的实习
#
18000次浏览
178人参与
#
设计人的面试记录
#
129118次浏览
1355人参与
#
比亚迪求职进展汇总
#
735487次浏览
3095人参与
#
网申一定要掌握的小技巧
#
10101次浏览
66人参与
#
你小时候最想从事什么职业
#
103729次浏览
1787人参与
#
机械校招之路总结
#
92906次浏览
1891人参与
牛客网
牛客网在线编程
牛客网题解
牛客企业服务