H

Tic Tac DREAMIN’

https://ac.nowcoder.com/acm/contest/120563/H

三角形的面积1/2*|向量AB向量AO|,该题中向量AB为(xb-xa,yb-ya),向量AC为(xc-xa,yc-ya),由题意得yc=0,所以该三角形的面积便为 1/2|(xb-xa)(-ya)+(yb-ya)(xc-xa)|,此时我们还需要考虑yb=ya,当yb=ya时,三角形的面积为: 1/2*|(xb-xa)*(-ya)|,若能让该式子等于2,则xc可以为任何数字,反之则no answer;当yb!=ya时,三角形的面积为2,所以我们所要求的xc=4-((yb-ya)*xa-(xb-xa)*ya))/(-(yb-ya)),同时由于题目需求,需要的输出小于小数点后7位

#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main(){
    double xa,ya,xb,yb;
    cin>>xa>>ya>>xb>>yb;
    if(yb==ya){
        if(fabs(fabs((xb-xa)*ya)-4)==0){
            cout<<"0"
        } 
        else{
            cout<<"no answer";
        }
    } 
    else{
        double x=(4-((yb-ya)*xa-(xb-xa)*ya))/(-(yb-ya));
        cout<<fixed<<setprecision(10)<<x;
    }
    return 0;
}
全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务