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 语句,但是 ...
随机推荐
- arcgis python 获得所有的工具名称
#######################import arcgisscripting import string; gp = arcgisscripting.create(9.3); ### ...
- char与varchar区别
char:储存定长数据,长度不够,以空格填满.储存效率高. varchar: 变长数据,根据数据长度储存,节省空间,效率低.
- Java SSL/TLS Socket实现
通信端无需向对方证明自己的身份,则称该端处于"客户模式",否则称其处于"服务器模式",无论是客户端还是服务器端,都可处于"客户模式"或者&q ...
- 【C#】获取本地Cookie的问题
using System; using System.Net; using System.IO; using System.Text; // // TODO: 在此处添加代码以启动应用程序 // st ...
- 关于sqlserver 2008 远程导入表数据
/*不同服务器数据库之间的数据操作*/ --创建链接服务器 exec sp_addlinkedserver 'ITSV ', ' ', 'SQLOLEDB ', '远程服务器名或ip地址 ' ex ...
- Objective-C MRC多个对象相互引用的内存管理
在MRC环境下,假定CTRoom对象是CTPerson的一个成员变量,那么修改CTRoom对象时应注意,代码如下: - (void) setRoom:(CTRoom *) room { //需判断新旧 ...
- 不一样的编码风格--Lambda表达式
Lambda表达式也是C#3.0中最重要的特性之一. 1.Lambda表达式的简介 Lambda表达式可以理解为一个匿名方法,它可以包含表达式和语句,并且用于创建委托或转换为表达式树.在使用Lambd ...
- 八卦某 G 的前端开发方式及流程
他山之石,可以攻玉. 话说本人从毕业到现在一直在某 B 公司工作,前些年折腾过不少开发方式和工具,但总觉得或许有更好的方案,所以很好奇其它公司内部是如何工作的,我曾经浏览过某 Y 公司内部无所不包 ...
- java web 文件上传下载
文件上传下载案例: 首先是此案例工程的目录结构:
- SGU 解题报告
Volume 1 Volume 2