點擊打開hdu2093
8 20 Smith -1 -16 8 0 0 120 39 0 John 116 -2 11 0 0 82 55(1) 0 Josephus 72(3) 126 10 -3 0 47 21(2) -2 Bush 0 -1 -8 0 0 0 0 0 Alice -2 67(2) 13 -1 0 133 79(1) -1 Bob 0 0 57(5) 0 0 168 -7 0
Josephus 5 376 John 4 284 Alice 4 352 Smith 3 167 Bob 2 325 Bush 0 0
import java.util.Scanner; public class P2093 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int n=sc.nextInt(); int m=sc.nextInt(); Person[] p=new Person[1000]; int k=0; while(sc.hasNext()){// String name=sc.next(); int time=0,num=0; for(int i=0;i0){ num++; time+=timer+numb*m; } } p[k++]=new Person(name,num,time); //System.out.println(num=+num+ time=+time); } sort(p,k); for(int i=0;i p[j+1].time){ swap(p,j,j+1); }else if(p[j].time==p[j+1].time){ if(p[j].name.compareTo(p[j+1].name)>0){ swap(p,j,j+1); } } } } } } private static void swap(Person[] p, int j, int i) { Person temp=new Person(); temp=p[j]; p[j]=p[i]; p[i]=temp; } } class Person{ public String name; public int num; public int time; public Person(String name,int num,int time){ this.name=name; this.num=num; this.time=time; } public Person(){ } }