Ichihime and Triangle(超时)

Ichihime作为麻将灵魂神殿的现任女祭司,正参加一场数学竞赛,目标是找到三个整数x,y,z,构成一个具有正面积的三角形,以赢得她最爱的饼干奖励。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Ichihime is the current priestess of the Mahjong Soul Temple. She claims to be human, despite her cat ears.These days the temple is holding a math contest. Usually, Ichihime lacks interest in these things, but this time the prize for the winner is her favorite — cookies. Ichihime decides to attend the contest. Now she is solving the following problem.
You are given four positive integers a, b, c, d, such that a≤b≤c≤d.Your task is to find three integers x,y,z, satisfying the following conditions:a≤x≤b.b≤y≤c.c≤z≤d.There exists a triangle with a positive non-zero area and the lengths of its three sides are xx, yy, and zz.Ichihime desires to get the cookie, but the problem seems too hard for her. Can you help her?
Input
The first line contains a single integer tt (1≤t≤1000) — the number of test cases.The next tt lines describe test cases. Each test case is given as four space-separated integers a,b,c,d (1≤a≤b≤c≤d≤109).
Output
For each test case, print three integers x, y, z — the integers you found satisfying the conditions given in the statement.It is guaranteed that the answer always exists. If there are multiple answers, print any.
Example
input
4
1 3 5 7
1 5 5 7
100000 200000 300000 400000
1 1 977539810 977539810
output
3 4 5
5 5 5
182690 214748 300999
1 977539810 977539810

//求高人指点一二,测试超时
#include<iostream>
using namespace std;
int main()
{
 long long int n,a,b,c,d,x,y,z,i=0;
 cin>>n;
 while(n--)
 {
  cin>>a>>b>>c>>d;
  int i,flag=0;
  for(int x=b;x>=a;x--)
  {
   for(int y=c;y>=b;y--)
   {
    for(int z=d;(z>=c&&(flag==0));z--)
    {
     if((x+y>z)&&(x+z>y)&&(y+z>x))
     {
      cout<<x<<" "<<y<<" "<<z<<endl;
      flag=1;
     }
    }
   }
  }
 }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

【执珪】瑕瑜·夕环玦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值