A. Fence(欧几里得四边形形成条件)Codeforces Round #675 (Div. 2)

    科技2022-08-04  106

    原题链接: https://codeforces.com/contest/1422/problem/A

    测试样例

    input 2 1 2 3 12 34 56 output 4 42

    Note

    We can build a quadrilateral with sides 1, 2, 3, 4.

    We can build a quadrilateral with sides 12, 34, 56, 42.

    题意: 给你三条边的边长,需要你再找到一条边,使得这四条边构成一个四边形。

    解题思路: 这道题应该没什么好说的,和构成三角形一样,是一个知识点:任意三条边之和大于第四条边则可构成四边形。 故此题易解。我们在枚举的时候要注意上限,就是给出三条边是一个参考值,以它们之和为界即可。

    AC代码

    /* *邮箱:unique_powerhouse@qq.com *blog:https://me.csdn.net/hzf0701 *注:文章若有任何问题请私信我或评论区留言,谢谢支持。 * */ #include<bits/stdc++.h> //POJ不支持 #define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增 #define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。 #define pb push_back #define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0) #define fi first #define se second #define mp make_pair using namespace std; const int inf = 0x3f3f3f3f;//无穷大 const int maxn = 1e5;//最大值。 typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<int, int> pii; //*******************************分割线,以上为自定义代码模板***************************************// ll t,a[3]; bool junge(ll x){ if(a[0]+a[1]+x>a[2]&&a[0]+a[2]+x>a[1]&&a[1]+a[2]+x>a[0]){ return true; } else{ return false; } } int main(){ //freopen("in.txt", "r", stdin);//提交的时候要注释掉 IOS; while(cin>>t){ while(t--){ rep(i,0,2){ cin>>a[i]; } ll temp=a[0]+a[1]+a[2]; for(ll i=temp-1;i>0;i--){ if(junge(i)){ cout<<i<<endl; break; } } } } return 0; }
    Processed: 0.015, SQL: 8