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就是调节层的显示优先级,决定哪个显示在最上方.作用范围 ...
随机推荐
- Codeforces Round#516 Div.1 翻车记
A:开场懵逼.然后发现有人1min过,于是就sort了一下,于是就过了.正经证明的话,考虑回文串两端点一定是相同的,所以最多有Σcnti*(cnti+1)/2个,cnti为第i种字母出现次数.而sor ...
- Vika and Segments - CF610D
Vika has an infinite sheet of squared paper. Initially all squares are white. She introduced a two-d ...
- Give NetScaler a “Tune-Up”
Give NetScaler a “Tune-Up” https://www.citrix.com/blogs/2014/10/21/give-netscaler-a-tune-up/ To Opti ...
- Android Bitmap和Drawable互转及使用BitmapFactory解析图片流
一.Bitmap转Drawable Bitmap bmp=xxx; BitmapDrawable bd=new BitmapDrawable(bmp); 因为BtimapDrawable是Drawab ...
- Eclipse配置web开发环境
eclipse的web配置: eclipse:Eclipse Java EE IDE for Web Developers. Version: Helios Service Release 1 下载地 ...
- cuda环境下安装opencv出现nvcc warning : The 'compute_11'
警告打印: nvcc warning : The 'compute_11', 'compute_12', 'compute_13', 'sm_11', 'sm_12', and 'sm_13' arc ...
- 三大linux系统对比
概述: centos作为服务器部署是第一选择.CentOS去除很多与服务器功能无关的应用,系统简单但非常稳定,命令行操作可以方便管理系统和应用,丰富的帮助文档和社区的支持. ubuntu最佳的应用领域 ...
- MEF——.NET中值得体验的精妙设计
摘要:.NET 是 Microsoft XML Web services 平台.MEF是.NET Framework 4.0一个重要的库,Visual Studio 2010 Code Editor的 ...
- HDU 5869 Different GCD Subarray Query 树状数组+离线
Problem Description This is a simple problem. The teacher gives Bob a list of problems about GCD (Gr ...
- python keras YOLOv3实现目标检测
1.连接 https://www.jianshu.com/p/3943be47fe84