本文主要是介绍8.10 第七场 Fall with Trees,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
8.10 第七场 Fall with Trees
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 2600 Accepted Submission(s): 618
Problem Description
Fall wants to draw a perfect binary tree.
We first stipulate that all nodes in the tree with the same depth also have the same y-coordinate in the plane. Define nodes with the same depth to be nodes at the same level, then the perfect binary tree has four properties.
- It is a full binary tree.
- The difference between the y-coordinates of two nodes at each adjacent level is a constant.
- The difference between the x-coordinates of two adjacent nodes at the same level is constant.
- The x-coordinate of each node is the average of the x-coordinates of its sons.
Fall has drawn the root node and its left and right sons of this binary tree. Now Fall intends to draw a total of k levels and cut the binary tree down and paste it on the wall afterwards, so he wants to know what is the area of the convex hull of all nodes of this perfect binary tree.
Hint
Here’s the picture of the perfect binary tree for the first example, whose area is SABC+SBCGD=14
Input
The input consists of multiple test cases.
The first line contains an integer T (T≤2×105) – the number of test cases.
For each test case:
In the first line, there is an integer k (2≤k≤104).
In the second line, there are six integers xroot,yroot,xlson,ylson,xrson,yrson∈[−104,104] ,which represent the coordinates of the root node and its sons.
It is guaranteed that all the coordinates meet the conditions of the question, which means:
- xlson+xrson=2×xroot
- ylson=yrson
- yroot>ylson,xlson<xrson
Output
For each test case, output a real number representing the answer, with three decimal places.
Sample Input
3
3
0 0 -2 -2 2 -2
4
0 0 -4 -2 4 -2
10000
0 0 -10000 -10000 10000 -10000
Sample Output
14.000
54.000
3999000000000.000
大概题意:
求题目描述的树所围成的面积
思路:
推导出复杂度O1
的求和公式后才能AC
代码:
//
// Created by Black on 2021/8/10.
//#include<iostream>
#include<cmath>
#include <cstdio>using namespace std;int main() {
// std::ios::sync_with_stdio(false);
// std::cin.tie(0);int t;double k;double xRoot, yRoot, xl, xr, yl, yr;scanf("%d", &t);while (t--) {
// cin >> k;scanf("%lf", &k);k--;scanf("%lf%lf%lf%lf%lf%lf", &xRoot, &yRoot, &xl, &yl, &xr, &yr);
// cin >> xRoot >> yRoot >> xl >> yl >> xr >> yr;double h = (yRoot - yr);double sum = (xr - xRoot) * (k - (1 - pow(0.5, k))) * 2;k--;sum += (xr - xRoot) * (k - (1 - pow(0.5, k))) * 2;sum *= h;
// for (int i = 1; i < k; ++i) {
// double xxr = 0, xxl = 0;
// xxr = xr + (xr - xRoot) / 2;
// xxl = xl - (xr - xRoot) / 2;
// sum += 1.0 * h * (xr - xl + xxr - xxl) / 2;
// xRoot = xr;
// xl = xxl;
// xr = xxr;
// }printf("%.3f\n", sum);}return 0;
}
/**
** 4 4+2 4+2+1* 4 4+2* 相加乘h** 2 2+1* 2* 相加乘h*
*/
这篇关于8.10 第七场 Fall with Trees的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!