8.10 第七场 Fall with Trees

2023-11-01 13:20
文章标签 trees fall 8.10 第七场

本文主要是介绍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的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/323284

相关文章

【docker】基于docker-compose 安装elasticsearch + kibana + ik分词器(8.10.4版本)

记录下,使用 docker-compose 安装 Elasticsearch 和 Kibana,并配置 IK 分词器,你可以按照以下步骤进行。此过程适用于 Elasticsearch 和 Kibana 8.10.4 版本。 安装 首先,在你的工作目录下创建一个 docker-compose.yml 文件,用于配置 Elasticsearch 和 Kibana 的服务。 version:

MIT 6.5940 EfficientML.ai Fall 2023: Lab 1 Pruning

EfficientML.ai Lec 3 - Pruning and Sparsity (Part I) MIT 6.5940, Fall 2023, Zoom 本文是EfficientML.ai Fall 2023课程作业1练习答案,在本次练习里将会对经典的分类神经网络进行剪枝处理,减少模型大小和延迟。The goals of this assignment are as fo

【LeetCode】Unique Binary Search Trees I II

1、Unique Binary Search Trees  Total Accepted: 11405 Total Submissions: 32197 My Submissions Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example

CMU15445 (Fall 2023) Project2 - EXTENDIBLE HASH INDEX 思路分享

文章目录 Task 1 - Read/Write Page GuardsPageGuard函数实现移动构造函数移动赋值函数UpgradeRead/UpgradeWriteDrop析构函数BufferPoolManager函数实现FetchPageBasicFetchPageRead/FetchPageWriteNewPageGuarded BUG调试 Task2 - Hash Table P

leetcode-Unique Binary Search Trees

Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example, Given n = 3, there are a total of 5 unique BST's. 去网上搜n个二叉搜索树的递推公式或者Catalan数,可以由h(n)=C(

红帽8.10静默安装单实例oracle19C

一. 依赖 1. 配置dnf源 vim local.repo[BaseOS]name=BaseOSbaseurl=file:///mnt/BaseOSenabled=1gpgcheck=0[AppStream]name=AppStreambaseurl=file:///mnt/AppStreamenabled=1gpgcheck=0 2. 程序安装 Oracle依赖 d

Unique Binary Search Trees II问题及解法

问题描述: Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1...n. 示例: Given n = 3, your program should return all 5 unique BST's shown below. 1

Unique Binary Search Trees问题及解法

问题描述: Given n, how many structurally unique BST's (binary search trees) that store values 1...n? 示例: Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1\

Codeforces Round #236 (Div. 2) B. Trees in a Row

B. Trees in a Row time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The Queen of England has n trees growing in a row i

HDU 2841 Visible Trees 容斥

题意(一开始也没怎么看懂): 一个人站在(0,0)处,树从(1,1)点开始排,共有m*n棵。如果两棵树在同一视线上(意思是两个点和(0,0)的斜率相同),则只看到前面一棵树,问你那个人能看到几棵树。 思路: 容斥。 简单分析之后,其实本质就是让你求gcd(x,y)=1有几组。(x,y)和(y,x)算两种。 这题和HDU 1695差不多,只不过那题(x,y)和(y,x)算一种。