HDU 4423 Simple Function(数学题,2012长春D题)
Simple Function
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 111 Accepted Submission(s): 31

What is the range of y?
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).
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.
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
(-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)
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题)的更多相关文章
- 组合数学第一发 hdu 2451 Simple Addition Expression
hdu 2451 Simple Addition Expression Problem Description A luxury yacht with 100 passengers on board ...
- zoj3658 Simple Function (函数值域)
Simple Function Time Limit: 2 Seconds Memory Limit: 32768 KB Knowing that x can be any real nu ...
- 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 ...
- HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛
普通的数位DP计算回文串个数 /* HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 2-36进制下回文串个数 */ ...
- 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 ...
- 2018 HDU多校第三场赛后补题
2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube ...
- 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 & ...
- HDU 5832 A water problem(某水题)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- 2018 HDU多校第四场赛后补题
2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...
随机推荐
- 20155222 2016-2017-2 《Java程序设计》第6周学习总结
20155222 2016-2017-2 <Java程序设计>第6周学习总结 教材学习内容总结 从应用程序的角度来看,如果要将数据从来源中取出,可以使用输入串流:如果要将数据写入目的地,可 ...
- 20155306 2016-2017-2 《Java程序设计》第5周学习总结
20155306 2016-2017-2 <Java程序设计>第5周学习总结 教材学习内容总结 第八章 异常处理 8.1 语法与继承架构 Java中所有错误都会被打包为对象,运用try.c ...
- IL反编译的实用工具Ildasm.exe
初识Ildasm.exe——IL反编译的实用工具 https://www.cnblogs.com/yangmingming/archive/2010/02/03/1662307.html 学 ...
- 分模块开发创建dao子模块——(七)
1.选中父工程右键新建maven module
- python2.7中MySQLdb的安装与使用详解
Python2.7中MySQLdb的使用 import MySQLdb #1.建立连接 connect = MySQLdb.connect( '127.0.0.1', #数据库地址 'root', # ...
- 公司软raid问题
RAID的技术介绍: stripe width(条带宽度):RAID中的磁盘数,就是组成这个stripe的磁盘数.如,4个磁盘组成的RAID 0,条带宽度就是4. stripe depth(条带深度) ...
- (转载)mysql:设置mysql的远程访问
1.登陆Mysqlmysql -u root -p2.允许任何IP访问,其中密码为admingrant all privileges on *.* to root@"%" iden ...
- Linux 生产实习01
Linux 生产实习01 标签(空格分隔): Linux 2018.07.02 相关软件下载地址:Linux Study 0x01. 安装 VMware Workstation VMware Work ...
- python的map,filter,reduce学习
python2,python3中map,filter,reduce区别: 1,在python2 中,map,filter,reduce函数是直接输出结果. 2,在python3中做了些修改,输出前需要 ...
- Java第三阶段学习(五、流的操作规律、Properties流、序列化流与反序列化流、打印流、commons-IO jar包)
一.流的操作规律 四个明确: 明确一:明确要操作的数据是数据源还是数据目的地 源:InputStream Reader 目的地:OutputStream Writer 先根据需求明确是要读还是写 ...