Uva 1050 Ars Longa
Description
You have been struck with inspiration, and are designing a beautiful new art sculpture for the foyer of your local museum. For highly important artistic reasons, you are designing it using very specific materials. However, you are not sure if physics is on your side. Will your sculpture actually stand up?
The sculpture will be composed of various ball joints weighing 1 kilogram each, and various rods (of negligible weight) connecting the joints. Rods cannot be stretched or compressed, and they can never detach from a joint. However, they are free to rotate around the joints in any direction. The joints that lie on the ground are glued in place; all others are free to move. For simplicity, you may ignore the effects of intersections of rods; each rod exerts force only on the 2 joints connected to it. Also, any joint that is in the air will have at least one rod coming out that is not parallel to the ground. This prevents the degenerate case where a ball is supported only horizontally by a rigid structure. In real life, it would sag just a little.
Write a program to determine whether your structure is static (that is, will not immediately move from the effects of gravity). Note that each rod can transmit an arbitrarily large tensional force along its length, and that “being static” means that the tensional forces at each joint balance the weight of the joint.
If the structure is static, you must also determine whether it is stable (that is, will not move if perturbed slightly by pulling its joints).
Input
The input contains several sculpture descriptions. Every description begins with a line containing integers \(J\) and \(R\), the number of joints and rods in the structure, respectively. Joints are numbered from \(1\) to \(J\). The description continues with \(J\) lines, one per joint, each containing \(3\) floating point numbers giving the \(x,y,z\) coordinates of that joint. Following are \(R\) lines, one per rod, with \(2\) distinct integers indicating the joints connected by that rod.
Each rod is exactly the right length to connect its joints. The \(z\) coordinates will always be nonnegative; a \(z\) coordinate of \(0\) indicates that the joint is on the ground and fixed in place. There are at most \(100\) joints and \(100\) rods.
The last description is followed by a line containing two zeroes.
Output
For each sculpture description, output ‘NON-STATIC’, ‘UNSTABLE’, or ‘STABLE’, as shown in the sample output.
Sample Input
4 3
0 0 0
-1.0 -0.5 1.0
1.0 -0.5 1.0
0 1.0 1.0
1 2
1 3
1 4
0 0
Sample Output
Sculpture 1: NON-STATIC
将每根杆子当做变量。
对于不在地面上的每个小球,我们可以列出一个方程。即每根与他相连的杆子给球的力的矢量和为\((0,0,1)\)(注意:相互作用力等大反向),由于是个三元组,我们需要把他拆成三个方程,对\(x,y,z\)分别列即可。最后是否静止只需判断方程有没有解即可。
对于是否稳定,即给予一个外力,方程是否还有解。但是在原方程上调整值复杂度太高,不可行。我们考虑问题的本质,即我们只改变常量,未知量的系数什么的都不变。因此,若消元后方程出现了\(0=0\)的情况,改变右边常量,方程明显无解了,反之肯定有解(可用增广矩阵来理解)。
#include<cstring>
#include<cmath>
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define eps (1e-8)
#define maxn (310)
int J,R,tot,con[maxn][maxn],T; double val[maxn][maxn];
struct Node
{
double x,y,z;
inline void read() { scanf("%lf %lf %lf",&x,&y,&z); }
friend inline Node operator -(const Node &a,const Node &b) { return (Node){ a.x-b.x,a.y-b.y,a.z-b.z }; }
}joints[maxn];
inline int guass()
{
int now = 0;
for (int i = 1,j;i <= R;++i)
{
for (j = now+1;j <= tot;++j) if (fabs(val[j][i]) > eps) break;
if (j == tot+1) continue; ++now;
for (int k = 1;k <= R+1;++k) swap(val[now][k],val[j][k]);
for (j = 1;j <= tot;++j)
{
if (j == now) continue; double t = val[j][i]/val[now][i];
for (int k = 1;k <= R+1;++k) val[j][k] -= t*val[now][k];
}
}
for (int i = now+1;i <= tot;++i) if (fabs(val[i][R+1]) > eps) return 0;
if (now < tot) return 1; return 2;
}
int main()
{
freopen("1050.in","r",stdin);
freopen("1050.out","w",stdout);
while (++T)
{
tot = 0; memset(val,0,sizeof(val)); memset(con,0,sizeof(con));
scanf("%d %d\n",&J,&R); if (!J) break;
for (int i = 1;i <= J;++i) joints[i].read();
for (int i = 1,a,b;i <= R;++i) scanf("%d %d",&a,&b),con[a][b] = con[b][a] = i;
for (int i = 1;i <= J;++i)
{
if (fabs(joints[i].z) <= eps) continue; tot += 3;
for (int j = 1;j <= J;++j)
{
if (!con[i][j]) continue; int id = con[i][j];
Node vec = joints[i]-joints[j];
val[tot-2][id] = vec.x,val[tot-1][id] = vec.y,val[tot][id] = vec.z;
}
val[tot][R+1] = 1;
}
int res = guass();
if (!res) printf("Sculpture %d: NON-STATIC\n",T);
else if (res == 1) printf("Sculpture %d: UNSTABLE\n",T);
else printf("Sculpture %d: STABLE\n",T);
}
fclose(stdin); fclose(stdout);
return 0;
}
Uva 1050 Ars Longa的更多相关文章
- [转]Teach Yourself Programming in Ten Years——用十年教会自己编程
作者:Peter Norvig 译者:刘海粟 本文原文为:http://norvig.com/21-days.html 该翻译文档的PDF版可以在这里获得:http://download.csdn.n ...
- Teach Yourself Programming in Ten Years
Teach Yourself Programming in Ten Years——用十年教会自己编程 作者:Peter Norvig 译者:刘海粟 本文原文为:http://norvig.com/21 ...
- 转:Teach Yourself Programming in Ten Years——用十年教会自己编程
转自:http://blog.csdn.net/UndeadWraith/article/details/6140455 作者:Peter Norvig 译者:刘海粟 本文原文为:http://nor ...
- (转载)Peter Norvig:十年学会编程
作者 Peter Norvig 是计算机科学家,Google 的研究总监.在本文中,Peter Norvig会告诉你:为什么急功近利地学习软件开发技术是没效果滴? ================华丽 ...
- Peter Norvig:学习在于挑战和重复
黄小非译注(本文来自伯乐在线):本文作者Peter Norvig目前任职于Google,其职位是研究主管(Director of Research). Peter Norvig是享誉世界的计算机科学 ...
- Peter Norvig:十年学会编程
为啥都想速成? 随便逛一下书店,你会看到<7天自学Java>等诸如此类的N天甚至N小时学习Visual Basic.Windows.Internet的书.我用亚马逊网站的搜索功能,出版年份 ...
- UVa 12099 The Bookcase - 动态规划
题目大意 给定一些书,每个书有一个高度和宽度,然后将它们放到一个三层的书架里(要求每一层都不为空).定义书架的大小为每层最大的高度和 乘 每层宽度和的最大值.求最小的书架大小. 显然动态规划(直觉,没 ...
- 训练指南 UVA - 10917(最短路Dijkstra + 基础DP)
layout: post title: 训练指南 UVA - 10917(最短路Dijkstra + 基础DP) author: "luowentaoaa" catalog: tr ...
- [Q&A] MySQL Error 1050(42S01): Table already exist
[环境说明] 1:MySQL Server 5.5 2:MyEclipse 2014 3:JDK 1.7 造成该问题的可能原因: 1:用 Java 读取 SQL 文件,并执行其中的 sql 语句,但是 ...
随机推荐
- SqlBulkCopy高效能批量插入SQL SERVER
what SqlBulkCopy是.NET提供的用来批量插入数据的一个类,特别是将内存中的数据一次性插入到数据库,目前只能插入到SQL SERVER数据库,数据源可以是DataTable.IDataR ...
- 组合模式(Composite Pattern)
组合模式定义:组合模式允许你将对象组合成树形结构来表现"整体/局部"层次结构,组合能让客户以一致的方式处理个别对象以及对象组合. 当涉及到如:菜单,子菜单之类的问题时,会自然而然的 ...
- Linux常用系统调用
转载 http://www.ibm.com/developerworks/cn/linux/kernel/syscall/part1/appendix.html#icomments 按照惯例,这个列表 ...
- 如何在网页上显示html代码?
a: 把代码写在文本区域 <textarea> 标签中.可以设置 disabled="disabled" 属性,禁止用户操作.b: 把要显示在html文档中标签的 &q ...
- Mysql下在某一列后即表的某一位置添加新列的sql语句
Mysql简介 MySQL是一个开放源码的小型关联式数据库管理系统,开发者为瑞典MySQL AB公司.MySQL被广泛地应用在Internet上的中小型网站中.由于其体积小.速度快.总体拥有成本低,尤 ...
- ORACLE 数据库用户备份及表备份
表备份模式备份:exp system/pwd@127.0.0.1:1521/db owner=(user) file=E:\DB\db20150326.dmp tables=(table);还原 ...
- iOS 多张图片保存到相册问题(add multiple images to photo album)
不知道朋友们有木有做过多图保存到系统的相册这个需求,我在用`UIImageWriteToSavedPhotosAlbum`保存图片时候,在代理回调方`didFinishSavingWithError` ...
- OS X环境下SVN回滚工程到指定版本,回滚指定文件到指定版本
1.打开命令行终端 2.cd + 工程或文件目录 3.svn update 工程目录或文件目录 -r 版本号 在Xcode中选中文件,右键选择''show in finder''(也可以用快捷键,不过 ...
- JS中==和===的区别
1.对于string,number等基础类型,==和===是有区别的 1)不同类型间比较,==之比较“转化成同一类型后的值”看“值”是否相等,===如果类型不同,其结果就是不等 2)同类型比较,直接进 ...
- 九度OJ 1108 堆栈的使用
题目地址:http://ac.jobdu.com/problem.php?pid=1108 题目描述: 堆栈是一种基本的数据结构.堆栈具有两种基本操作方式,push 和 pop.Push一个值会将其压 ...