链接

题意:给定三角形的三个顶点A(0,0) ,B(Xb,0),C(Xc,Yc);在底边AB能否找到一个整数点x0使得三角形能被x=x0分为部分相等的两部分。

题解:本题主要考察了数学知识和二分。当Xc大于Xb/2时,x0一定在0到Xc之间,在此区间进行二分查找,最后判断一下是否满足条件。注意不能用除号,可能有误差。第二种情况,x0一定在Xc到Xb之间,在此区间进行二分,需要注意的只有check的判断条件,以及搞清楚是r收缩还是l收缩。

代码

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <math.h>
#include <string>
#define PI 3.14159
using namespace std;

typedef pair<int,int> PII;
typedef long long LL;
const int MAX_INT =  0x3f3f3f3f;
const int N = 1e5+15;
const int mod = 1e9+7;

void solve()
{
    int xb,xc,yc;
    cin>>xb>>xc>>yc;
    int l,r;
    if(xc>xb/2)
    {
        l = 0;
        r = xc;
        while(l<r)
        {
            int mid = (l+r)>>1;
            if(2*mid*mid >= xb*xc)r=mid;
            else l = mid+1;
        }
        if(2*l*l == xb * xc)
            cout<<"YES"<<endl;
        else 
            cout<<"NO"<<endl;
        
    }
    else
    {
        l = xc;
        r = xb;
        while(l<r)
        {
            int mid = (l+r)>>1;
            if((xb-mid)*(xb-mid) <= xb*xb/2 - xb *xc/2)r=mid;
            else l = mid+1;
        }
        if((xb-l)*(xb-l)*2 == xb*xb - xb *xc)
            cout<<"YES"<<endl;
        else 
            cout<<"NO"<<endl;
    }
    
}

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    int T = 1;
    cin>>T;
    while(T--)
    {
        solve();
    }
}