//HTML
我們提供的服務(wù)有:成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、微信公眾號(hào)開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、綦江ssl等。為1000多家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的綦江網(wǎng)站制作公司
html
applet code=SZJSQ.class width=400 height=180
/applet
/html
//APPLET
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
public class SZJSQ extends JApplet implements ActionListener
{
boolean i=true;
private JButton num0=new JButton("0");
private JButton num1=new JButton("1");
private JButton num2=new JButton("2");
private JButton num3=new JButton("3");
private JButton num4=new JButton("4");
private JButton num5=new JButton("5");
private JButton num6=new JButton("6");
private JButton num7=new JButton("7");
private JButton num8=new JButton("8");
private JButton num9=new JButton("9");
private JButton zuok=new JButton("(");
private JButton youk=new JButton(")");
private JButton dian=new JButton(".");
private JButton NULL=new JButton("N");
private JButton plu=new JButton("+");
private JButton min=new JButton("-");
private JButton mul=new JButton("x");
private JButton div=new JButton("/");
private JButton equ=new JButton("=");
private JButton cle=new JButton("C");//清除
private JTextField space=new JTextField(30);
public void init()
{
JPanel text=new JPanel();
text.setLayout(new FlowLayout());
text.add(space);
JPanel buttons=new JPanel();
buttons.setLayout(new GridLayout(5,4));
buttons.add(num9);
buttons.add(num8);
buttons.add(num7);
buttons.add(plu);
buttons.add(num6);
buttons.add(num5);
buttons.add(num4);
buttons.add(min);
buttons.add(num3);
buttons.add(num2);
buttons.add(num1);
buttons.add(mul);
buttons.add(num0);
buttons.add(cle);
buttons.add(equ);
buttons.add(div);
buttons.add(zuok);
buttons.add(youk);
buttons.add(dian);
buttons.add(NULL);
(num9).addActionListener(this);
(num8).addActionListener(this);
(num7).addActionListener(this);
(num6).addActionListener(this);
(num5).addActionListener(this);
(num4).addActionListener(this);
(num3).addActionListener(this);
(num2).addActionListener(this);
(num1).addActionListener(this);
(num0).addActionListener(this);
(plu).addActionListener(this);
(min).addActionListener(this);
(mul).addActionListener(this);
(div).addActionListener(this);
(equ).addActionListener(this);
(cle).addActionListener(this);
(zuok).addActionListener(this);
(youk).addActionListener(this);
(dian).addActionListener(this);
setLayout(new BorderLayout());
add("North",text);
add("South",buttons);
space.setText("0");
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==num9)
{
if(i==true)
{
space.setText("9");
i=false;
}
else space.setText(space.getText()+'9');
}
if(e.getSource()==num8)
{
if(i==true)
{
space.setText("8");
i=false;
}
else space.setText(space.getText()+'8');
}
if(e.getSource()==num7)
{
if(i==true)
{
space.setText("7");
i=false;
}
else space.setText(space.getText()+'7');
}
if(e.getSource()==num6)
{
if(i==true)
{
space.setText("6");
i=false;
}
else space.setText(space.getText()+'6');
}
if(e.getSource()==num5)
{
if(i==true)
{
space.setText("5");
i=false;
}
else space.setText(space.getText()+'5');
}
if(e.getSource()==num4)
{
if(i==true)
{
space.setText("4");
i=false;
}
else space.setText(space.getText()+'4');
}
if(e.getSource()==num3)
{
if(i==true)
{
space.setText("3");
i=false;
}
else space.setText(space.getText()+'3');
}
if(e.getSource()==num2)
{
if(i==true)
{
space.setText("2");
i=false;
}
else space.setText(space.getText()+'2');
}
if(e.getSource()==num1)
{
if(i==true)
{
space.setText("1");
i=false;
}
else space.setText(space.getText()+'1');
}
if(e.getSource()==num0)
{
if(i==true)
{
space.setText("0");
i=false;
}
else space.setText(space.getText()+'0');
}
if(e.getSource()==zuok)
{
if(i==true)
{
space.setText("(");
i=false;
}
else space.setText(space.getText()+'(');
} if(e.getSource()==youk)
{
if(i==false)
space.setText(space.getText()+')');
}
if(e.getSource()==dian)
{
if(i==false)
space.setText(space.getText()+'.');
}
if(e.getSource()==plu)
{
space.setText(space.getText()+'+');
i=false;
}
if(e.getSource()==min)
{
space.setText(space.getText()+'-');
i=false;
}
if(e.getSource()==mul)
{
space.setText(space.getText()+'*');
i=false;
}
if(e.getSource()==div)
{
space.setText(space.getText()+'/');
i=false;
}
if(e.getSource()==equ)
{
space.setText(String.valueOf(Calculator(space.getText())));
i=true;
}
if(e.getSource()==cle)
{
space.setText("0");
i=true;
}
}
public double Calculator(String f)//科學(xué)計(jì)算
{
int i=0,j=0,k;
char c;
StringBuffer s=new StringBuffer();
s.append(f);
s.append('=');
String formula=s.toString();
char[] anArray;
anArray=new char[50];
StackCharacter mystack=new StackCharacter();
while(formula.charAt(i)!='=')
{
c=formula.charAt(i);
switch(c)
{
case '(': mystack.push(new Character(c));
i++;
break;
case ')':
while(mystack.peek().charValue()!='(')
{
anArray[j++]=mystack.pop().charValue();
}
mystack.pop();
i++;
break;
case '+':
case '-':
while(!mystack.empty()mystack.peek().charValue()!='(')
{
anArray[j++]=mystack.pop().charValue();
}
mystack.push(new Character(c));
i++;
break;
case '*':
case '/':
while(!mystack.empty()(mystack.peek().charValue()=='*'||mystack.peek().charValue()=='/'))
{
anArray[j++]=mystack.pop().charValue();
}
mystack.push(new Character(c));
i++;
break;
case' ': i++;
break;
default: while((c='0'c='9')||c=='.')
{
anArray[j++]=c;
i++;
c=formula.charAt(i);
}
anArray[j++]='#';
break;
}
}
while(!(mystack.empty()))
anArray[j++]=mystack.pop().charValue();
i=0;
int count;
double a,b,d;
StackDouble mystack1 =new StackDouble();
while(ij)
{
c=anArray[i];
switch(c)
{
case '+':
a=mystack1.pop().doubleValue();
b=mystack1.pop().doubleValue();
d=b+a;
mystack1.push(new Double(d));
i++;
break;
case '-':
a=mystack1.pop().doubleValue();
b=mystack1.pop().doubleValue();
d=b-a;
mystack1.push(new Double(d));
i++;
break;
case '*':
a=mystack1.pop().doubleValue();
b=mystack1.pop().doubleValue();
d=b*a;
mystack1.push(new Double(d));
i++;
break;
case '/':
a=mystack1.pop().doubleValue();
b=mystack1.pop().doubleValue();
if(a!=0)
{
d=b/a;
mystack1.push(new Double(d));
i++;
}
else
{
System.out.println("Error!");
}
break;
default:
d=0;count=0;
while((c='0'c='9'))
{
d=10*d+c-'0';
i++;
c=anArray[i];
}
if(c=='.')
{
i++;
c=anArray[i];
while((c='0'c='9'))
{
count++;
d=d+(c-'0')/Math.pow(10,count);
i++;
c=anArray[i];
}
}
if(c=='#')
mystack1.push(new Double(d));
i++;
break;
}
}
return(mystack1.peek().doubleValue());
}
}
產(chǎn)銷不平衡用NBPSProcedure,平衡用BPSProcedure
public class ProductSaleBTProb {
public static void main(String[] args) {
float[][] costMatrix=new float[][]{{1.5f,2f,0.3f,3f},{7f,0.8f,1.4f,2f},{1.2f,0.3f,2f,2.5f}};
/*
* 測(cè)試行、列位勢(shì)方法
float[][] ASMatrix=new float[6][7];
ASMatrix[0]=new float[]{20f,0f,80f,0f,0f,0f,0f};
ASMatrix[1]=new float[]{0f,70f,0f,10f,0f,0f,0f};
ASMatrix[2]=new float[]{30f,0f,0f,20f,0f,0f,0f};
doLCPosiPower(costMatrix, ASMatrix, 3, 4);
for(int i=0;i6;i++){
System.out.println(Arrays.toString(ASMatrix[i]));
}
*/
/*
* 測(cè)試pw為產(chǎn)地產(chǎn)量,sw為銷售地效率,費(fèi)用矩陣costMatrix
*/
int[] pw=new int[]{100,80,50};
int[] sw=new int[]{50,70,80,30};
int[] rv=BPSProcedure(costMatrix, 3, 4, pw, sw);
for(int i=0;irv.length;i+=3){
System.out.print("編號(hào)"+rv[i]+"的產(chǎn)地,向編號(hào)"+rv[i+1]+"的銷地運(yùn)輸:"+rv[i+2]+"\n");
}
/*
*產(chǎn)銷不平衡測(cè)試
costMatrix=new float[][]{{4f,2f,5f},{3f,5f,3f},{1f,3f,2f}};
int[] pw=new int[]{8,7,4};
int[] sw=new int[]{4,8,5};
int[] rv=NBPSProcedure(costMatrix, 3, 3, pw, sw);
for(int i=0;irv.length;i+=3){
System.out.print("編號(hào)"+rv[i]+"的產(chǎn)地,向編號(hào)"+rv[i+1]+"的銷地運(yùn)輸:"+rv[i+2]+"\n");
}
*/
}
//產(chǎn)銷平衡運(yùn)輸費(fèi)用最低問題,保證pw和sw相等
//costMatrix為費(fèi)用矩陣,pnum為產(chǎn)地個(gè)數(shù),即costMatrix的行數(shù),snum為銷地個(gè)數(shù),即costMatrix的列數(shù)
//pw表示不同產(chǎn)地產(chǎn)量,sw表示不同銷地銷量,由于是float浮點(diǎn)運(yùn)算,保留2位小數(shù)
//返回值沒三位表示一個(gè)信息,比如{...,0,1,40,1,2,60..}表示編號(hào)0的產(chǎn)地向編號(hào)1的銷售地運(yùn)輸40,編號(hào)1的產(chǎn)地向編號(hào)2的銷售地運(yùn)輸60,
public static int[] BPSProcedure(float[][] costMatrix,int pnum,int snum,int[] pw,int[] sw){
int i,j;
//構(gòu)造一個(gè)分配矩陣,增加3行3列,增加的第1行列表示分配的和,第2行列表示行列差,第3行列表示行、列位勢(shì)
float[][] ASMatrix=new float[pnum+3][snum+3];
int tmpsum=0; //記錄初始解是否分配完畢,
while(tmpsumpnum){
//運(yùn)用行、列差值法分別求行、列差,對(duì)即沒有給運(yùn)量又沒有打叉的進(jìn)行統(tǒng)計(jì)
float min1=0,min2=0;
for(i=0;ipnum;i++){
//該行打叉則跳過
if(ASMatrix[i][snum+1]==-1)continue;
min1=0;min2=0;
for(j=0;jsnum;j++){
//如果ij有運(yùn)量或者已經(jīng)該行或該列打叉則不統(tǒng)計(jì)
if(ASMatrix[i][j]0||ASMatrix[pnum+1][j]==-1)
continue;
else if(min1==0)min1=costMatrix[i][j];
else if(min2==0){
if(min1costMatrix[i][j]){
min2=min1;
min1=costMatrix[i][j];
}else
min2=costMatrix[i][j];
}else{
if(!(min2costMatrix[i][j])) continue;
else if(!(min1costMatrix[i][j]))
min2=costMatrix[i][j];
else{
min2=min1;
min1=costMatrix[i][j];
}
}
}
if(min2!=0) //如果min2有值,則計(jì)算差額
ASMatrix[i][snum+1]=Math.round((min2-min1)*100)/100f;
else
ASMatrix[i][snum+1]=min1;
}
for(j=0;jsnum;j++){
//該列打叉則跳過
if(ASMatrix[pnum+1][j]==-1)continue;
min1=0;min2=0;
for(i=0;ipnum;i++){
//如果有運(yùn)量或者該行打叉則跳過
if(ASMatrix[i][j]0||ASMatrix[i][snum+1]==-1)
continue;
else if(min1==0) min1=costMatrix[i][j];
else if(min2==0){
if(min1costMatrix[i][j]){
min2=min1;
min1=costMatrix[i][j];
}else
min2=costMatrix[i][j];
}else{
if(!(min2costMatrix[i][j])) continue;
else if(!(min1costMatrix[i][j]))
min2=costMatrix[i][j];
else{
min2=min1;
min1=costMatrix[i][j];
}
}
}
if(min2!=0)
ASMatrix[pnum+1][j]=Math.round((min2-min1)*100)/100f;
else
ASMatrix[pnum+1][j]=min1;
}
//找出沒有被標(biāo)記為-1的行、列差額最大的并按照滿足一方最大分配,當(dāng)分配數(shù)和等于最大值時(shí)對(duì)應(yīng)行列差標(biāo)記為-1,循環(huán)進(jìn)行,直到分完
float lcpospowmax=-1;
int lindex=-1,cindex=-1;
for(i=0;ipnum;i++){
if(ASMatrix[i][snum+1]==-1)continue;
if(ASMatrix[i][snum+1]!=-1lcpospowmaxASMatrix[i][snum+1]){
lcpospowmax=ASMatrix[i][snum+1];
lindex=i;
}
}
for(j=0;jsnum;j++){
if(ASMatrix[pnum+1][j]==-1)continue;
if(ASMatrix[pnum+1][j]!=-1lcpospowmaxASMatrix[pnum+1][j]){
lcpospowmax=ASMatrix[pnum+1][j]; cindex=j;
}
}
float mincost=0;
//在列上找到最大值
if(cindex!=-1){
lindex=-1;
for(i=0;ipnum;i++){
//如果該位置有運(yùn)量或者被叉掉則不在統(tǒng)計(jì)之內(nèi)
if(ASMatrix[i][cindex]0||ASMatrix[i][snum+1]==-1)
continue;
else if(mincost==0){
mincost=costMatrix[i][cindex];
lindex=i;
}else{
if(mincostcostMatrix[i][cindex]){
mincost=costMatrix[i][cindex];
lindex=i;
}
}
}
//最終找到lindex、cindex對(duì)應(yīng)格子分配,盡量滿足一方
//ASMatrix[pnum][cindex]表示第cindex已經(jīng)分配數(shù)、ASMatrix[lindex][snum]表示已經(jīng)供應(yīng)的數(shù)量
//需求量和分配量之間的關(guān)系,分配后標(biāo)記每行、列和的格子也相應(yīng)加上
if((sw[cindex]-ASMatrix[pnum][cindex])(pw[lindex]-ASMatrix[lindex][snum])){
ASMatrix[lindex][cindex]=Math.round((sw[cindex]-ASMatrix[pnum][cindex])*100)/100f;
ASMatrix[pnum+1][cindex]=-1; //該列已經(jīng)分配完畢
}else if((sw[cindex]-ASMatrix[pnum][cindex])(pw[lindex]-ASMatrix[lindex][snum])){
ASMatrix[lindex][cindex]=Math.round((pw[lindex]-ASMatrix[lindex][snum])*100)/100f;
ASMatrix[lindex][snum+1]=-1;
tmpsum++; //該行生產(chǎn)量分配完畢
}else{
ASMatrix[lindex][cindex]=pw[lindex]-ASMatrix[lindex][snum];
ASMatrix[lindex][snum+1]=-1;
ASMatrix[pnum+1][cindex]=-1;
tmpsum++;
}
ASMatrix[lindex][snum]=Math.round((ASMatrix[lindex][snum]+ASMatrix[lindex][cindex])*100)/100f;
ASMatrix[pnum][cindex]=Math.round((ASMatrix[pnum][cindex]+ASMatrix[lindex][cindex])*100)/100f;
}else if(lindex!=-1){
mincost=0;
cindex=-1;
for(j=0;jsnum;j++){
if(ASMatrix[lindex][j]0||ASMatrix[pnum+1][j]==-1)
continue;
else if(mincost==0){
mincost=costMatrix[lindex][j];
cindex=j;
}else{
if(mincostcostMatrix[lindex][j]){
mincost=costMatrix[lindex][j];
cindex=j;
}
}
}
//最終找到lindex、cindex對(duì)應(yīng)格子分配
if((sw[cindex]-ASMatrix[pnum][cindex])(pw[lindex]-ASMatrix[lindex][snum])){
ASMatrix[lindex][cindex]=Math.round((sw[cindex]-ASMatrix[pnum][cindex])*100)/100f;
ASMatrix[pnum+1][cindex]=-1; //該列已經(jīng)分配完畢
}else if((sw[cindex]-ASMatrix[pnum][cindex])(pw[lindex]-ASMatrix[lindex][snum])){
ASMatrix[lindex][cindex]=Math.round((pw[lindex]-ASMatrix[lindex][snum])*100)/100f;
ASMatrix[lindex][snum+1]=-1;
tmpsum++; //該行生產(chǎn)量分配完畢
}else{
ASMatrix[lindex][cindex]=pw[lindex]-ASMatrix[lindex][snum];
ASMatrix[lindex][snum+1]=-1;
ASMatrix[pnum+1][cindex]=-1;
tmpsum++;
}
ASMatrix[lindex][snum]=Math.round((ASMatrix[lindex][snum]+ASMatrix[lindex][cindex])*100)/100f;
ASMatrix[pnum][cindex]=Math.round((ASMatrix[pnum][cindex]+ASMatrix[lindex][cindex])*100)/100f;
}
}
//至此,用行列差法找到了初始分配方案ASMatrix[i][j]==0表示叉去的格子,ipnum,jsnum
boolean findSolu=false;
int tmp1=0;
for(i=0;ipnum;i++)
for(j=0;jsnum;j++){
if(ASMatrix[i][j]0)
tmp1+=1;
}
if(tmp1(pnum+snum-1))
findSolu=true;
while(!findSolu){
// 位勢(shì)法求Rij,如果能找到0的說明要調(diào)整,否則找到最優(yōu)解
doLCPosiPower(costMatrix,ASMatrix,pnum,snum);
//Rij=cij-(ui+vj);對(duì)于分派矩陣中空格計(jì)算Rij
float rijmin=0; //存放最小的空格校驗(yàn)值
int rijminl=-1,rijminc=-1;
for(i=0;ipnum;i++){
for(j=0;jsnum;j++){
if(!(ASMatrix[i][j]0)((costMatrix[i][j]-ASMatrix[i][snum+2]-ASMatrix[pnum+2][j])rijmin)){
rijmin=Math.round((costMatrix[i][j]-ASMatrix[i][snum+2]-ASMatrix[pnum+2][j])*100)/100f;
rijminl=i;rijminc=j;
}
}
}
//如果校驗(yàn)值小于0,則用閉回路進(jìn)行調(diào)整
if(rijmin0){
//找閉回路,
int rijminOVl=-1,rijminOVc=-1; //rijmin對(duì)應(yīng)點(diǎn)的閉回路的頂點(diǎn)的i、j
boolean find=false;
// 向右邊上下找
for(j=rijminc+1;jsnum!find;j++){
if(ASMatrix[rijminl][j]0){
for(i=rijminl+1;ipnum;i++){
if(ASMatrix[i][rijminc]0(ASMatrix[i][j]0)){
rijminOVl=i;rijminOVc=j;
find=true;
break;
}
}
for(i=rijminl-1;i=0;i--){
if(ASMatrix[i][rijminc]0(ASMatrix[i][j]0)){
rijminOVl=i;rijminOVc=j;
find=true;
break;
}
}
}
}
// 向左邊上下找
for(j=rijminc-1;j=0!find;j--){
if(ASMatrix[rijminl][j]0){
for(i=rijminl+1;ipnum;i++){
if(ASMatrix[i][rijminc]0(ASMatrix[i][j]0)){
rijminOVl=i;rijminOVc=j;
find=true;
break;
}
}
for(i=rijminl-1;i=0;i--){
if(ASMatrix[i][rijminc]0(ASMatrix[i][j]0)){
rijminOVl=i;rijminOVc=j;
find=true;
break;
}
}
}
}
//記錄rijmin閉回路相鄰點(diǎn)中最小的,并調(diào)整分派矩陣
float minW=ASMatrix[rijminl][rijminOVc]ASMatrix[rijminOVl][rijminc]?
ASMatrix[rijminl][rijminOVc]:ASMatrix[rijminOVl][rijminc];
ASMatrix[rijminl][rijminOVc]=Math.round((ASMatrix[rijminl][rijminOVc]-minW)*100)/100f;
ASMatrix[rijminOVl][rijminc]=Math.round((ASMatrix[rijminOVl][rijminc]-minW)*100)/100f;
ASMatrix[rijminOVl][rijminOVc]=Math.round((ASMatrix[rijminOVl][rijminOVc]+minW)*100)/100f;
ASMatrix[rijminl][rijminc]=minW;
}else
findSolu=true;
}
ListInteger rv=new ArrayListInteger();
for(i=0;ipnum;i++)
for(j=0;jsnum;j++){
if(ASMatrix[i][j]0){
rv.add(i);
rv.add(j);
rv.add((int)ASMatrix[i][j]);
}
}
int[] tmprv=new int[rv.size()];
for(i=0;irv.size();i++){
tmprv[i]=rv.get(i);
}
return tmprv;
}
//根據(jù)分配矩陣和費(fèi)用矩陣求出分配矩陣中的行、列位勢(shì),pnum+2、sunm+2表示行、列位勢(shì)在ASMatrix中的位置
//由于方程組都是cij=ui+vj的形式,根據(jù)矩陣可以逐行逐列求解。
public static void doLCPosiPower(float[][] costMatrix,float[][] ASMatrix,int pnum,int snum){
int ansnum=0,lp=snum+2,cp=pnum+2; //lp列位置,cp行位置
boolean[] bs=new boolean[pnum+snum]; //0..pnum-1為行位勢(shì)
ASMatrix[0][lp]=0; //令u0=0
bs[0]=true;
ansnum+=1;
int i,j;
while(ansnumpnum+snum){
for(i=0;ipnum;i++){ //逐行求解,根據(jù)costMatrix[i][j]=ASMatrix[i][lp]+ASMatrix[cp][j]
for(j=0;jsnum!bs[i];j++){ //根據(jù)列位勢(shì)求行位勢(shì)
if(ASMatrix[i][j]0bs[pnum+j]){
ASMatrix[i][lp]=Math.round((costMatrix[i][j]-ASMatrix[cp][j])*100)/100f;
ansnum+=1;
bs[i]=true;
}
}
if(!bs[i])continue;
for(j=0;jsnum;j++){ //根據(jù)行位勢(shì)求列位勢(shì)
if(ASMatrix[i][j]0!bs[pnum+j]){
ASMatrix[cp][j]=Math.round((costMatrix[i][j]-ASMatrix[i][lp])*100)/100f;
ansnum+=1;
bs[pnum+j]=true;
}
}
}
}
}
/*
* 產(chǎn)銷不平衡,把它增加產(chǎn)地或者銷地轉(zhuǎn)化為平衡問題
* costMatrix費(fèi)用矩陣,pnum產(chǎn)地個(gè)數(shù),snum銷地個(gè)數(shù)
*/
public static int[] NBPSProcedure(float[][] costMatrix,int pnum,int snum,int[] pw,int[] sw){
int pwsum=0,swnum=0;
int i,j;
for(i=0;ipw.length;i++)
pwsum+=pw[i];
for(i=0;isw.length;i++)
swnum+=sw[i];
//產(chǎn)大于銷 增加一個(gè)銷地,單位費(fèi)用為0
int[] rv;
if(pwsumswnum){
float[][] nCostMatrix=new float[pnum][snum+1];
for(i=0;ipnum;i++)
for(j=0;jsnum;j++)
nCostMatrix[i][j]=costMatrix[i][j];
for(i=0;ipnum;i++)
nCostMatrix[i][snum]=0f;
int[] nsw=new int[snum+1];
for(i=0;isnum;i++)
nsw[i]=sw[i];
nsw[snum]=pwsum-swnum;
rv=BPSProcedure(nCostMatrix, pnum, snum+1, pw, nsw);
}
//銷大于產(chǎn) 增加一個(gè)產(chǎn)地
else if(pwsumswnum){
float[][] nCostMatrix=new float[pnum+1][snum];
for(i=0;ipnum;i++)
for(j=0;jsnum;j++)
nCostMatrix[i][j]=costMatrix[i][j];
for(j=0;jsnum;i++)
nCostMatrix[pnum][j]=0f;
int[] npw=new int[pnum+1];
for(i=0;ipnum;i++)
npw[i]=pw[i];
npw[pnum]=swnum-pwsum;
rv=BPSProcedure(nCostMatrix, pnum+1, snum, npw, sw);
}else
rv=BPSProcedure(costMatrix, pnum, snum, pw, sw);
return rv;
}
}
先來分析一下原理。
1.js調(diào)用手機(jī)或者pad終端的攝像頭,拍照。
2.蘋果或者安卓原生程序獲取到拍照的照片路徑,然后解析圖片二維碼,將二維碼中的內(nèi)容返回給前臺(tái)
3.前臺(tái)將內(nèi)容顯示在input框中。
網(wǎng)上有現(xiàn)成的來源庫(kù),自己搜索一下吧,二維碼解析已經(jīng)很普遍了,沒啥難度。
一般掃描二維碼,都是將代碼寫在硬件里,比如掃碼槍,電腦鏈接掃碼槍,直接將掃描內(nèi)容顯示在頁(yè)面上。