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. shell test条件判断

    test 条件判断 # 符号 [ ] 等同  test命令 test -lt # 判断大小 echo $? # 查看上句test命令返回状态 # 结果0为真,1为假 test -n "hel ...

  2. [CEOI2015 Day2]世界冰球锦标赛 (双向搜索)

    题目描述 [CEOI2015 Day2]世界冰球锦标赛译自 CEOI2015 Day2 T1「Ice Hockey World Championship」 今年的世界冰球锦标赛在捷克举行.Bobek ...

  3. 银行卡号码校验算法(Luhn算法,又叫模10算法)

    有时候在网上办理一些业务时有些需要填写银行卡号码,当胡乱填写时会立即报错,但是并没有发现向后端发送请求,那么这个效果是怎么实现的呢. 对于银行卡号有一个校验算法,叫做Luhn算法. 一.银行卡号码的校 ...

  4. Linux驱动中completion接口浅析(wait_for_complete例子,很好)

    completion是一种轻量级的机制,它允许一个线程告诉另一个线程工作已经完成.可以利用下面的宏静态创建completion:                          DECLARE_CO ...

  5. 大数据系列之数据仓库Hive命令使用及JDBC连接

    Hive系列博文,持续更新~~~ 大数据系列之数据仓库Hive原理 大数据系列之数据仓库Hive安装 大数据系列之数据仓库Hive中分区Partition如何使用 大数据系列之数据仓库Hive命令使用 ...

  6. Jmeter遇到Connection reset by peer的解决方法

    解决方案如下: 1.修改HTTP请求下面的Impementation选项,改成HttpClient4 2.修改了/bin/jmeter.bat文件:找到这2行 set HEAP=-Xms256m -X ...

  7. intellij 出现“Usage of API documented as @since 1.8+”的解决办法

    intellij 出现“Usage of API documented as @since 1.8+”的解决办法 Usage of API documented as @since 1.8+ This ...

  8. K-means聚类算法的三种改进(K-means++,ISODATA,Kernel K-means)介绍与对比

      一.概述 在本篇文章中将对四种聚类算法(K-means,K-means++,ISODATA和Kernel K-means)进行详细介绍,并利用数据集来真实地反映这四种算法之间的区别. 首先需要明确 ...

  9. Linux学习笔记:常用命令grep、iconv、cp、mv、rm

    本篇记录一些近期常用的命令. 一.grep过滤 grep过滤 不包含某些字符串 cat test.txt | grep -v '.jpg' 过滤jpg结尾的图片 cat test.txt | grep ...

  10. 在centos中修改yum源为阿里源

    cd /etc/yum.repos.d 备份旧的配置文件:mv CentOS-Base.repo CentOS-Base.repo.bak 下载阿里源的文件: wget -O CentOS-Base. ...