经典三分题

#define debug
#ifdef debug
#include <time.h>
#include "/home/majiao/mb.h"
#endif

#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <math.h>

#define MAXN ((int)1e5+7)
#define ll long long int
#define INF (0x7f7f7f7f)
#define fori(lef, rig) for(int i=lef; i<=rig; i++)
#define forj(lef, rig) for(int j=lef; j<=rig; j++)
#define fork(lef, rig) for(int k=lef; k<=rig; k++)
#define QAQ (0)

using namespace std;

#ifdef debug
#define show(x...) \ do { \ cout << "\033[31;1m " << #x << " -> "; \ err(x); \ } while (0)

void err() { cout << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#endif

#ifndef debug
namespace FIO {
	template <typename T>
		void read(T& x) {
			int f = 1; x = 0;
			char ch = getchar();

			while (ch < '0' || ch > '9') 
			{ if (ch == '-') f = -1; ch = getchar(); }
			while (ch >= '0' && ch <= '9') 
			{ x = x * 10 + ch - '0'; ch = getchar(); }
			x *= f;
		}
};
using namespace FIO;
#endif


int n, m, Q, K;

double H, h, D, lmt;

#if 0
double get_dist(double mid) {
	if(mid <= lmt) return h*D/H;
	else {
		double ret = D - mid;
		double A = D - mid, B = mid;
		double x = A*(H-h)/B;
		return (ret + x);
	}
}
#else
#define get_dist check
double check(double x) {
	if((H - h) / x * (D - x) > h) { //如果灯的高度小于影子到墙时底部到灯的距离
		return x / (H - h) * h;               //就返回第二种情况
	}
	return D - x + h - (H - h) / x * (D - x); //否则返回第一种
}
#endif

int main() {
#ifdef debug
	freopen("test", "r", stdin);
	clock_t stime = clock();
#endif
	scanf("%d ", &Q);
	while(Q--) {
		scanf("%lf %lf %lf ", &H, &h, &D);
		lmt = D - (h*D)/H;
		double lef = 0, rig = D, mid, midmid;
		for(int i=0; i<100; i++) {
			double tmp = (rig - lef) / 3;
			double L = tmp + lef, R = rig - tmp;
			if(get_dist(L) < get_dist(R)) lef = L;
			else rig = R;
		}
		printf("%.3lf\n", get_dist(lef));
	}





#ifdef debug
	clock_t etime = clock();
	printf("rum time: %lf 秒\n",(double) (etime-stime)/CLOCKS_PER_SEC);
#endif 
	return 0;
}




全部评论

相关推荐

10-27 17:26
东北大学 Java
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务