Simple Function

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 111    Accepted Submission(s): 31

Problem Description
Knowing that x can be any real number that x2 + Dx + E ≠ 0. Now, given the following function:

What is the range of y?
 
Input
The first line contains a single integer T (T ≤ 10000), indicating that there are T cases below.
Each case contains five integers in a single line which are values of A, B, C, D and E (-100 ≤ A, B, C, D, E ≤ 100).
 
Output
For each case, output the range of y in the form of standard interval expression like in a single line.
The expression is made up by one interval or union of several disjoint intervals.
Each interval is one of the following four forms: "(a, b)", "(a, b]", "[a, b)", "[a, b]"(there is a single space between ',' and 'b'), where a, b are real numbers rounded to 4 decimal places, or "-INF" or "INF" if the value is negative infinity or positive infinity.
If the expression is made up by several disjoint intervals, put the letter 'U' between adjacent intervals. There should be a single space between 'U' and nearby intervals.
In order to make the expression unique, the expression should contain as minimum of intervals as possible and intervals should be listed in increasing order.
See sample output for more detail.
 
Sample Input
5
1 1 1 2 3
0 1 0 1 -10
-3 -1 0 -1 -1
0 0 0 0 0
1 3 0 2 0
 
Sample Output
[0.3170, 1.1830]
(-INF, INF)
(-INF, -1.8944] U [-0.1056, INF)
[0.0000, 0.0000]
(-INF, 1.0000) U (1.0000, 1.5000) U (1.5000, INF)
 
Source
 
Recommend
zhuyuanchen520
 

2012长春的D题,当年只有两个队过,够坑的。

其实就是讨论的情况比较多,折腾了一天终于分析清楚了,还debug了好久。

我是把分母乘过来分析的。

另外一种分析方法见:

http://blog.happybin.org/archives/zoj_3658_simple-function_2012_changchun_site/

我的做法:

代码:

 /* ***********************************************
Author :kuangbin
Created Time :2013-10-5 12:05:22
File Name :E:\2013ACM\专题强化训练\区域赛\2012长春\D.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
const double eps = 1e-;
int main()
{
//freopen("d.in","r",stdin);
//freopen("out.txt","w",stdout);
int A,B,C,D,E;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d%d%d",&A,&B,&C,&D,&E);
if(B == D*A && C == E*A)
{
printf("[%.4lf, %.4lf]\n",1.0*A,1.0*A);
continue;
}
bool fA;//值域包不包含A
if(B == D*A)fA = false;
else
{
/*
double ttx = (double)(E*A-C)/(B-D*A);
if(fabs(ttx*ttx + D*ttx + E) < eps)fA = false;
else fA = true;
*/
int t1 = E*A - C;
int t2 = B-D*A;
if((long long)t1*t1 +(long long)D*t2*t1 +(long long)E*t2*t2 == )fA = false;
else fA = true;
}
if(D*D < *E)
{
int a = D*D - *E;
int b = *A*E + *C - *B*D;
int c = B*B - *A*C;
double l = (-b+sqrt(1.0*b*b-4.0*a*c))/(2.0*a);
double r = (-b-sqrt(1.0*b*b-4.0*a*c))/(2.0*a);
if(B != D*A)
{
if(fA)printf("[%.4lf, %.4lf]\n",l,r);
else printf("[%.4lf, %.4lf) U (%.4lf, %.4lf]\n",l,1.0*A,1.0*A,r);
}
else
{
if(fabs(A-l) < eps)printf("(%.4lf, %.4lf]\n",l,r);
else printf("[%.4lf, %.4lf)\n",l,r);
}
continue;
}
if(D*D == *E)
{
int f1 = *A*E + *C - *B*D;
double tt1 = (-D)/(2.0);
if(f1 == )//
{
if(B*B > *A*C)
{
if(fA)printf("(-INF, INF)\n");
else printf("(-INF, %.4lf) U (%.4lf, INF)\n",1.0*A,1.0*A);
}
else while();//****
//while(1);
}
else if(f1 > )
{
double l = (double)(-B*B + *A*C)/f1;
double tt2 = -(B-D*l)/(*A - *l);
if(fabs(tt2 - tt1) < eps)
{
if(!fA)
{
if(B != D*A)
printf("(%.4lf, %.4lf) U (%.4lf, INF)\n",l,1.0*A,1.0*A);
else printf("(%.4lf, INF)\n",l);
}
else printf("(%.4lf, INF)\n",l);
}
else
{
if(!fA)
{
if(B == D*A)printf("(%.4lf, INF)\n",l);
else printf("[%.4lf, %.4lf) U (%.4lf, INF)\n",l,1.0*A,1.0*A);
}
else printf("[%.4lf, INF)\n",l);
}
}
else
{
double r = (double)(-B*B + *A*C)/f1;
double tt2 = -(B-D*r)/(*A - *r);
if(fabs(tt2 - tt1) < eps)
{
if(!fA)
{
if(B != D*A)
printf("(-INF, %.4lf) U (%.4lf, %.4lf)\n",1.0*A,1.0*A,r);
else printf("(-INF, %.4lf)\n",r);
}
else printf("(-INF, %.4lf)\n",r);
}
else
{
if(!fA)
{
if(B == D*A)printf("(-INF, %.4lf)\n",r);
else printf("(-INF, %.4lf) U (%.4lf, %.4lf]\n",1.0*A,1.0*A,r);
}
else printf("(-INF, %.4lf]\n",r);
}
}
continue;
}
if(D*D > *E)
{
double root1 = (double)(-D + sqrt(D*D - *E) )/;
double root2 = (double)(-D - sqrt(D*D - *E))/;
int a = D*D - *E;
int b = *A*E + *C - *B*D;
int c = B*B - *A*C;
long long deta = (long long)b*b - (long long)*a*c;
if(deta < )
{
if(fA)printf("(-INF, INF)\n");
else printf("(-INF, %.4lf) U (%.4lf, INF)\n",1.0*A,1.0*A);
}
else if(deta == )
{
double y0 = (double)(-b)/(*a);
double tt2 = (double)(D*y0 - B)/(*(A-y0));
if(fabs(tt2 - root1) < eps || fabs(tt2 - root2) < eps)
{
if(!fA && A < y0 - eps)
printf("(-INF, %.4lf) U (%.4lf, %.4lf) U (%.4lf, INF)\n",(double)A,(double)A,y0,y0);
else if(!fA && A > y0+eps)
printf("(-INF, %.4lf) U (%.4lf, %.4lf) U (%.4lf, INF)\n",y0,y0,(double)A,(double)A);
else printf("(-INF, %.4lf) U (%.4lf, INF)\n",y0,y0);
}
else
{
if(!fA)
printf("(-INF, %.4lf) U (%.4lf, INF)\n",(double)A,(double)A);
else printf("(-INF, INF)\n");
}
}
else
{
double y1 = (double)(-b-sqrt(1.0*b*b-4.0*a*c))/(*a);
double y2 = (double)(-b+sqrt(1.0*b*b-4.0*a*c))/(*a);
double tt1 = (double)(D*y1 - B)/(*(A-y1));
double tt2 = (double)(D*y2 - B)/(*(A-y2));
bool fy1 = true;
bool fy2 = true;
if(fabs(tt1 - root1) < eps || fabs(tt1 - root2) < eps)
fy1 = false;
if(fabs(tt2 - root1) < eps || fabs(tt2 - root2) < eps)
fy2 = false;
if(!fA && fabs(y1 - A) < eps)fy1 = false;
if(!fA && fabs(y2 - A) < eps)fy2 = false;
if(fy1 && fy2)
{
if(!fA && A < y1 - eps)
printf("(-INF, %.4lf) U (%.4lf, %.4lf] U [%.4lf, INF)\n",(double)A,(double)A,y1,y2);
else if(!fA && A > y2 + eps)
printf("(-INF, %.4lf] U [%.4lf, %.4lf) U (%.4lf, INF)\n",y1,y2,(double)A,(double)A);
else printf("(-INF, %.4lf] U [%.4lf, INF)\n",y1,y2);
}
else if(fy1 && !fy2)
{
if(!fA && A < y1 - eps)
printf("(-INF, %.4lf) U (%.4lf, %.4lf] U (%.4lf, INF)\n",(double)A,(double)A,y1,y2);
else if(!fA && A > y2 + eps)
printf("(-INF, %.4lf] U (%.4lf, %.4lf) U (%.4lf, INF)\n",y1,y2,(double)A,(double)A);
else printf("(-INF, %.4lf] U (%.4lf, INF)\n",y1,y2);
}
else if(!fy1 && fy2)
{
if(!fA && A < y1 - eps)
printf("(-INF, %.4lf) U (%.4lf, %.4lf) U [%.4lf, INF)\n",(double)A,(double)A,y1,y2);
else if(!fA && A > y2 + eps)
printf("(-INF, %.4lf) U [%.4lf, %.4lf) U (%.4lf, INF)\n",y1,y2,(double)A,(double)A);
else printf("(-INF, %.4lf) U [%.4lf, INF)\n",y1,y2);
}
else
{
if(!fA && A < y1 - eps)
printf("(-INF, %.4lf) U (%.4lf, %.4lf) U (%.4lf, INF)\n",(double)A,(double)A,y1,y2);
else if(!fA && A > y2 + eps)
printf("(-INF, %.4lf) U (%.4lf, %.4lf) U (%.4lf, INF)\n",y1,y2,(double)A,(double)A);
else printf("(-INF, %.4lf) U (%.4lf, INF)\n",y1,y2);
}
}
}
}
return ;
}

HDU 4423 Simple Function(数学题,2012长春D题)的更多相关文章

  1. 组合数学第一发 hdu 2451 Simple Addition Expression

    hdu 2451 Simple Addition Expression Problem Description A luxury yacht with 100 passengers on board ...

  2. zoj3658 Simple Function (函数值域)

    Simple Function Time Limit: 2 Seconds       Memory Limit: 32768 KB Knowing that x can be any real nu ...

  3. HDU 4291 A Short problem(2012 ACM/ICPC Asia Regional Chengdu Online)

    HDU 4291 A Short problem(2012 ACM/ICPC Asia Regional Chengdu Online) 题目链接http://acm.hdu.edu.cn/showp ...

  4. HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛

    普通的数位DP计算回文串个数 /* HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 2-36进制下回文串个数 */ ...

  5. HDU 6050 - Funny Function | 2017 Multi-University Training Contest 2

    /* HDU 6050 - Funny Function [ 公式推导,矩阵快速幂 ] 题意: F(1,1) = F(1, 2) = 1 F(1,i) = F(1, i-1) + 2 * F(1, i ...

  6. 2018 HDU多校第三场赛后补题

    2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube ...

  7. A Simple Math Problem 矩阵打水题

    A Simple Math Problem Lele now is thinking about a simple function f(x).If x < 10 f(x) = x.If x & ...

  8. HDU 5832 A water problem(某水题)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  9. 2018 HDU多校第四场赛后补题

    2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...

随机推荐

  1. Docker学习笔记一 概念、安装、镜像加速

    本文地址:https://www.cnblogs.com/veinyin/p/10406378.html  Docker 是一个容器,可以想象成一个轻便的虚拟机,但不虚拟硬件和操作系统. 优点:启动快 ...

  2. Nessus扫描策略

    本篇将简单介绍下Nessus的扫描策略设置.选用plugins及如何使用定制的策略来进行扫描任务. Step 1: 启动Nessus服务 root@kali:~# /etc/init.d/nessus ...

  3. Spark笔记之累加器(Accumulator)

    一.累加器简介 在Spark中如果想在Task计算的时候统计某些事件的数量,使用filter/reduce也可以,但是使用累加器是一种更方便的方式,累加器一个比较经典的应用场景是用来在Spark St ...

  4. Redis持久化——AOF

    一.是什么? AOF是以日志的形式来记录每个写操作,将Redis执行过的所有写操作记录下来(读操作不做记录),只许追加文件不可以改写文件,Redis启动之初会读取该文件重新构建数据,换言之,Redis ...

  5. Three.js基础探寻三——透视投影照相机

    本篇主要介绍Three.js照相机中的透视投影照相机. 上一篇:正交投影照相机 5.透视投影照相机构造函数 透视投影照相机(Perspective Camera)的构造函数是: THREE.Persp ...

  6. Nginx是什么,有什么优点?为什么选择Nginx做web服务器软件?(经典经典)

    1.基础知识 代理服务器:    一般是指局域网内部的机器通过代理服务器发送请求到互联网上的服务器,代理服务器一般作用在客户端.应用比如:GoAgent,FQ神器.    一个完整的代理请求过程为:客 ...

  7. mysql8.0 在window环境下的部署与配置

    今天在阿里云window服务器上配置mysql环境,踩了一些坑,分享出来.需要的朋友可以看看.额,或许有人要吐槽我为什么不在linux上去配置,额,因为我window的那台服务器配置相对高些.本人技术 ...

  8. flask基础之LocalProxy代理对象(八)

    前言 flask框架自带的代理对象有四个,分别是request,session,g和current_app,各自的含义我们在前面已经详细分析过.使用代理而不是显式的对象的主要目的在于这四个对象使用太过 ...

  9. 使用@SpringBootApplication注解

    很多Spring Boot开发者总是使用@Configuration , @EnableAutoConfiguration 和 @ComponentScan 注解他们的main类. 由于这些注解被如此 ...

  10. ps命令实用方法.ps -l ps -L详解

    一.统计sleep状态的进程. c233 plugins # ps -elf|head -1F S UID     PID   PPID C PRI   NI       ADDR SZ   WCHA ...