- 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;
您可能关注的文档
- 体外诊断试剂质量管理体系的评价与实施试行.doc
- 体育公司规划.doc
- 体育器材市场营销现状与发展.doc
- 体育强乡定级标准表.doc
- 体育用品促销流程策划案例.doc
- 体育欣赏课程教学大纲.doc
- 体育用品厂管理系统.doc
- 体力活动与痴呆的预防.ppt
- 体育用品的发展已成为经济新的增长点.doc
- 体育用品知识.doc
- 2026年中国窗饰产品市场全景调查与市场供需预测报告.docx
- 2026年中国船舶水下清洗行业深度研究报告:市场需求预测、进入壁垒及投资风险.docx
- 2026年中国船用绞车行业运行态势及十五五盈利前景预测报告.docx
- 2026年中国橱柜行业深度调研报告.docx
- 2026年中国船用绞车市场深度调研及投资前景战略分析报告.docx
- 2026年中国船用配套设备市场发展策略及投资潜力可行性预测报告.docx
- 2026年中国储能材料行业运营态势与投资前景预测分析报告.docx
- 2026年中国储氢材料行业运营现状及发展规划分析报告.docx
- 2026年中国传真机市场深度研究及投资前景咨询报告.docx
- 2026年中国储能变流器(PCS)产业深度评估与发展前景趋势分析研究报告.docx
原创力文档

文档评论(0)