UVa 11236 - Grocery store

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mobius_strip/article/details/85252834

题目

输出20.00以内的四元组,四元组的和与积相同。

分析

枚举即可。枚举精度为0.01,这里为了处理精度误差,直接用整数处理(全都乘以100)。

说明

圣诞节在实验室写代码,ε=(´ο`*)))唉

#include <stdio.h>
#include <stdlib.h>

int main()
{
	for (int a1 = 8; a1 <= 125; a1 ++) {
		for (int a2 = a1; a2 <= 2000; a2 ++) {
			for (int a3 = a2; a3 <= 2000; a3 ++) {
				if (a1 * a2 * a3 > 1000000) {
					long long a4 = 1000000LL * (a1 + a2 + a3) / (a1 * a2 * a3 - 1000000LL);
					if (a3 <= a4 && a1 + a2 + a3 + a4 <= 2000 && 1000000LL * (a1 + a2 + a3 + a4) == a1 * a2 * a3 * a4) {
						printf("%.2lf %.2lf %.2lf %.2lf\n", a1/100.0, a2/100.0, a3/100.0, a4/100.0);
					}
				}
			}
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/mobius_strip/article/details/85252834