田忌赛车算法java.docVIP

  • 3
  • 0
  • 约4.58万字
  • 约 5页
  • 2017-07-10 发布于河南
  • 举报
田忌赛车算法java

package Test1; import java.util.Scanner; public class LOLTestAnyType { /** * @param args */ Node firstNode=new Node(0); Node secondNode=new Node(0); int sizeA=1; int sizeB=1; public int getSizeA() { return sizeA; } public int getSizeB() { return sizeB; } public static void main(String[] args) { // TODO Auto-generated method stub Scanner reader = new Scanner(System.in); int T = reader.nextInt(); for (int i = 0; i T; i++) { int m = reader.nextInt(); LOLTest test = new LOLTest(); double[] a = new double[m]; double[] b = new double[m]; for (int j = 0; j m; j++) { a[j] = reader.nextDouble(); } for (int j = 0; j m; j++) { b[j] = reader.nextDouble(); } test.sort(a); test.sort(b); test.create1(test.firstNode, a); test.create2(test.secondNode, b); int sum = test.abcd(); if (sum = 0) { System.out.println(Xiaoming will get + sum + QB); } else { System.out.println(Xiaotao will get + Math.abs(sum) + QB); } } } // 计算sum并返回 public AnyType extends Comparable? super AnyType int abcd( ) { int sum = 0; while (firstNode.next!=null) { Node p=firstNode.next; Node q=secondNode.next; if (p.data q.data) { sum=sum+200; remove1(1); remove2(1); }if (p.data == q.data) { Node c=getNode(getSizeA(),firstNode); Node d=getNode(getSizeB(),secondNode); if(c.data=d.datac.data!=p.data){ remove1(1); remove2(getSizeB()-1); sum=sum-200; }else if(c.datad.data){ remove1(getSizeA()-1); remove2(getSizeB()-1); sum=sum+200; }else if(c.data==d.datac.data==p.data){ remove1(getSizeA()-1); remove2(getSizeA()-1); } }if (p.data q.data) { sum=sum-200; remove1(1); remove2(getSizeB()-1); } } return sum; } //获得idx位置的节点 public Node getNode(int idx,Node node){ Node p=node; for(int i=0;iidx-1;i++){ p=p.next; } return p; } // 删除单链表中的元素 public void remove1(int idx){ Node p=firstNode;

文档评论(0)

1亿VIP精品文档

相关文档