BOJ 1003 Guess

//此题目的难点就在于高精度上了
//微小增量0.001,0.0001,0.00001。。。。。。。都是可以的。
#include<iostream>
#include<algorithm>
using namespace std;

int all[16390][8];
int cmp(int a,int b){
	return a>b;
}
int N;
double a,b,c;
int i,j,num=0;
int rank[16390];
int main(){
	double dd=10;
	while(scanf("%d",&N)&&N){
		num++;
		printf("Case %d: ",num);
		for(i=0;i<N;i++){
			scanf("%lf%lf%lf",&a,&b,&c);
			all[i][0]=(int)((a+0.000001)*100);
			all[i][1]=(int)((b+0.000001)*100);
			all[i][2]=(int)((c+0.000001)*100);
			all[i][3]=all[i][0]+all[i][1];
			all[i][4]=all[i][0]+all[i][2];
			all[i][5]=all[i][1]+all[i][2];
			all[i][6]=all[i][0]+all[i][1]+all[i][2];
			all[i][7]=0;
			sort(all[i],all[i]+8,cmp);
		}
		for(i=0;i<N;i++)
			scanf("%d",&rank[i]);
		bool flag=false;
		i=0,j=1;
		int m=0,n=0;
		while(i<N&&j<N&&m<8&&n<8){
			if(rank[i]<rank[j]){
				if(all[rank[i]-1][m]>=all[rank[j]-1][n]){
					i=j;
					j++;
					m=n;
					n=0;
				}else{
					n++;
				}
			}else{
				if(all[rank[i]-1][m]>all[rank[j]-1][n]){
					i=j;
					j++;
					m=n;
					n=0;
				}else{
					n++;
				}
			}
		}
		if(j==N&&n!=8)
			flag=true;
		if(flag)
			printf("%.2lf\n",(double)all[rank[N-1]-1][m]/100);
		else
			cout<<"No solution"<<endl;
	}
	return 0;
}

你可能感兴趣的:(BOJ 1003 Guess)