ZOJ 1241 Geometry Made Simple
/*
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<stdio.h>
#include<math.h> int main(){
double a,b,c;
int n=0;
while(scanf("%lf%lf%lf",&a,&b,&c)){
if(a==0&&b==0&&c==0)
break;
n++;
if (c==-1)
{
c=sqrt(a*a+b*b);
printf("Triangle #%d\n",n);
printf("c = %.3lf\n",c);
}
else
if (a==-1)
{
a=sqrt(c*c-b*b);
printf("Triangle #%d\n",n);
if (c>b)
printf("a = %.3lf\n",a);
else
printf("Impossible.\n");
}
else
if (b==-1)
{
b=sqrt(c*c-a*a);
printf("Triangle #%d\n",n);
if (c>a)
printf("b = %.3lf\n",b);
else
printf("Impossible.\n");
}
printf("\n"); } return 0;
}
ZOJ 1241 Geometry Made Simple的更多相关文章
- ZOJ Problem Set - 1241 Geometry Made Simple
水题不解释 #include <stdio.h> #include <math.h> int main() { ,flag=; double a,b,c; while(scan ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- MySQL所有函数及操作符
参考:Function and Operator Reference Name Description ABS() Return the absolute value ACOS() Return th ...
- arcgis地图服务之 identify 服务
arcgis地图服务之 identify 服务 在近期的一次开发过程中,利用IdentityTask工具查询图层的时候,请求的参数中ImageDisplay的参数出现了错误,导致查询直接不能执行,百度 ...
- 翻译:探索GLSL-用几何着色器(着色器库)实现法线可视化
翻译:探索GLSL-用几何着色器(着色器库)实现法线可视化 翻译自: Exploring GLSL – Normal Visualizer with Geometry Shaders (Shader ...
- Extensions for Spatial Data
http://dev.mysql.com/worklog/task/?spm=5176.100239.blogcont4270.8.j3asa7&id=6609 前文: 这两天因为项目原因看了 ...
- mysql 函数表
Name Description ABS() Return the absolute value ACOS() Return the arc cosine ADDDATE() Add time val ...
- cvpr2015papers
@http://www-cs-faculty.stanford.edu/people/karpathy/cvpr2015papers/ CVPR 2015 papers (in nicer forma ...
随机推荐
- Memcached 及 Redis 架构分析和比较
Memcached和Redis作为两种Inmemory的key-value数据库,在设计和思想方面有着很多共通的地方,功能和应用方面在很多场合下(作为分布式缓存服务器使用等) 也很相似,在这里把两者放 ...
- mongoose深层修改问题
https://cnodejs.org/topic/50dde64ea7e6c6171a80a678 各位大神好,好久没写点什么东西了,最近也是cnode社区不知道咋的了都登录不进去,今天总算能回到这 ...
- sql 行专列 列转行 普通行列转换
转载:http://www.cnblogs.com/newwind521/archive/2010/11/25/1887203.html sql 行专列 列转行 普通行列转换 /* 标题:普通行列转换 ...
- 用K2 smartforms开发一个应用程序究竟比ASP.NET快多少?
这次试验的起因是一场内部辩论. “用K2 smartforms开发一个应用程序究竟比ASP.NET快多少?” 我们推测是快4倍. 但是经过测试发现,我们推测错了. 本文记录了试验的规划.过程以及令人惊 ...
- java基础之 string
一 string public final class String 继承自java.lang.Object类. 实现了接口: java.io.Serializable, Comparable< ...
- Openstack Swift中间件编写
关于openstack swift的资料可以看这里,这里还有这里. 准备环境 从零开始接触的同学可以先从swift的all in one部署开始学习,在本机搭建好swift环境就可以进行简单的测试了. ...
- 更改layout的布局
创建了一个layout,缺省都是LinearLayout,原来都在xml把他改成其他布局,习惯了拖放的方式觉得挺麻烦. 其实vs2013有这个功能,就是在设计界面单机右键可以删除布局,然后拖一个布局进 ...
- HTML--8Window.document对象
1.Window.document对象 一.找到元素: docunment.getElementById("id"):根据id找,最多找一个: var a =docunme ...
- iOS数据存取和对象序列化
一. 使用NSKeyedArchiver类操作对象的存取 特点:该类可以将对象以键值对的形式存入文件,并通过key从文件中取出,与android中的SharedPreference用法类似,而且它序列 ...
- pyplot基本绘制(二)
本节主要解决在一个figure中放置多福图,以及图中一些注释文字的添加等问题. 先看一个效果图: 下面是实现代码: __author__ = 'hust' import numpy as np imp ...