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 (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.

#include <iostream>
#include<cmath>
using namespace std;
int main(int argc, char *argv[])
{
    int a,b,c,n;
    n=0;
    cout.precision(3);
    while(cin>>a>>b>>c)
    {
           n++;
        if(a==0&& b==0 && c==0)    break;
            if(a==-1)
            {
                if(c*c-b*b<=0)
                {
                cout<<"Triangle #"    <<n <<endl;
                    cout<<"Impossible."    <<endl;
                    cout<<endl;
                }

                else
                    {
                    cout<<"Triangle #"    <<n <<endl;
                    cout<<"a = " <<fixed<<pow(c*c-b*b,.5)    <<endl;
                    cout<<endl;    

                }
            }

    else    if(b==-1)
            {
                if(c*c-a*a<=0)
                {
                cout<<"Triangle #"    <<n <<endl;
                    cout<<"Impossible."    <<endl;
                    cout<<endl;
                }

                else
                    {
                    cout<<"Triangle #"    <<n <<endl;
                    cout<<"b = " <<fixed<<pow(c*c-a*a,.5)    <<endl;
                    cout<<endl;    

                }
            }    

    else    if(c==-1)
            {
                      cout<<"Triangle #"    <<n <<endl;
                    cout<<"c = " <<fixed<<pow(a*a+b*b,.5)    <<endl;
                    cout<<endl;    

                }

    }

    return 0;
}

#include <iostream>
#include<cmath>
using namespace std;
int main(int argc, char *argv[])
{
 int a,b,c,n;
 n=0;
 cout.precision(3);
 while(cin>>a>>b>>c)
 {    
        n++;
     if(a==0&& b==0 && c==0)    break;
   if(a==-1)
   {
    if(c*c-b*b<=0)
    {
    cout<<"Triangle #" <<n <<endl;
     cout<<"Impossible." <<endl;
     cout<<endl;
    }
    
    else
     {
     cout<<"Triangle #" <<n <<endl;
     cout<<"a = " <<fixed<<pow(c*c-b*b,.5) <<endl;
     cout<<endl; 
     
    }
   }
   
 else if(b==-1)
   {
    if(c*c-a*a<=0)
    {
    cout<<"Triangle #" <<n <<endl;
     cout<<"Impossible." <<endl;
     cout<<endl;
    }
    
    else
     {
     cout<<"Triangle #" <<n <<endl;
     cout<<"b = " <<fixed<<pow(c*c-a*a,.5) <<endl;
     cout<<endl; 
     
    }
   } 
   
   
 else if(c==-1)
   {
             cout<<"Triangle #" <<n <<endl; 
     cout<<"c = " <<fixed<<pow(a*a+b*b,.5) <<endl;
     cout<<endl; 
     
    }
    
   
    
    
   
   
 }

return 0;
}

zju 1241 Geometry Made Simple

时间: 2024-10-28 11:25:14

zju 1241 Geometry Made Simple的相关文章

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 hy

Geometry是否Simple检查

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

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,有的算做了图论. 有些比较

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

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

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

BNU 28887——A Simple Tree Problem——————【将多子树转化成线段树+区间更新】

A Simple Tree Problem Time Limit: 3000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ID: 368664-bit integer IO format: %lld      Java class name: Main Prev Submit Status Statistics Discuss Next Type: None None Graph Theory 2-SA

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