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 语句,但是 ...
随机推荐
- HDU1010(bfs)
#include <stdio.h>#include <iostream>#include <string.h>#include <stdlib.h>u ...
- mac 终端中添加tree命令显示文件目录结构
在Ubuntu下,通过 sudo apt-get install tree 可以使用tree命令,显示文件目录列表,如图所示: 在mac OS X系统下怎么使用呢? 在终端输入: cd $home ...
- Mysql 半同步复制配置
以下是配置和监控半同步复制: 1. 半同步复制功能以plugin的方式接入MySQL,需要在主库与从库两端同时开启半同步的支持,具体配置如下: On the master mysql> INST ...
- mysql远程连接错误提醒:2013-Lost connection to MySQL server at ‘reading initial communication packet', system error: 0
因为没有匹配/etc/hosts.allow. 解决方法: 1.在hosts.allow 文件中添加 mysqld:ALL [root@ucDB204 ~]# cat /etc/hosts.allow ...
- ReadWriteLock与ReentrantReadWriteLock
JAVA的JUC包中的锁包括"独占锁"和"共享锁".JUC中的共享锁有:CountDownLatch.CyclicBarrier.Semaphore.Reent ...
- How to: cgminer (Bitcoin, Litecoin etc.) + AMD Radeon driver install on CentOS
UPDATE 7/7/13: If you want to use Catalyst drivers version 12.8 you will find that X won’t start (er ...
- js基础1
一.JavaScript 不同于Java 有三部分组成 核心(ECMAScript) 文档对象模型(DOM) 浏览器对象模型(BOM) 二.var 是定义数据前加的前缀 三.弹出 alert( ) ...
- 玩转html5<canvas>画图
导航 前言 基本知识 绘制矩形 清除矩形区域 圆弧 路径 绘制线段 绘制贝塞尔曲线 线性渐变 径向渐变(发散) 图形变形(平移.旋转.缩放) 矩阵变换(图形变形的机制) 图形组合 给图形绘制阴影 绘制 ...
- java中关于时间的格式化
long time = System.currentTimeMillis(); SimpleDateFormat format = new SimpleDateFormat(); String s = ...
- 状态栏通知Notification的简单使用
今天在学习Notification时同时参考了一些相关的博客,现在结合自身学习实际来总结一下. 在使用手机时,当有未接来电或者短消息时,通常会在手机屏幕上的状态栏上显示.而在Android中有提醒功能 ...