2137.cpp

来自「这是哈尔滨工业大学acmOJ的源代码」· C++ 代码 · 共 41 行

CPP
41
字号
/*  This Code is Submitted by wywcgs for Problem 2137 on 2006-06-23 at 20:16:22 */ 
#include <cstdio>
#include <cmath>
#include <cctype>
#include <algorithm>
using namespace std;

const int N = 32;
const int LMT = 10000;
const double eps = 1e-8;

int main()
{
	double p[N];
	int n, i, j, t;

	for(t = 1; scanf("%d", &n) != EOF && n != 0; t++) {
		int pn; double d = 0.5;
		for(i = 0; i < n; i++) {
			char num[16]; scanf("%s", num);
			for(pn = 0; isdigit(num[pn]); pn++) ;
			pn = strlen(num)-pn-1;
			sscanf(num, "%lf", &p[i]);
		}
		for(i = 0; i < pn; i++) d /= 10;
		for(i = 1; i < LMT; i++) {
			int us = 0, ds = 0;
			for(j = 0; j < n; j++) {
				us += (int)floor(min(p[j]+d-eps, 100.0)/100*i);
				ds += (int)ceil(max(p[j]-d, 0.0)/100*i);
			}
			if(ds <= i && us >= i) break;
		}
		printf("Case %d: ", t);
		if(i < LMT) printf("%d\n", i);
		else printf("error\n");
	}
	
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?