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就是调节层的显示优先级,决定哪个显示在最上方.作用范围 ...
随机推荐
- BZOJ 口胡记录
最近实在是懒的不想打代码...好像口胡也算一种训练,那就口胡把. BZOJ 2243 染色(树链剖分) 首先树链剖分,然后记录下每个区间的左右端点颜色和当前区间的颜色段.再对每个节点维护一个tag标记 ...
- 【bzoj4500】矩阵 带权并查集
题目描述 有一个n*m的矩阵,初始每个格子的权值都为0,可以对矩阵执行两种操作: 1. 选择一行, 该行每个格子的权值加1或减1. 2. 选择一列, 该列每个格子的权值加1或减1. 现在有K个限制,每 ...
- 【bzoj4165】矩阵 堆+STL-map
题目描述 定义和谐矩阵为长不小于 Mina 且宽不小于 Minb 的矩阵,矩阵的权值为整个矩阵内所有数的和.给定一个长为 N,宽为 M 的矩阵 A,求它的所有和谐子矩阵中权值第 K 小的矩阵,并输出它 ...
- Go语言【第十二篇】:Go数据结构之:切片(Slice)、范围(Range)、集合(Map)
Go语言切片(Slice) Go语言切片是对数组的抽象,Go数组的长度不可改变,在特定场景中这样的集合就不太适用,Go中提供了一种灵活,功能强悍的内置类型切片("动态数组"),与数 ...
- Luogu3936 Coloring(模拟退火)
裸退火,每次交换两个格子即可.依旧不会调参,稍微抄了点参数并且把随机种子设成了一个神奇的数字终于过掉了. #include<iostream> #include<cstdio> ...
- 协程-Greenlet
协程拥有自己的寄存器上下文和栈.协程调度切换时,将寄存器上下文和栈保存到其他地方,在切回来的时候,恢复先前保存的寄存器上下文和栈. 线程切换的时候会保存到CPU里面. 因此: 协程能保留上一次调用时的 ...
- 【原创】宿主机远程登录虚拟机(windows server 2003系统)
转载请注明,谢谢合作 1.虚拟机网络设置为 “桥接模式”如图 2.系统装好并登陆后 右键点击我的电脑,点击属性,然后在弹出来的选择框中勾选远程桌面-->启用这台计算机的远程桌面 然后点添加-- ...
- 【题解】SDOI2009Bill的挑战
这题好像状压的做法比较的无脑?但想记录一下容斥的做法,感觉自己对于容斥简直一无所知.这道题目容斥的解法我也是看了题解才会的.如有雷同,是我看的(*/ω\*)我们可以首先枚举当前字符串与给定的哪 \(k ...
- DFS搜索题素数环
素数环: 输入整数1,2,3,4,5,···,n组成一个环,使得相邻两个整数之和均为素数. 输出时从整数1开始逆时针排列.同一个环应恰好输出一次.n<=16. Sample: input: 6 ...
- Java并发之同步原语
volatile: 定义:Java编程语言允许线程访问共享变量,为了确保共享变量内被准确和一致性地更新,线程应该确保通过排它锁单独获得这个变量.根据volatile的定义,volatile有锁的语义. ...