sicily 1012. Stacking Cylinders & 1206. Stacking Cylinders
Time Limit: 1sec Memory Limit:32MB
Description
Cylinders (e.g. oil drums) (of radius 1 foot) are stacked in a rectangular bin. Each cylinder on an upper row rests on two cylinders in the row below. The cylinders in the bottom row rest on the floor. Each row has one less cylinder than the row below. This problem is to write a program to compute the location of the center of the top cylinder from the centers of the cylinders on the bottom row. Computations of intermediate values should use double precision. Input
Each data set will appear in one line of the input. An input line consists of the number, n, of cylinders on the bottom row followed by n floating point values giving the x coordinates of the centers of the cylinders (the y coordinates are all 1.0 since the cylinders are resting on the floor (y = 0.0)). The value of n will be between 1 and 10 (inclusive). The end of input is signaled by a value of n = 0. The distance between adjacent centers will be at least 2.0 (so the cylinders do not overlap) but no more than 3.4 (cylinders at level k will never touch cylinders at level k – 2).
Output
The output for each data set is a line containing the x coordinate of the topmost cylinder rounded to 4 decimal places, a space and the y coordinate of the topmost cylinder to 4 decimal places. Note: To help you check your work, the x-coordinate of the center of the top cylinder should be the average of the x-coordinates of the leftmost and rightmost bottom cylinders.
Sample Input
Copy sample input to clipboard
4 1.0 4.4 7.8 11.2 Sample Output
6.1000 4.1607 |
分析:
1. 首先,根据题意,程序的输入就是最底层的球,然后在其上面每层都比下一层少一个球,
. 可以证明,在底层的球每一个和其底层第一个球的横坐标的中点不为都有一个其上面球的横坐标,最后一个球对应最上面一个球,如图:
也就是利用等腰三角形来求解。
其实应该说首先要证明第一行的球其从第二个开始,每一个和第一个求,上一层的最左边球都会构成一个等腰三角形,根据这个性质去做就ok,
不要把题意理解为输入的球就是所有球,我开始就是这么理解的所以和一个小伙伴一起想了很久想了一个很复杂的办法,因为那样的话根本不知道分层情况,当然还是利用等腰三角形去解。然后在去饭堂吃饭的时候突然想明白了,,,
code:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio> using namespace std; #define RADIUS 2.0 int main(int argc, char const *argv[])
{
vector<double> xValue;
int pointNum;
double x, y; while (cin >> pointNum && pointNum != ) {
xValue.resize(pointNum);
y = RADIUS / ;
for (int i = ; i != pointNum; ++i) {
cin >> xValue[i];
}
sort(xValue.begin(), xValue.end());
x = xValue[]; for (int i = ; i != pointNum; ++i) {
double preX = x;
x = (xValue[i] - xValue[]) / + xValue[]; // 上一层的最左边球的横坐标,注意这个上一层是递增的
preX = x - preX;
y = sqrt(pow(RADIUS, ) - pow(preX, )) + y; // 上一层的最左边球的纵坐标,注意这个上一层是递增的,利用勾股定理
}
printf("%.4lf %.4lf\n", x, y);
}
return ;
}
至于 . Stacking Cylinders 这道题,其实方法是完全一样的,但是输入和输出格式都不一样,我看了好久才发现输入格式不一样。。。
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio> using namespace std; #define RADIUS 2.0 int main(int argc, char const *argv[])
{
vector<double> xValue;
int pointNum;
double x, y; int testNum;
cin >> testNum;
for (int i = ; i <= testNum; ++i) {
cin >> pointNum;
xValue.resize(pointNum);
y = RADIUS / 2.0;
for (int i = ; i != pointNum; ++i) {
cin >> xValue[i];
}
sort(xValue.begin(), xValue.end());
x = xValue[]; for (int i = ; i != pointNum; ++i) {
double preX = x;
x = (xValue[i] - xValue[]) / 2.0 + xValue[];
preX = x - preX;
y += sqrt(pow(RADIUS, 2.0) - pow(preX, 2.0));
}
printf("%d: %.4lf %.4lf\n", i, x, y);
}
return ;
}
sicily 1012. Stacking Cylinders & 1206. Stacking Cylinders的更多相关文章
- 层叠上下文 Stacking Context
层叠上下文 Stacking Context 在CSS2.1规范中,每个盒模型的位置是三维的,分别是平面画布上的x轴,y轴以及表示层叠的z轴.对于每个html元素,都可以通过设置z-index属性来设 ...
- Dream team: Stacking for combining classifiers梦之队:组合分类器
sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频) https://study.163.com/course/introduction.htm?courseId=1005269003& ...
- Stacking调参总结
1. 回归 训练了两个回归器,GBDT和Xgboost,用这两个回归器做stacking 使用之前已经调好参的训练器 gbdt_nxf = GradientBoostingRegressor(lear ...
- 集成学习中的 stacking 以及python实现
集成学习 Ensemble learning 中文名叫做集成学习,它并不是一个单独的机器学习算法,而是将很多的机器学习算法结合在一起,我们把组成集成学习的算法叫做“个体学习器”.在集成学习器当中,个体 ...
- 【书签】stacking、blending
读懂stacking:模型融合Stacking详解/Stacking与Blending的区别 https://blog.csdn.net/u014114990/article/details/5081 ...
- 【集成学习】:Stacking原理以及Python代码实现
Stacking集成学习在各类机器学习竞赛当中得到了广泛的应用,尤其是在结构化的机器学习竞赛当中表现非常好.今天我们就来介绍下stacking这个在机器学习模型融合当中的大杀器的原理.并在博文的后面附 ...
- visual formatting model (可视化格式模型)【持续修正】
概念: visual formatting model,可视化格式模型 The CSS visual formatting model is an algorithm that processes a ...
- ORACLE 移动数据文件 控制文件 重做日志文件
ORACLE数据库有时候需要对存储进行调整,增加分区.IO调优等等,此时需要移动数据文件.重做日志文件.控制文件等等,下文结合例子总结一下这方面的知识点. 进行数据文件.重做日志文件.控制文件的迁移前 ...
- 关于z-index的总结
z-index的作用 很多时候需要把一个元素覆盖到另一个元素之上,比如登入弹出框等,这个时候就需要z-index属性出场了.所以呢,z-index就是调节层的显示优先级,决定哪个显示在最上方.作用范围 ...
随机推荐
- axios post提交数据格式不对的问题
需要格式化一下 this.$http({ method: "post", url: "/chinacountry/index.php/home/Search/index& ...
- Git的安装与使用(一)
闲来无事写了个小demo,想上传到GitHub上,发现得使用git进行上传,所以得先了解下git . 1.git是什么 分布式版本控制器 2.svn与git的区别 svn:是集中式的版本控制系统,版本 ...
- [CH弱省胡策R2]TATT
description 洛谷 data range \[ n\le 5\times 10^4\] solution 这就是四维偏序了... 好象时间复杂度是\(O(n^{\frac{5}{3}})\) ...
- React属性用法总结
1. 键值对 <ClaaNameA name = “Tom” /> <ClaaNameA name = {Tom} /> <ClaaNameA name = {“Tom” ...
- bzoj1051: [HAOI2006]受欢迎的牛(tarjan强连通分量)
强连通缩下点,出度为0有多个答案为0,否则答案为出度为0的强连通分量中点的个数. 发现一道tarjan模板题,顺便复习一波tarjan #include<iostream> #includ ...
- [zhuan]arm中的汇编指令
http://blog.csdn.net/qqliyunpeng/article/details/45116615 一. 带点的(一般都是ARM GNU伪汇编指令) 1. ".text& ...
- httpClient需要的jar包
- some interesting words
No one gets rich betting against the market. Never bet against the Fed. Bulls make money, bears make ...
- selenium测试-open chrome
通过selenium来打开浏览器测试之前,需要确认本地已安装相应的webdriver,本例以chrome为例. 1. 查看本地chrome版本,以此确认需要安装的webdriver版本 查看chrom ...
- Basic Data Structure HDU - 5929 (这个模拟我要报警了)
Mr. Frog learned a basic data structure recently, which is called stack.There are some basic operati ...