首页 > IT职业 > IT生活 > 算法 test 五个用例
package t170427;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Solution170427_weimeng {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int test_case=sc.nextInt();//测试用例的数量
for(int t=0;t
int boatCount=sc.nextInt();//船的数量
for(int i=0;i
boatList.add(boat);
}
Boat b=Collections.min(boatList);
System.out.println("#"+(t+1)+" "+b.index);
}
sc.close();
}
}
class Boat implements Comparable
Boat(int index,int x,int y){
this.index=index;
this.x=x;
this.y=y;
this.distance=xx+yy;
if(x>0 && y>0){
this.xiangxian=1;
}
if(x>0 && y this.xiangxian=2;
}
if(x this.xiangxian=3;
}
if(x0){
this.xiangxian=4;
}
}
int index;
int x;
int y;
int xiangxian;
int angle;
int distance;
@Override
public int compareTo(Boat boat) {
if(this.xiangxian
}
if(this.xiangxian>boat.xiangxian){
return 1;
}
if(this.xiangxian==1 || boat.xiangxian==3){
//x1/y1>x2/y2 return 1
if(Math.abs(this.xboat.y) >Math.abs(boat.xthis.y)){
return 1;
}
if(Math.abs(this.xboat.y)
return -1;
}
}
if(this.xiangxian==2 || boat.xiangxian==4){
//y1/x1>y2/x2 return 1
if(Math.abs(this.yboat.x) >Math.abs(boat.ythis.x)){
return 1;
}
if(Math.abs(this.yboat.x)
return -1;
}
}
//象限一样,夹角一样,继续判断距离
if(this.distance>boat.distance){
return 1;
}else{
return -1;
}
}
}
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Solution {
static int N; // 书的种类
static int K; // 每种书内必读书的个数
static int M; // 读书周期
static int[][] Input = null; // 每本必读书的点赞数
static int sum = 0;
static List
public static void main(String[] args) throws FileNotFoundException {
Scanner sc = new Scanner(System.in);
int test_case = sc.nextInt();
for (int i = 0; i sum = 0;
N = sc.nextInt();
K = sc.nextInt();
M = sc.nextInt();
Input = new int[N][K];
for (int j = 0; j for (int k = 0; k Input[j][k] = sc.nextInt();
}
}
fnMaxSum(i);
}
sc.close();
}
private static void fnMaxSum(int test_case) {
list = new ArrayList
for (int j = 0; j Arrays.sort(Input[j]);
}
for (int j = 0; j for (int k = K - 1; k >= (K - M / 2) && k >= 0; k--) {
list.add(Input[j][k]);
}
}
Collections.sort(list);
for (int j = list.size() - 1; j > list.size() - M - 1 && j >= 0; j--) {
sum += list.get(j);
}
System.out.println("#" + (test_case + 1) + " " + sum);
}
}
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Solution {
static int TestCase;
static int answer;
static int N,M,K;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
TestCase=sc.nextInt();
for(int t=1;t sc.nextLine();
N=sc.nextInt();
M=sc.nextInt();
K=sc.nextInt();
answer=M+1;
Map
for(int i=1;i sc.nextLine();
int k1=sc.nextInt();
int k2=sc.nextInt();
ArrayList
if(arr==null){
arr=new ArrayList
}
arr.add(k2);
relative.put(k1, arr);
}
getNum(1,1,relative);
if(answer==M+1){
answer=-1;
}
System.out.println("#"+t+" "+answer);
}
}
public static void getNum(int num,int key,Map
if(num if(num
}
return;
}else{
if(num>M || rela.get(key)==null){
return;
}else{
num++;
for(int i=0;i
}
}
}
}
}
package t170223;
import java.util.Scanner;
/**
所以限定条件:
1.每个部门只出现1个人力缺口,而应聘人力也是一对一。即N个部门 N个人力
2.应聘人力为 3 招聘担当为此想出了一个办法来最大满足各位的需求: 即每个人对每个部门进行打分 4个部门时 4个人就进行打分 最高分4分 最低分1分 分数不重复 打分表如下: 部门1 部门2 部门3 部门4 人力1 4 2 3 1 人力2 2 3 4 1 人力3 3 1 2 4 人力4 4 3 1 2 然后招聘担当尽量去每个部门满意度最高的人去相应部门,当然会有多人最想去的部门相同,但一个部门只能去一个人。所以需要在不同的组合选择中。选择出总得分最高的。 即 方式一:人力1->部门1 人力2->部门3 人力3->部门4 人力4-> 部门2 总得分为 4+4+4+3 =15 方式二:人力1->部门2 人力2->部门3 人力3->部门4 人力4-> 部门1 总得分为 2+4+4+4 =14 方式三:....... 方式四:....... 等等。。。。 要求我们给出所有方式组合中 总得分最高的 分数 即输出15这个值 Test case 输入 2 --case 总数 4 --部门数 4 2 3 1 -- 每个人的打分 依次是1~N的部门 2 3 4 1 3 1 2 4 4 3 1 2 5 --部门数 4 2 3 1 5-- 每个人的打分 依次是1~N的部门 2 3 5 1 4 3 5 2 4 1 4 3 5 1 2 1 4 3 2 5 输出 Scanner sc=new Scanner(System.in); sc.close(); /String str="123"; public static void process(int[] array,int start,int end){ }else{ public static int countCurrentScore(int[] array,int [][] deptScore){ } package Solution02_yourname; import java.util.Scanner; public class Solution512_lizhun { static int T,N,small,big; } } } import java.util.Scanner; /** 所以限定条件: 1.每个部门只出现1个人力缺口,而应聘人力也是一对一。即N个部门 N个人力 2.应聘人力为 3 招聘担当为此想出了一个办法来最大满足各位的需求: 即每个人对每个部门进行打分 4个部门时 4个人就进行打分 最高分4分 最低分1分 分数不重复 打分表如下: 部门1 部门2 部门3 部门4 人力1 4 2 3 1 人力2 2 3 4 1 人力3 3 1 2 4 人力4 4 3 1 2 然后招聘担当尽量去每个部门满意度最高的人去相应部门,当然会有多人最想去的部门相同,但一个部门只能去一个人。所以需要在不同的组合选择中。选择出总得分最高的。 即 方式一:人力1->部门1 人力2->部门3 人力3->部门4 人力4-> 部门2 总得分为 4+4+4+3 =15 方式二:人力1->部门2 人力2->部门3 人力3->部门4 人力4-> 部门1 总得分为 2+4+4+4 =14 方式三:....... 方式四:....... 等等。。。。 要求我们给出所有方式组合中 总得分最高的 分数 即输出15这个值 Test case 输入 2 --case 总数 4 --部门数 4 2 3 1 -- 每个人的打分 依次是1~N的部门 2 3 4 1 3 1 2 4 4 3 1 2 5 --部门数 4 2 3 1 5-- 每个人的打分 依次是1~N的部门 2 3 5 1 4 3 5 2 4 1 4 3 5 1 2 1 4 3 2 5 输出 Scanner sc=new Scanner(System.in); sc.close(); /String str="123"; public static void process(int[] array,int start,int end){ }else{ public static int countCurrentScore(int[] array,int [][] deptScore){ } package Solution02_yourname; import java.util.Scanner; public class Solution512_lizhun { static int T,N,small,big; } } }
/
public class Solution170223_weimeng {
static int[][] deptScore;
static int maxScore=0;
public static void main(String[] args) {
//int test_case=sc.nextInt();
int test_case=1;
for(int t=0;t
deptScore=new int[deptSize][deptSize];
int[] array=new int[deptSize];
for(int i=0;i
for(int j=0;j
}
}
process(array,0,array.length-1);
System.out.println(maxScore);
}
process(str.toCharArray(),0,str.length()-1);/
}
if(start==end){
//System.out.println(String.valueOf(array));
int currentScore=countCurrentScore(array,deptScore);
if(currentScore>maxScore){
maxScore=currentScore;
}
for(int index=start;index int temp=array[start];
array[start]=array[index];
array[index]=temp;
process(array,start+1,end);
temp=array[start];
array[start]=array[index];
array[index]=temp;
}
}
}
int count=0;
for(int i=0;i
}
return count;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
T = sc.nextInt();
for (int testcase = 1; testcase N = sc.nextInt();
small = big = 0;
if (N%2 != 0) {//奇数
small = 2;
if (isSuShu(N - small)) {
big = N - small;
}
} else { //偶数
int x = N/2;
for(int i = x;i > 1; i--){
//如果已经找到了big和small就跳出循环
if (big != 0) {
break;
} for (int j = 2; j
printRes(testcase);
}
private static void printRes(int testcase) {
if (big == 0) {
System.out.println("#" + testcase + " -1");
} else {
System.out.println("#" + testcase + " " + small + " " + big);
}
}
private static boolean isSuShu(int i) {
for (int j = 2; j if (i%j == 0) {
return false;
}
}
return true;
}
package t170223;
/
public class Solution170223_weimeng {
static int[][] deptScore;
static int maxScore=0;
public static void main(String[] args) {
//int test_case=sc.nextInt();
int test_case=1;
for(int t=0;t
deptScore=new int[deptSize][deptSize];
int[] array=new int[deptSize];
for(int i=0;i
for(int j=0;j
}
}
process(array,0,array.length-1);
System.out.println(maxScore);
}
process(str.toCharArray(),0,str.length()-1);/
}
if(start==end){
//System.out.println(String.valueOf(array));
int currentScore=countCurrentScore(array,deptScore);
if(currentScore>maxScore){
maxScore=currentScore;
}
for(int index=start;index int temp=array[start];
array[start]=array[index];
array[index]=temp;
process(array,start+1,end);
temp=array[start];
array[start]=array[index];
array[index]=temp;
}
}
}
int count=0;
for(int i=0;i
}
return count;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
T = sc.nextInt();
for (int testcase = 1; testcase N = sc.nextInt();
small = big = 0;
if (N%2 != 0) {//奇数
small = 2;
if (isSuShu(N - small)) {
big = N - small;
}
} else { //偶数
int x = N/2;
for(int i = x;i > 1; i--){
//如果已经找到了big和small就跳出循环
if (big != 0) {
break;
} for (int j = 2; j
printRes(testcase);
}
private static void printRes(int testcase) {
if (big == 0) {
System.out.println("#" + testcase + " -1");
} else {
System.out.println("#" + testcase + " " + small + " " + big);
}
}
private static boolean isSuShu(int i) {
for (int j = 2; j if (i%j == 0) {
return false;
}
}
return true;
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4325/viewspace-2807847/ ,如需转载,请注明出处,否则将追究法律责任。