当前位置:网站首页>洛谷P5139 z小f的函数
洛谷P5139 z小f的函数
2022-08-11 04:00:00 【CLH_W】
题目背景
zz小ff热爱数学。
题目描述
由于zz小ff要复习NOIpNOIp,而且他认为觉得数学作业太简单了,于是把数学作业交给了你。
题目如下:
给定二次函数y=ax^{2}+bx+c (a \neq 0)y=ax
2
+bx+c(a
=0),求函数的最大(小)值;
zz小ff当然不喜欢看见做这么简单的题目啦,于是他决定给函数进行如下操作:
操作 11:给定系数kk,将函数向上平移kk位,(kk<00则向下平移kk位)
操作22:给定系数kk,将函数向右平移kk位,(kk<00则向左平移kk位)
操作33:给定系数k_1,k_2k
1
,k
2
,将函数关于点(k_1,k_2)(k
1
,k
2
)进行对称变换
操作44:给定系数k_1,k_2k
1
,k
2
,求函数在闭区间[k_1,k_2][k
1
,k
2
]上的最小值和最大值
操作55:给定系数u,v,wu,v,w,求出二次函数yy与二次函数y_2=ux^{2}+vx+wy
2
=ux
2
+vx+w是否有交点。
由于zz小ff需要,你还要输出最终的二次函数yy此时的最大值(最小值)。
输入格式
第一行一个正整数TT,表示数学作业的题目数(即数据组数)
接下来TT组数据,对于每一组数据:
第一行三个数a,b,ca,b,c,表示二次函数的系数a,b,ca,b,c;
第二行一个正整数nn,表示操作的数量。
接下来nn行,每一行都有一个整数pp,表示操作的编号,接下来的数即操作的内容(见题目描述 )
由于zz小ff太可爱了,所以数据保证合法。
输出格式
对于每一个操作44,输出两个小数,分别表示区间的最小值与最大值(保留两位小数);
对于每一个操作55,输出一个整数,其中0表示没有交点,2表示有交点;
每组数据操作完成后,输出最终的二次函数yy此时的最大值(最小值)(保留两位小数)。
输入输出样例
输入 #1复制
1
1 0 0
4
1 3
1 -4
4 1 2
5 -1 0 -3
输出 #1复制
0.00 3.00
0
-1.00
输入 #2复制
1
-4 10 100
15
4 0 78
5 -4 -95 -97
1 -79
4 12 54
4 -60 11
1 83
4 68 80
2 -63
1 71
1 80
3 12 67
1 60
1 41
3 35 -13
4 6 26
输出 #2复制
-23456.00 106.25
2
-11103.00 -435.00
-14979.00 27.25
-24696.00 -17712.00
-6972.00 -1892.00
0.25
说明/提示
对于30%的数据,n<=100n<=100,且没有操作33。
对于60%的数据,n<=1000n<=1000。
对于100%的数据,T<=10,n<=10000T<=10,n<=10000
数据保证a \neq 0,u \neq 0,a \neq u,1<=p<=5,-100<=a,b,c,k1,k2,k,u,v,w<=100a
=0,u
=0,a
=u,1<=p<=5,−100<=a,b,c,k1,k2,k,u,v,w<=100。
上代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
#include<cmath>
#include<vector>
#include<queue>
#define ca(a) scanf("%lf",&a)
using namespace std;
typedef double db;
double T,n,m;
double a,b,c;
double u,v,w;
double k,p,k1,k2;
double h,num;
void cl()
{
h=-b/2/a;
num=c-a*h*h;
// printf("%.2lf(x-%.2lf)^2+%.2lf\n",a,h,num);
}
double js(double x)
{
return a*(x-h)*(x-h)+num;
}
void dfs1(){
num+=k;
// printf("%.2lf(x-%.2lf)^2+%.2lf\n",a,h,num);
}
void dfs2(){
h+=k;
// printf("%.2lf(x-%.2lf)^2+%.2lf\n",a,h,num);
}
void dfs3()
{
a=-a;
num=2*k2-num;
h=k1*2-h;
// printf("%.2lf(x-%.2lf)^2+%.2lf\n",a,h,num);
}
void dfs4(){
double dd=js(h),l=js(k1),r=js(k2);
if (a>0)
{
double maxx=max(l,r),minn=min(l,r);
if (h>=k1 && h<=k2) printf("%.2lf %.2lf\n",dd,maxx);
else printf("%.2lf %.2lf\n",minn,maxx);
}
if (a<0)
{
double maxx=max(l,r),minn=min(l,r);
if (h>=k1 && h<=k2) printf("%.2lf %.2lf\n",minn,dd);
else printf("%.2lf %.2lf\n",minn,maxx);
}
}
int dfs5()
{
double deleta=(2*a*h+v)*(2*a*h+v)-4*(a-u)*(a*h*h+num-w);
if (deleta>=0) return 2;
if (deleta<0) return 0;
return 0;
}
double dfs6(){
return js(h);
}
int main()
{
cin>>T;
while (T--)
{
cin>>a>>b>>c;
cl();
cin>>n;
for (int i=1; i<=n; i++)
{
cin>>p;
if (p==1) ca(k),dfs1();
if (p==2) ca(k),dfs2();
if (p==3) ca(k1),ca(k2),dfs3();
if (p==4) {
ca(k1),ca(k2);
dfs4();
}
if (p==5) {
ca(u),ca(v),ca(w);
cout<<dfs5()<<endl;}
}
printf("%.2lf\n",dfs6());
}
return 0;
}
边栏推荐
- LeetCode刷题第17天之《3 无重复字符的最长子串》
- Multi-serial port RS485 industrial gateway BL110
- Rotary array problem: how to realize the array "overall reverse, internal orderly"?"Three-step conversion method" wonderful array
- 高校就业管理系统设计与实现
- 什么是机器强化学习?原理是什么?
- 【FPGA】SDRAM
- es-head插件插入查询以及条件查询(五)
- [Likou] 22. Bracket generation
- Echart地图的省级,以及所有地市级下载与使用
- 我的 archinstall 使用手册
猜你喜欢

Description of ESB product development steps under cloud platform

DNS separation resolution and intelligent resolution

UNI-APP_iphone bottom safe area

你不知道的 console.log 替代品

【FPGA】SDRAM

【FPGA】abbreviation

多串口RS485工业网关BL110

Design and Realization of Employment Management System in Colleges and Universities

A large horse carries 2 stone of grain, a middle horse carries 1 stone of grain, and two ponies carry one stone of grain. It takes 100 horses to carry 100 stone of grain. How to distribute it?

使用jackson解析json数据详讲
随机推荐
北湖区燕泉街道开展“戴头盔·保安全”送头盔活动
shell监视gpu使用情况
这些云自动化测试工具值得拥有
[yu gong series] Go program 035-08 2022 interfaces and inheritance and transformation and empty interface
Binary tree related code questions [more complete] C language
MySQL database storage engine and database creation, modification and deletion
typedef defines the structure array type
快速使用UE4制作”大场景游戏“
MySQL数据库存储引擎以及数据库的创建、修改与删除
MYSQLg advanced ------ return table
多串口RS485工业网关BL110
你不知道的 console.log 替代品
Interchangeability and Measurement Techniques - Tolerance Principles and Selection Methods
The impact of programmatic trading and subjective trading on the profit curve!
每日一题-滑动窗口
使用百度EasyDL实现智能垃圾箱
DNS separation resolution and intelligent resolution
LeetCode刷题第17天之《3 无重复字符的最长子串》
uni-app - city selection index list / city list sorted by A-Z (uview component library IndexList index list)
The FTP error code list