HDOJ 1330 Deck(叠木块-物理题啊!贪心算法用到了一点)
Problem Description
A single playing card can be placed on a table, carefully, so that the short edges of the card are parallel to the table’s edge, and half the length of the card hangs over the edge of the table. If the card hung any further out, with its center of gravity off the table, it would fall off the table and flutter to the floor. The same reasoning applies if the card were placed on another card, rather than on a table.
Two playing cards can be arranged, carefully, with short edges parallel to table edges, to extend 3/4 of a card length beyond the edge of the table. The top card hangs half a card length past the edge of the bottom card. The bottom card hangs with only 1/4 of its length past the table’s edge. The center of gravity of the two cards combined lies just over the edge of the table.
Three playing cards can be arranged, with short edges parallel to table edges, and each card touching at most one other card, to extend 11/12 of a card length beyond the edge of the table. The top two cards extend 3/4 of a card length beyond the edge of the bottom card, and the bottom card extends only 1/6 over the table’s edge; the center of gravity of the three cards lines over the edges of the table.
If you keep stacking cards so that the edges are aligned and every card has at most one card above it and one below it, how far out can 4 cards extend over the table’s edge? Or 52 cards? Or 1000 cards? Or 99999?
Input
Input contains several nonnegative integers, one to a line. No integer exceeds 99999.
Output
The standard output will contain, on successful completion of the program, a heading:
# Cards Overhang
(that’s two spaces between the words) and, following, a line for each input integer giving the length of the longest overhang achievable with the given number of cards, measured in cardlengths, and rounded to the nearest thousandth. The length must be expressed with at least one digit before the decimal point and exactly three digits after it. The number of cards is right-justified in column 5, and the decimal points for the lengths lie in column 12.
Sample Input
1
2
3
4
30
Sample Output
The line of digits is intended to guide you in proper output alignment, and is not part of the output that your solution should produce.
12345678901234567
# Cards Overhang
1 0.500
2 0.750
3 0.917
4 1.042
30 1.997
物理题!还是一个英语题!
题意:就是在桌面上铺一样的卡片,求最多能够超过桌面多少。
理想化条件:问题中几个理想化的用词—“水平桌面”、“完全相同”、“质量均匀”、“长方体”
物理学原理: 若物体的重心位于支持面的上方,当重力作用线在支持面内,重力矩与支持力矩平衡,物体处于平衡状态;反之,重力矩与支持力矩同方向,物体处于不平衡状态;临界的平衡条件为重力的作用线恰好经过支持面的边缘。
贪心法求解: 设每个卡片长度均为L,重力均为G。将卡片从上到下编号,依次为1、2、3、„、n。记第k(k=1,2,3,„,n)块卡片相对其下方支持物的最大允许伸出量为x.k(n号卡片的支持物为水平桌面,其余卡片的支持物为其下方的木块),第k块卡片及其上方所有卡片的公共重心到第k块卡片另一端的距离为g.k。显然,1号卡片的伸出量为及公共重心为
现加入2号卡片,1号卡片平衡的临界条件为其重力作用下恰好位于2号卡片对其支持面的边缘。公共重心的坐标是其各组成部分的重心坐标的加权平均,在图示位置下两个卡片的公共重心到2号卡片最左端的距离为
加入第k块卡片后的公共重心到第k块卡片最左端的距离为:
第t块木块的最大允许伸出量为:
总伸出量为:
贪心算法简介:
所谓贪心算法,就是指在对问题求解时,总是做出在当前看来是最好的选择。在本题中,每一步加入一个木块,1号木块的最大允许伸出量为L/2;加入2号木块后,两个木块的公共重心与1号木块的伸出量有关,那么2号木块的最大允许伸出量也就受1号木块的最大允许伸出量所限。由于贪心算法并非从整体最优上加以考虑,使得贪心算法并非对所有的问题都能求得最佳解;但在大多数情况下,贪心算法都能得出满意解。
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double[] dabiao = new double[100010];
double sum=0.0;
dabiao[1]=0.5;
for(int i=2;i<=100000;i++){
dabiao[i]=dabiao[i-1]+1.0/i/2.0;
}
System.out.println("# Cards Overhang");
while(sc.hasNext()){
int n = sc.nextInt();
System.out.printf("%5d%10.3f\r\n",n,dabiao[n]);
}
}
}
HDOJ 1330 Deck(叠木块-物理题啊!贪心算法用到了一点)的更多相关文章
- hdoj 4445 Crazy Tank 物理题/枚举角度1
Crazy TankTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- Codeforces Round #114 (Div. 1) A. Wizards and Trolleybuses 物理题
A. Wizards and Trolleybuses Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...
- hdu 5761 Rower Bo 物理题
Rower Bo 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5761 Description There is a river on the Ca ...
- hdu 5066 小球碰撞(物理题)
http://acm.hdu.edu.cn/showproblem.php?pid=5066 中学物理题 #include <cstdio> #include <cstdlib> ...
- Bungee Jumping---hdu1155(物理题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1155 题目很长,但是很容易理解,就是人从高s的桥上跳下来,手拉着长为l的绳子末端,如果绳子太短那么人将 ...
- [物理题+枚举] hdu 4445 Crazy Tank
题意: 给你N个炮弹的发射速度,以及炮台高度H和L1,R1,L2,R2. 问任选发射角度.最多能有几个炮弹在不打入L2~R2的情况下打入L1~R1 注意:区间有可能重叠. 思路: 物理题,发现单纯的依 ...
- HDU 1155 Bungee Jumping(物理题,动能公式,弹性势能公式,重力势能公式)
传送门: Bungee Jumping Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- 杭电 1155 Bungee Jumping(物理题)
Problem Description Once again, James Bond is fleeing from some evil people who want to see him dead ...
- 浙大PAT CCCC L3-013 非常弹的球 ( 高中物理题 )
题目链接 题意 : 刚上高一的森森为了学好物理,买了一个“非常弹”的球.虽然说是非常弹的球,其实也就是一般的弹力球而已.森森玩了一会儿弹力球后突然想到,假如他在地上用力弹球,球最远能弹到多远去呢?他不 ...
随机推荐
- OpenSSL与公钥私钥证书签名的千丝万缕
导语 人对任何事物的认识都是阶段性的,从无知到知晓,从懵懂到半知半解,从误解到将信将疑,从晕头转向到下定决心吃透. 介绍 OpenSSL是一个强大的命令行工具,它可以用来处理许多种跟PKI(Publi ...
- java cmd常用命令
熟悉Java的常用命令 面试例题11:使用jar命令. 请使用jar命令,将test文件夹压缩成.jar文件,并简述其压缩包的结构. 考点:对于Java程序员来说,更多情况下是使用集成Java开发工具 ...
- SKAction类
继承自 NSObject 符合 NSCodingNSCopyingNSObject(NSObject) 框架 /System/Library/Frameworks/SpriteKit.framewo ...
- freemarker的使用心得
freemarker眼下尽管使用的公司不多,可是在某些时候就必须使用,当须要遍历json数据的时候,眼下市面上的好多显示组件都达不到要求唯一能用的也就仅仅有freemarker了.在java里使用的模 ...
- Spring事务管理使用
发现问题 最近,碰到一个问题,再用spring实现事务管理的时候,发现不起作用,在出异常时,并不会回滚数据库操作. 我想实现的功能如下: @Transactional(isolation=Isolat ...
- Swift学习笔记 - 函数与闭包
import Foundation //1.函数的定义与调用//以 func 作为前缀,返回箭头 -> 表示函数的返回类型func sayHello(name: String) -> St ...
- git pull 代码很慢的问题
办公环境调整,之前开发机是和自己的电脑放同一网段内的,现在开发机放至到本地其他网段内,造成pull 代码很慢的问题,在网上查了一下 以下是原文,链接为 http://blog.sina.com.cn/ ...
- 【转】解决警告 warning: directory not found for option
转:http://blog.sina.com.cn/s/blog_6f72ff900101es6x.html 解决方法: 选择项目名称----->Targets----->Build Se ...
- codevs 4650 破损的键盘(链表)
/* 之前一直不重视链表 (好吧说实话主要是看着板子都是指针就怂了T.T) 这道题比较基础 应用了链表的思想 数组模拟指针 遇到的问题就是跑着跑着光标跳到前面或者跳到后面 我们用next储存每个点下一 ...
- call和apply区别
call和apply 基本上是一个意思 区别在于call的第二个参数可以是任意的类型,而apply的第二个参数必须是数组,也可以是arguments.call方法:语法:call(thisObj,Ob ...