package fin;
import tool.catchword;
import tool.readfile;
import org.apache.commons.math3.stat.ranking.*;
public class pro {
int datanumber,s;
double[] y=new double[600];
double[] p=new double[600];
int number;
int[] point_y=new int[100];
int[] point_p=new int[100];
double[][] v=new double[100][11];
int[][] gotos=new int[100][11];
int[] op=new int[100];
String[] year=new String[5000];
String[] season=new String[5000];
public static void main(String[] args) {
pro te=new pro();
}
pro(){
catchdata xx=new catchdata();
xx.makedata();
y=xx.y;
p=xx.p;
number=xx.number;
year=xx.year;
season=xx.season;
double[] ys=new double[number];
double[] ps=new double[number];
p[0]=p[1];
for(s=0;s<number;s++){
ys[s]=y[s+1];
ps[s]=p[s+1]-p[s];
}
NaturalRanking ranking = new NaturalRanking(NaNStrategy.MINIMAL,TiesStrategy.MAXIMUM);
double[] datay =ys;
double[] rank_y =ranking.rank(datay);
double[] datap =ps;
double[] rank_p =ranking.rank(datap);
System.out.println(number);
for(s=0;s<number;s++){
point_y[s+1]=(int)(rank_y[s]/9)+1;
}
for(s=0;s<number;s++){
point_p[s+1]=(int)(rank_p[s]/9)+1;
}
int gap;
double e1;
for(s=1;s<11;s++){
gap=point_y[1]-s;
e1=point_p[1]-gap-5;
v[1][s]=e1*e1;
}
int t,sx;
for(t=2;t<number+1;t++){
for(s=1;s<11;s++){
gap=point_y[t]-s;
e1=point_p[t]-gap-5;
double u1=e1*e1;
double minv=999;
int sxs=0;
for(sx=1;sx<11;sx++){
double v1=u1+v[t-1][sx];
double e2=(s-sx)*(s-sx);
if(e2>2)v1=9999;
if(v1<minv)sxs=sx;
if(v1<minv)minv=v1;
}
gotos[t][s]=sxs;
v[t][s]=minv;
}
}
t=number;
double minv=999;
sx=0;
for(s=1;s<11;s++){
if(v[t][s]<minv)sx=s;
if(v[t][s]<minv)minv=v[t][s];
}
op[number]=sx;
for(s=1;s<number;s++){
t=number+1-s;
int m=op[t];
op[t-1]=gotos[t][m];
}
for(s=1;s<number+1;s++){
System.out.println(year[s]+"年"+season[s]+"期,"+point_y[s]+","+op[s]);
}
}}
import tool.catchword;
import tool.readfile;
public class catchdata {
int datanumber,s;
String[] data=new String[5000];
double[] y=new double[600];
double[] p=new double[600];
int number;
String[] year=new String[5000];
String[] season=new String[5000];
void makedata(){
readfile xx=new readfile();
xx.makedata("p.txt", "UTF-8");
data=xx.data;
datanumber=xx.datanumber;
int sx=0;
for(s=1;s<datanumber+1;s++){
catchword subb=new catchword();
String str=subb.makedata(data[s],"code_credit");
int n=Integer.parseInt(str);
if(n==44)sx=sx+1;
str=subb.makedata(data[s],"value");
if(n==44)p[sx]=num(str);
}
readfile xx2=new readfile();
xx2.makedata("gdp.txt", "UTF-8");
data=xx2.data;
datanumber=xx2.datanumber;
sx=0;
for(s=1;s<datanumber+1;s++){
catchword subb=new catchword();
String str=subb.makedata(data[s],"code_credit");
int n=Integer.parseInt(str);
String strx=subb.makedata(data[s],"year");
String str2=subb.makedata(data[s],"season");
if(n==48)sx=sx+1;
str=subb.makedata(data[s],"value");
if(n==48)y[sx]=num(str);
if(n==48)year[sx]=strx;
if(n==48)season[sx]=str2;
}
number=sx;
}
int numx(String str){
int nx;
nx=0;
try{
nx=Integer.parseInt(str);
}catch (Exception e) {}
return nx;
}
double num(String str){
double nx;
nx=0;
try{
nx=Double.parseDouble(str);
}catch (Exception e) {}
return nx;
}
}
最終更新:2015年04月21日 02:45