ccf 排队问题
来源:互联网 发布:阿里云域名使用方法 编辑:程序博客网 时间:2024/06/05 06:13
import java.util.*;public class Main { public static void main(String[] args) { new Main().run(); } private void run() { HashMap<Integer,Student> hashMap=new HashMap<Integer,Student>(); ArrayList<Student> arrayList=new ArrayList<Student>(); Scanner input=new Scanner(System.in); int n,m; n=input.nextInt(); m=input.nextInt(); for (int i =1; i <=n; i++) { hashMap.put(i,new Student(i)); } for (int i = 0; i < m; i++) { int num=input.nextInt(); int ins=input.nextInt(); int low,high; Student ptr=hashMap.get(num); int index=ptr.position; ptr.position+=ins; if (ins>0){ low=index+1; high=index+ins; for (Integer integer : hashMap.keySet()) { if(hashMap.get(integer).position>=low&&hashMap.get(integer).position<=high) hashMap.put(integer,new Student(integer,hashMap.get(integer).position-1)); } hashMap.put(ptr.id,new Student(ptr.id,ptr.position)); } else { low=index+ins; high=index-1; for (Integer integer : hashMap.keySet()) { if(hashMap.get(integer).position>=low&&hashMap.get(integer).position<=high) hashMap.put(integer,new Student(integer,hashMap.get(integer).position+1)); } hashMap.put(ptr.id,new Student(ptr.id,ptr.position)); } } arrayList.addAll(hashMap.values()); Collections.sort(arrayList, new Comparator<Student>() { @Override public int compare(Student o1, Student o2) { if (o2.position<=o1.position) return 1; else return -1; } }); System.out.print(arrayList.get(0).id); for (int i = 1; i <arrayList.size() ; i++) { System.out.print(" "+arrayList.get(i).id); } } class Student{ public int id; public int position; public Student(int i){ this.id=i; this.position=i-1; } public Student(int id,int position){ this.id=id; this.position=position; } }}
0 0
- ccf 排队问题
- ccf 排队问题
- CCF排队问题
- CCF—学生排队问题 20170302
- CCF学生排队
- CCF学生排队
- CCF 学生排队
- ccf学生排队
- ccf认证学生排队
- ccf 学生排队
- ccf-学生排队
- ccf学生排队
- CCF--学生排队
- CCF之学生排队
- CCF 学生排队
- ccf之学生排队
- 第十次ccf 学生排队
- CCF 学生排队 Java实现
- UESTC 375
- tiny6410关闭看门狗
- javaScript基本数据类型
- 求二叉排序树的最小根
- 【Algothrim】Christmas Gifts
- ccf 排队问题
- 三、makefile 之echo \ $^ exec
- <教程>-扁平化
- CSS3D
- AngularJS 深入理解 $scope
- select2点击空白处不消失
- kaggle中的可视化(一):House Prices
- CSS样式排版
- 关于unity build后的unity_builtin_extra很大的问题