360的编程题真nb

我的是内存管理  实现一个简易的堆
真几把不说了
全部评论
内存管理我直接用链表做的,ac了
点赞 回复 分享
发布于 2016-09-10 21:15
import java.util.HashMap; import java.util.Scanner; /** * Created by gzd on 2016/9/10. */ public class Test360R2 { public static void main(String[] args){ Scanner in = new Scanner(System.in); while(in.hasNextLine()){ int op = in.nextInt(); int maxMen = in.nextInt(); String[] str = new String[op]; String abc = in.nextLine(); for(int i = 0; i < op; ++i){ str[i] = in.nextLine(); } result(maxMen,str); } } public static void result(int max,String[] str){ int[] count = new int[max]; int hhh = 1; HashMap<Integer,int[]> map3 = new HashMap<>(); HashMap<Integer,Integer> map2 = new HashMap<>(); for(int i = 0; i < str.length; ++i){ String[] single = str[i].split(" "); if(single[0].equals("new")){ int newSize = Integer.parseInt(single[1]); int maxLen = 0; int mflag = 0; for(int m = 0;m < max; ++m){ if(count[m] == 1){ maxLen = 0; mflag = m+1; }else if(count[m] == 0){ maxLen++; } if(maxLen >= newSize){ for(int k = 0;k < maxLen;k++){ count[mflag + k] = 1; } int[] o = new int[2]; o[0] = mflag; o[1] = mflag+maxLen; map3.put(hhh,o); System.out.println(hhh); hhh++; break; } } if(maxLen < newSize) System.out.println("NULL"); }else if(single[0].equals("del")){ int handle = Integer.parseInt(single[1]); int[] o = map3.get(handle); if(o == null){ System.out.println("ILLEGAL_OPERATION"); }else{ for(int p = o[0];p < o[1];p++){ count[p] = 0; } } }else if(single[0].equals("def")){ int mark = 0; for(int u = 0;u < max; ++u){ if(count[u] == 1){ count[mark] = count[u]; count[u] = 0; mark++; } } } } } }
点赞 回复 分享
发布于 2016-09-10 22:25
有java语言的吗?你们输入部分是怎么写的啊?为啥提交到服务器一直0%...
点赞 回复 分享
发布于 2016-09-10 21:32
内存管理写完了。。然后 def 靠近顶端看成了靠近底部,10%,gg 以及这题用 TreeSet 其实不算难
点赞 回复 分享
发布于 2016-09-10 21:10
package wangyi1; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int size = sc.nextInt(); int handle = 0; int lab = 0; int ishan[] = new int[size]; int cursize=0; for (int i = 0; i < n; i++) { String s = sc.next(); if (s.equals("new")) { int k = sc.nextInt(); if (cursize+k <= size) { handle++; cursize+=k; while (--k >= 0) { while(ishan[lab]!=0) lab++; ishan[lab++] = handle; } System.out.println(handle); } else System.out.println("NULL"); } if (s.equals("del")) { int k = sc.nextInt(); int cnt = 0; int first=0; for (int j = 0; j < size; j++) { if (ishan[j] == k) { if(first==0) lab=j; first=1; ishan[j] = 0; cnt++; } } if (cnt == 0) System.out.println("ILLEGAL_OPERATION"); cursize-=cnt; } if (s.equals("def")) { int blank = size - 1; for (int j = size - 1; j >= 0; j--) { for (int l = size - 1; l >= 1; l--) { if (ishan[l] == 0 && ishan[l - 1] != 0) { int tmp = ishan[l]; ishan[l] = ishan[l - 1]; ishan[l - 1] = tmp; } } } if (ishan[0] == 0) lab = 0; else lab = n - 1; } for (int j = 0; j < size; j++) System.out.print(ishan[j] + " "); System.out.println("size "+cursize); } } }
点赞 回复 分享
发布于 2016-09-13 14:40
有用JAVA完全对的么,求分享代码。
点赞 回复 分享
发布于 2016-09-10 21:47
这是题目 对样例而言,初始空间大小为10,编号1-10, 操作1,new 5, 占据1-5, 返回句柄是1没问题。 操作2,new 3,占据6-8,返回句柄应该是6呀??为什么是2 样例是不是有问题啊,求大神指教哪里理解错了?
点赞 回复 分享
发布于 2016-09-10 21:40
内存管理  一直就只能通过10%   交卷了  才突然反应过来  题意理解错了 
点赞 回复 分享
发布于 2016-09-10 21:28
两道题本地都没问题,第一道内存管理通过10%, 第二道火车站看旗子很简单但是不能用STL find函数醉了!!
点赞 回复 分享
发布于 2016-09-10 21:07
40% 不谈了肯定超时
点赞 回复 分享
发布于 2016-09-10 21:05

相关推荐

牛马为难牛马中,疑似阿里的员工看某个从拼多多跳槽过来的员工抢他的A+绩效不顺眼,反手向多多举报的,结果导致人家竞业被发现了,违约金5w,赔偿100+w上海长宁区劳动人事争议仲裁委公告显示:上海寻梦信息技术有限公司(拼多多主体)与一名员工的劳动争议案,因被申请人未到庭,仲裁委依法缺席裁决。结果是,该员工需要返还已发放的竞业补偿58,211.29元,并按约支付违约金1,089,103元。公告自发布30日后视为送达,15日内不诉即生效
nova!1028:竞业避坑指南:1、平时戴口罩及帽子、墨镜,不在公共场所露面 2、不在现有公司收快递 3、自己竞业期间社保缴纳不挂靠,最好不交 4、三方公司不能对外说可挂医社保 5、记住社保缴纳地的地址 6、注意陌生可疑电话,比如猎头 7、自己名下车子不要出入到服务的场所 8、竞业到期后不能马上出现在竞对公司股东信息上 9、注意平台简历内容,会被取证 10、竞业期过后,不要透露过往,以防被追溯 11、非必要不开大会和培训,注意公司内鬼 12、不在社交平台展示自己 13、电话卡不用自己名字登记 14、注意陌生的外卖 15、注意动车票信息 16、竞业期低调不结仇 复制过来的
投递阿里巴巴集团等公司10个岗位
点赞 评论 收藏
分享
07-02 10:39
门头沟学院 Java
Steven267:说点真实的,都要秋招了,还没有实习,早干嘛去了,本来学历就差,现在知道急了,而且你这个简历完全可以写成一页,劣势太大了,建议转测试
点赞 评论 收藏
分享
07-20 11:20
新疆大学 Java
Alan_01:看到都是黑马点评跟苍穹外卖我就放心了
无实习如何秋招上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务