真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

java權(quán)重代碼 java權(quán)重是什么意思

如何在java代碼中設(shè)置權(quán)重

editText.setLayoutParams(new LinearLayout.LayoutParams(width, height, weight)); 只有LinearLayout才有l(wèi)ayout_weight屬性。

創(chuàng)新互聯(lián)建站專業(yè)為企業(yè)提供菏澤網(wǎng)站建設(shè)、菏澤做網(wǎng)站、菏澤網(wǎng)站設(shè)計(jì)、菏澤網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、菏澤企業(yè)網(wǎng)站模板建站服務(wù),十余年菏澤做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。

設(shè)計(jì)一種java數(shù)據(jù)結(jié)構(gòu),按照權(quán)重進(jìn)行排序

public?enum?SortBy?{

Number,

Weights1,

Weights2

}

import?java.util.Comparator;

public?class?MyComparator?implements?ComparatorStudent{

private?SortBy?sortBy;

public?MyComparator?(SortBy?sortBy){

this.sortBy?=?sortBy;

}

@Override

public?int?compare(Student?s1,?Student?s2)?{

switch?(this.sortBy)?{

case?Weights1:

return?s1.getWeights1()?-?s2.getWeights1();

case?Weights2:

return?s1.getWeights2()?-?s2.getWeights2();

default:

return?s1.getNumber()?-?s2.getNumber();

}

}

}

import?java.util.Collections;

import?java.util.Comparator;

import?java.util.LinkedList;

import?java.util.List;

public?class?Student?{

private?int?number;

private?int?weights1;

private?int?weights2;

public?Student(int?number,?int?weights1,?int?weights2)?{

this.number?=?number;

this.weights1?=?weights1;

this.weights2?=?weights2;

}

public?int?getNumber()?{

return?this.number;

}

public?int?getWeights1()?{

return?this.weights1;

}

public?int?getWeights2()?{

return?this.weights2;

}

public?static?void?main(String[]?args){

final?Student?s1?=?new?Student(1,?20,?300);

final?Student?s2?=?new?Student(2,?10,?100);

final?Student?s3?=?new?Student(3,?30,?200);

final?ListStudent?array?=?new?LinkedListStudent();

array.add(s1);

array.add(s2);

array.add(s3);

 

final?ComparatorStudent?numberComparator?=?new?MyComparator(SortBy.Number);

Collections.sort(array,?numberComparator);

System.out.println("sort?by?number");

System.out.print("Number:?");

for(Student?s:?array){

System.out.print(s.getNumber()?+?"?");

}

System.out.println("\n\n");

 

final?ComparatorStudent?weights1Comparator1?=?new?MyComparator(SortBy.Weights1);

System.out.println("sort?by?weights1");

System.out.print("Number:?");

Collections.sort(array,?weights1Comparator1);

for(Student?s:?array){

System.out.print(s.getNumber()?+?"?");

}

System.out.println("\n\n");

final?ComparatorStudent?weights2Comparator?=?new?MyComparator(SortBy.Weights2);

System.out.println("sort?by?weights2");

System.out.print("Number:?");

Collections.sort(array,?weights2Comparator);

for(Student?s:?array){

System.out.print(s.getNumber()?+?"?");

}

System.out.println("\n\n");

}

}

sort?by?number

Number:?1?2?3

 

sort?by?weights1

Number:?2?1?3

 

sort?by?weights2

Number:?2?3?1

java實(shí)現(xiàn)最大權(quán)重單增序列

import?java.util.Scanner;

public?class?Main?{

public?static?int?data[]?=?null;

public?static?int?weight[]?=?null;

public?static?int?res[]?=?null;

/**

?*?@param?args

?*/

public?static?void?main(String[]?args)?{

//?TODO?Auto-generated?method?stub

Scanner?scan?=?new?Scanner(System.in);

System.out.println("輸入序列個(gè)數(shù):");

int?n?=?0;

n?=?scan.nextInt();

System.out.println("輸入"+n+"個(gè)數(shù)(空格隔開):");

data?=?new?int[n];

for?(int?i?=?0;?i??n;?++i)?{

data[i]?=?scan.nextInt();

}

System.out.println("輸入"+n+"個(gè)數(shù)的權(quán)重(空格隔開):");

weight?=?new?int[n];

for?(int?i?=?0;?i??n;?++i)?{

weight[i]?=?scan.nextInt();

}

doit(n);

int?max?=?res[0];

int?k?=?0;

for?(int?i?=?1;?i??n;?++i)?{

if?(max??res[i])?{

max?=?res[i];

k?=?i;

}

}

System.out.println("最大權(quán)值:"+max);

System.out.println("序列為:");

print(k);

System.out.println();

}

public?static?void?doit(int?n)?{

res?=?new?int[n];

for?(int?i?=?0;?i??n;??++i)?{

res[i]?=?weight[i];

for?(int?j?=?0;?j??i;?++j)?{

if?(data[i]??data[j]??res[i]??weight[i]+res[j])?{

res[i]?=?weight[i]+res[j];?

}

}

}

}

public?static?void?print(int?k)?{

for?(int?i?=?k-1;?i?=?0;?--i)?{

if?(res[i]+weight[k]?==?res[k])?{

print(i);

}

}

System.out.print("?"+data[k]);

}

}

輸入樣例:

輸入序列個(gè)數(shù):

5

輸入5個(gè)數(shù)(空格隔開):

1 4 2 3 9

輸入5個(gè)數(shù)的權(quán)重(空格隔開):

1 10 1 1 1

輸出樣例

最大權(quán)值:12

序列為:

?1 4 9

注:序列可能不唯一,就輸出了一組

java按權(quán)重選取對(duì)象,大家知道怎么做嗎?

int rand = 49;//隨機(jī)數(shù)

int sum= 0;

List大海 list = new ArrayList大海();//假設(shè)這是一個(gè)武將列表

for(int i=0;ilist.size();i++){

sum = list.get(i).getWeight();//大海的出現(xiàn)機(jī)率

if(rand=sum){

return i;//返回該武將對(duì)應(yīng)的索引

}

}


本文名稱:java權(quán)重代碼 java權(quán)重是什么意思
本文來源:http://weahome.cn/article/higsis.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部