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

相关推荐

06-19 14:58
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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