Geometry Made Simple

Geometry Made Simple

Description

Mathematics can be so easy when you have a computer. Consider the following example. You probably know that in a right-angled triangle, the length of the three sides a, b, c (where c is the longest side, called the hypotenuse) satisfy the relation a*a+b*b=c*c. This is called Pythagora’s Law.

Here we consider the problem of computing the length of the third side, if two are given.

Input

The input contains the descriptions of several triangles. Each description consists of a line containing three integers a, b and c, giving the lengths of the respective sides of a right-angled triangle. Exactly one of the three numbers is equal to -1 (the ‘unknown’ side), the others are positive (the ‘given’ sides).

A description having a=b=c=0 terminates the input.

Output

For each triangle description in the input, first output the number of the triangle, as shown in the sample output. Then print “Impossible.” if there is no right-angled triangle, that has the ‘given’ side lengths. Otherwise output the length of the ‘unknown’ side in the format “s = l”, where s is the name of the unknown side (a, b or c), and l is its length. l must be printed exact to three digits to the right of the decimal point.

Print a blank line after each test case.

Sample Input

3 4 -1

-1 2 7

5 -1 3

0 0 0

Sample Output

Triangle #1

c = 5.000

Triangle #2

a = 6.708

Triangle #3

Impossible.

题意分析:这是一道三角形的勾股定理的题目,这道题目的题意大体是按顺序输入a、b、c三条边, c为斜边,如果输入-1表示该边为未知边,求此边长度,如果没有,输出不可能。

下面给一下代码:

#include<stdio.h>
#include<math.h>
int main()
{
    int i=1;
    int  a, b, c;
    double x;
    while(scanf("%d %d %d",&a, &b, &c)==3)
    {
        x=0;
        if(a==0&&b==0&&c==0)
        {
            break;
        }
        printf("Triangle #%d\n",i);
        if(a==-1)
        {
            x=c*c-b*b;
            if(x<0)
            {
                printf("Impossible.\n");
            }
            else
            {
                printf("a = %.3f\n",(double)sqrt(x));
            }

        }
        else if(b==-1)
        {
            x=c*c-a*a;
            if(x<0)
            {
                printf("Impossible.\n");
            }
            else
            {
                printf("b = %.3f\n",(double)sqrt(x));
            }

        }
        else
        {
            x=a*a+b*b;
            if(x<0)
            {
                printf("Impossible.\n");
            }
            else
            {
                printf("c = %.3f\n",(double)sqrt(x));
            }

        }
         i++;
         printf("\n");
    }
    return 0;
}

时间: 2024-10-09 23:03:03

Geometry Made Simple的相关文章

Geometry是否Simple检查

问题: 判断一个几何图形是否Simple,当一个Geometry转换成ITopologicalOperator2时,无论Geometry     是否为Simple,其IsKnownSimple和IsSimple属性都为True. 解决方法: 只需要先把IsKnownSimple_2设置成False中行了. 代码: private bool IsSimple(IGeometry pGeo) { ITopologicalOperator2 pTopo = pGeo as ITopologicalO

zju 1241 Geometry Made Simple

Geometry Made Simple Time Limit: 2 Seconds      Memory Limit: 65536 KB Mathematics can be so easy when you have a computer. Consider the following example. You probably know that in a right-angled triangle, the length of the three sides a, b, c (wher

Mysql空间数据,空间索引,Spatial Data,Spatial Index

前文: 这两天因为项目原因看了一下MySQL的空间索引,发现网上的资料不多,查了一下官方文档,为了强化记忆做了一个简单的翻译.基本上理解了mysql空间索引的要点.谨以此纪. Extensions for Spatial Data Open Geospatial Consortium (OGC) 是一个由超过两百五十个公司,机构,大学组成的致力于发展管理空间数据的解决方案的组织. OGC 发布了OpenGIS® Implementation Standard for Geographic inf

POJ百道水题列表

以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive

zoj题目分类

饮水思源---zoj 转载自:http://bbs.sjtu.edu.cn/bbscon,board,ACMICPC,file,M.1084159773.A.html 注:所有不是太难的题都被归成了“简单题”,等到发现的时候已经太晚了,我太死脑筋 了……:( 有些题的程序我找不到了,555……:( SRbGa的题虽然都很经典……但是由于其中的大部分都是我看了oibh上的解题报告后做 的,所以就不写了…… 题目排列顺序没有规律……:( 按照个人感觉,最短路有的算做了DP,有的算做了图论. 有些比较

MySQL5.6空间扩展(原创)

MySQL空间扩展 MySQL空间扩展支持几何数据的存储,生成,分析,优化. 1.空间数据类型(存储) MySQL支持以下数据类型: Geometry:可以存储所有的几何类型 Point:简单点 LINESTRING:简单线 POLYGON:简单面 MULITIPOINT:多点 MULITILINESTRING:多线 MUILITIPOLYGON:多面 GEOMETRYCOLLECTION:任何几何集合 在创建表的时候可以根据需求选择合适的几何类型存储你的空间数据. 2.空间数据类型的生成 My

Extensions for Spatial Data

前文: 这两天因为项目原因看了一下MySQL的空间索引,发现网上的资料不多,查了一下官方文档,为了强化记忆做了一个简单的翻译.基本上理解了mysql空间索引的要点.谨以此纪. Extensions for Spatial Data Open Geospatial Consortium (OGC) 是一个由超过两百五十个公司,机构,大学组成的致力于发展管理空间数据的解决方案的组织. OGC 发布了OpenGIS® Implementation Standard for Geographic inf

Arcgis Runtime for andriod 100 Simple marker symbol

//create a simple marker symbolSimpleMarkerSymbol symbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, Color.RED, 12); //size 12, style of circle //add a new graphic with a new point geometryPoint graphicPoint = new Point(-226773, 6550477

如何使用sqlserver 2012 空间查询(geometry及 geography)

---恢复内容开始--- 介绍 SQL Server 2008为大地测量空间数据提供了geography数据类型为平面空间数据提供了geometry数据类型.这两个都是Microsoft .NET Framework通用语言运行时(CLR)类型,并且可以用来存储不同种类的地理元素,例如点.线和多边形.这两个数据类型都提供了你可以用来执行空间操作的属性和方法,例如计算位置间的距离和找出两者间交叉的地理特性(例如一条河流经一个城镇.) geography 数据类型 geography数据类型为空间数