【接近直角三角形的三角形】CodeForce 18A ——Triangle

來源:互聯網
上載者:User

題目來源:

這個題是個暴搜,要求先判斷是不是直角三角形,然後再判斷是否是接近直角三角形的三角形,方法是各邊座標加一或減一,如果能夠湊成直角三角形,那麼就是近似直角的三角形。輸入輸出也挺順,記住用勾股定理進行判斷。本來還擔心卡精度的,但是pow一下子就過了,看來可能是我想多了。

其實ACM中適當用用GOTO也是可以的。。。。= =:

#include <iostream>#include <cmath>using namespace std;class point{public:int x;int y;};point p[3];bool isrighttr(){int a,b,c;a=pow((p[0].x-p[1].x),2.0)+pow((p[0].y-p[1].y),2.0);b=pow((p[1].x-p[2].x),2.0)+pow((p[1].y-p[2].y),2.0);c=pow((p[2].x-p[0].x),2.0)+pow((p[2].y-p[0].y),2.0);    if(a==0||b==0||c==0)    return false;     if(a+b==c||a+c==b||b+c==a) return true; else return false;}int main(){for(int i=0;i<3;i++)cin>>p[i].x>>p[i].y;if(isrighttr()){cout<<"RIGHT"<<endl;goto over;}else{int pos=0;for(int i=0;i<3;i++)//暴搜 {for(int j=-1;j<2;j++){p[i].x+=j;if(isrighttr())pos=1;p[i].x-=j;//複原 p[i].y+=j;if(isrighttr())pos=1;p[i].y-=j;}}if(pos==1){cout<<"ALMOST"<<endl;goto over;}else{cout<<"NEITHER"<<endl;}}over:return 0;}    

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.