码迷,mamicode.com
首页 > 其他好文 > 详细

2.5 上海马拉松 C题题解

时间:2021-02-08 12:05:36      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:ken   task   div   typedef   ace   png   马拉松   clu   its   

技术图片

 

 技术图片

 

 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

ll a, b, c, d;

void solve1()
{
    if (a > 0)
    {
        puts("(-inf,inf)");
        puts("-1");
    }
    else
    {
        puts("-1");
        puts("(-inf,inf)");
    }
}

void solve2()
{
    db x = -b / (a * 2.0);
    if (a > 0)
    {
        printf("(%.2f,inf)\n", x);
        printf("(-inf,%.2f)", x);
    }
    else
    {
        printf("(-inf,%.2f)\n", x);
        printf("(%.2f,inf)", x);
    }
}

void solve3()
{
    a *= 3.0;
    b *= 2.0;
    ll delta = b * b - 4.0 * a * c;
    if (delta <= 0)
    {
        if (a > 0)
        {
            puts("(-inf,inf)");
            puts("-1");
        }
        else
        {
            puts("-1");
            puts("(-inf,inf)");
        }
    }
    else
    {
        db x1 = (-b - (db)sqrt(delta)) / (2.0 * a), x2 = (-b + (db)sqrt(delta)) / (2.0 * a);
        if (x1 > x2) swap(x1, x2);
        if (a > 0)
        {
            printf("(-inf,%.2f) (%.2f,inf)\n", x1, x2);
            printf("(%.2f,%.2f)", x1, x2);
        }
        else
        {
            printf("(%.2f,%.2f)\n", x1, x2);
            printf("(-inf,%.2f) (%.2f,inf)", x1, x2);
        }
    }
}

main()
{
////    freopen("3.in", "r", stdin);
////    freopen("3.out", "w", stdout);
    ll task;
    scanf("%lld", &task);
    if (task == 1) return puts("-1"), puts("-1"), 0;
    else if (task == 2 || task == 3 || task == 4) scanf("%lld", &a), solve1();
    else if (task == 5 || task == 6 || task == 7 || task == 8) scanf("%lld%lld", &a, &b), solve2();
    else scanf("%lld%lld%lld", &a, &b, &c), solve3();
}

 

 

2.5 上海马拉松 C题题解

标签:ken   task   div   typedef   ace   png   马拉松   clu   its   

原文地址:https://www.cnblogs.com/Chasing-Dreams-Z/p/14383395.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!