|
|
back to boardgive me some test where this program works wrong!!! import java.util.*; public class Cover implements Comparator{ public int compare(Object o1,Object o2){ Cover oo1 = (Cover)o1; Cover oo2 = (Cover)o2;
if(oo1.q>oo2.q) return 1; else if(oo1.q>oo2.q) return -1; else return 0;
}
int q,z; public static void main(String[] args) { int n,i,j,k,l,a[],b[],ct=0,min=Integer.MAX_VALUE,pos=0; int tmp; Cover obj = new Cover(); ArrayList<Cover> map = new ArrayList<Cover>(); boolean visit[][]; Scanner input = new Scanner(System.in); n = input.nextInt(); a = new int[n]; b = new int[n]; visit = new boolean[n][n]; for(i=0;i<n;i++) java.util.Arrays.fill(visit[i],true);
for(i=0;i<n;i++){ a[i] = input.nextInt(); b[i] = input.nextInt(); if(a[i]>b[i]) { tmp = a[i]; a[i] = b[i]; b[i] = tmp; } } for(k=0;k<n;k++){ct=0; for(i=k,l=0;l<n;l++,i++){
if(i>=n)i = i%n; if(visit[k][i]!=false){ for(j=0;j<n;j++){
if(i!=j) if(!(((a[j]<=a[i])&&(b[j]<=a[i]))||((a[j]>=b[i])&&(b[j])>=b[i]))){ if(visit[k][j]!=false){ visit[k][j]=false; ct++; } }}}} if(ct<min){ min = ct; pos = k;
} }
System.out.println(n-min);
for(i=0;i<n;i++){ if(visit[pos][i]!=false) { obj = new Cover(); obj.q = a[i];obj.z = b[i]; map.add(obj); }
} Collections.sort(map,new Cover()); ListIterator it = map.listIterator(); while(it.hasNext()){ obj = (Cover) it.next(); System.out.println(obj); } } public String toString(){ return q + " " + z; } } |
|
|