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 语句,但是 ...
随机推荐
- UISenior之数据的本地化持久化
数据的本地化主要分为两个方面:1.简单数据的本地持久化(NSString.NSArray.NSDictionary.NSData)2.复杂数据的本地持久化(本文以Person类为例) 简单对象的本地化 ...
- kickstart安装
1.生成ks.cfg 文件 安装Kickstart # yum install system-config-kickstart 8.2 在桌面环境下配置Kickstart 启动X Windows 环境 ...
- Atom编辑器入门到精通(三) 文本编辑基础
身为编辑器,文本编辑的功能自然是放在第一位的,此节将总结常用的文本编辑的方法和技巧,掌握这些技巧以后可以极大地提高文本编辑的效率 注意此节中用到的快捷键是Mac下的,如果你用的系统是Win或者Linu ...
- js 字符串编码转换函数
escape 方法 对 String 对象编码以便它们能在所有计算机上可读, escape(charString) 必选项 charstring 参数是要编码的任意 String 对象或文字. 说明 ...
- hbuilder用自己的服务
2016-03-10 以后写测试demo用Sublime3 http://docs.emmet.io/cheat-sheet/ 更多炫酷信息和emmet语法请参见: 视频demo 语法文档 2016- ...
- 不需要软件让Windows7变身WIFI热点
很简单,就是把一台装有windows 7操作系统,并配有无线网卡的电脑变成一台无线路由器或无线AP,以便在没有路由器的环境中实现多台无线终端(比如支持wifi的手机.电脑等设备)共享无线网络.那么我们 ...
- 2013年10月13日学习:SQL通过命令语句来创建表
优点:操作简单,不容易出错,易于调试 缺点:需要记住命令.命令多了就容易混淆,是吧!但是熟悉了时间长了就OK了! step 1. 新建数据库,命名为Test 点击图形化界面中的新建查询,此时就可以输入 ...
- SQL Server调优系列基础篇 - 索引运算总结
前言 上几篇文章我们介绍了如何查看查询计划.常用运算符的介绍.并行运算的方式,有兴趣的可以点击查看. 本篇将分析在SQL Server中,如何利用先有索引项进行查询性能优化,通过了解这些索引项的应用方 ...
- MathType支持64位 WIN 7Office 2013(完美解决)(转载)
经过几次尝试解决了,方法如下: 1. 安装MathType 6.8 (别的版本不知是否适用,本人安装的是该版本) 2. 将以下两个文件拷贝出来 C:\Program Files (x86)\MathT ...
- 周末充电之WPF(二 ) .窗口的布局
登录窗口布局:[ Grid 布局 -Grid.RowDefinitions / Grid.ColumnDefinitions] 代码如下: <Window x:Class="login ...