比赛 20101119 评测结果 AWWWWWWAAW
题目名称 奥运会 最终得分 30
用户昵称 lc 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2010-11-19 10:09:51
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int maxn = 100010,INF = 100000000;
int val[maxn];
int N,K,P,Ans;
int G[maxn],S[maxn],B[maxn];



void prep()
{
	scanf("%d",&N);
	for (int i=1; i<=N; i++)
	{
		scanf("%d%d%d",&G[i],&S[i],&B[i]);
	}
}

int down(int x,int y)
{
	int p = x / y;
	if (p*y==x) return p;
	int t = x/abs(x) * y/abs(y);
	if (t>0) return p;
	else return p - 1;
}

int up(int x,int y)
{
	int p = x / y;
	if (p*y==x) return p;
	int t = x/abs(x) * y/abs(y);
	if (t>0) return p + 1;
	else return p;
}

void print(int Ans1,int Ans2,int Ans3)
{
	printf("%d %d %d\n",Ans1,Ans2,Ans3);
}


void work()
{
	for (int Pg=1; Pg<=1000; Pg++)
		for (int Ps=1; Ps<=Pg; Ps++)
		{
			for (int i=1; i<=N; i++) val[i] = Pg*G[i] + Ps*S[i];
			bool ok = true;
			int Pbmax = Ps,Pbmin = 1;
			for (int i=2; i<=N; i++)
			{
				if (B[i]==B[1])
				{
					if (val[i]>val[1]) {ok = false; break;}
					continue;
				}
				if (B[i] >B[1]) Pbmax = min(Pbmax , down(val[i]-val[1],B[1]-B[i]));
				if (B[i] <B[1]) Pbmin = max(Pbmin , up(val[i]-val[1],B[1]-B[i]));
				if (Pbmax <Pbmin) continue;
			}
			if (!ok) continue;
			if (Pbmax<Pbmin) continue;
			print(Pg,Ps,Pbmin); return;
		}
}

int main()
{
	freopen("olympic.in","r",stdin);
	freopen("olympic.out","w",stdout);
	prep();
	work();
	return 0;
}