Uva - 1612 - Guess

A competition was just over. It had 3 problems and n players. Each player had an ID number from 1 to n. The final rank was decided by the total score of the 3 problems. The higher the total score was, the higher a player ranked (the smaller the rank number). If two players got the same total score, the one with the smaller ID number got a higher rank. We've known for each problem, how much score each player might get if he din't solve totally wrong (if solved totally wrong, the player got zero in the problem). However, we don't know whether a player did get score in a problem. For a predicted final rank, you need to judge if the rank is possible.

Input 

Input contains several cases. For each case, the first line is an integer n, ( n $ \leq$ 16384) to indicate the number of players, followed by n lines, the ith of which contains three real numbers abc ( $ \leq$ abc< 1000ab and c have 2 decimal places at most.) to respectively indicate the score of each problem Playeri might get if he didn't solve totally wrong. Another line containing n integers follows to indicate the player ID number in the order from rank 1st to rank nth.

The last case is followed by a line containing only a zero.

Output 

For each case, if the rank is possible, output the highest possible total score for the player with the lowest rank (calculate to  2  decimal places), otherwise output `` No solution " (quotes for clarity).

Sample Input 

3
100 200 300
100 200 300
100 200 300
1 2 3
3
100 200 300
100 200 300
100 200 300
3 2 1
0

Sample Output 

Case 1: 600.00
Case 2: 400.00


Sample Explanation:


Case 1:


RankPlayer ID NumberProblem 1's ScoreProblem 2's ScoreProblem 3's Score
11100200300
22100200300
33100200300


Case 2:


RankPlayer ID NumberProblem 1's ScoreProblem 2's ScoreProblem 3's Score
13100200300
220 (wrong)200300
311000 (wrong)300

刚开始没理解题意,后来找了别人的题解才懂。

因为一共只有三道题,所以每个人的得分最多有8种可能性。把这8种可能性都算出来,存在数组里,排好序备用

排名就是一个天然的链表,给出了扫描的顺序

扫描时,维护两个变量:前一个player的最大得分 recd 和他的ID recdID

扫描到每个player时,从大到小遍历他的8种得分,如果有等于recd的得分,且这个player的ID大于recdID,则只需更新recdID。否则遇到第一个小于recd的得分,就更新recd和recdID。

如果在遍历完8种得分后,还没有满足上面两种情况的,则说明无解

最后只需打印recd的值即可。要注意float型变量相等的判断方法。

在UVa Board中,Brian Fry给了一个很好的提示:尝试不用float。一看得分的范围:10^3,两位小数,则可以果断的乘100得到一个范围为10^5的int。这样出错的机会又少了很多。最后除以100.0输出即可

AC代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <stack>
#include <queue>
#include <bitset> 
#include <cassert> 
#include <cmath>
#include <functional>

using namespace std;

const int maxn = 20000;
int n;
int rankOfPlayer[maxn];

void calcScores(vector<int>& v, int* a, int d, int maxd, int sum) { // 得到所有8种可能
	if (d == maxd)
		v.push_back(sum);
	else {
		calcScores(v, a, d + 1, maxd, sum + a[d]);
		calcScores(v, a, d + 1, maxd, sum);
	}
}

struct Player{
	vector<int> scores;
	int ID;
	Player(){}
	Player(int* a, int id) :ID(id){
		calcScores(scores, a, 0, 3, 0);
		sort(scores.begin(), scores.end());
	}
};

int main() {
	int kase = 1;
	while (scanf("%d", &n) && n) {
		memset(rankOfPlayer, -1, sizeof(rankOfPlayer));
		Player q[maxn];
		float data_fl[3];
		int data_int[3];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 3; j++) {
				scanf("%f", &data_fl[j]);
				data_int[j] = (int)(round((data_fl[j] * 100.0)));
			}
			Player& p = q[i];
			p = Player(data_int, i);
		}

		for (int i = 0; i < n; i++) {
			scanf("%d", &rankOfPlayer[i]);
		}
		int recd = 1000000;
		int recdID = -1;
		for (int i = 0; i < n; i++) {
			Player& u = q[rankOfPlayer[i] - 1];
			bool ok = false;
			for (int j = 7; j >= 0; j--) { // 从大到小
				if (u.scores[j] == recd && u.ID > recdID) { // 小分数ID比较大
					recdID = u.ID;
					ok = true;
					break;
				}
				else if (u.scores[j] < recd) { // 最小的分数
					recd = u.scores[j];
					recdID = u.ID;
					ok = true;
					break;
				}
			}
			if (!ok) {
				recd = -1;
				break;
			}
		}
		if (recd == -1) {
			printf("Case %d: No solution\n", kase++);
		}
		else {
			printf("Case %d: %.2f\n", kase++, recd / 100.0);
		}
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
牙科就诊管理系统利用当下成熟完善的SSM框架,使用跨平台的可开发大型商业网站的Java语言,以及最受欢迎的RDBMS应用软件之一的Mysql数据库进行程序开发。实现了用户在线查看数据。管理员管理病例管理、字典管理、公告管理、药单管理、药品管理、药品收藏管理、药品评价管理、药品订单管理、牙医管理、牙医收藏管理、牙医评价管理、牙医挂号管理、用户管理、管理员管理等功能。牙科就诊管理系统的开发根据操作人员需要设计的界面简洁美观,在功能模块布局上跟同类型网站保持一致,程序在实现基本要求功能时,也为数据信息面临的安全问题提供了一些实用的解决方案。可以说该程序在帮助管理者高效率地处理工作事务的同时,也实现了数据信息的整体化,规范化与自动化。 管理员在后台主要管理病例管理、字典管理、公告管理、药单管理、药品管理、药品收藏管理、药品评价管理、药品订单管理、牙医管理、牙医收藏管理、牙医评价管理、牙医挂号管理、用户管理、管理员管理等。 牙医列表页面,此页面提供给管理员的功能有:查看牙医、新增牙医、修改牙医、删除牙医等。公告信息管理页面提供的功能操作有:新增公告,修改公告,删除公告操作。公告类型管理页面显示所有公告类型,在此页面既可以让管理员添加新的公告信息类型,也能对已有的公告类型信息执行编辑更新,失效的公告类型信息也能让管理员快速删除。药品管理页面,此页面提供给管理员的功能有:新增药品,修改药品,删除药品。药品类型管理页面,此页面提供给管理员的功能有:新增药品类型,修改药品类型,删除药品类型。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值