当前位置:网站首页>洛谷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;
}
边栏推荐
- Element's BFC attribute
- [FPGA] day19- binary to decimal (BCD code)
- What is machine learning?Explain machine learning concepts in detail
- Differences and connections between distributed and clustered
- C language recv() function, recvfrom() function, recvmsg() function
- C# 一周入门高级编程之《C#-LINQ》Day Four
- Read the article, high-performance and predictable data center network
- “顶梁柱”滑坡、新增长极难担重任,阿里“蹲下”是为了跳更高?
- The impact of programmatic trading and subjective trading on the profit curve!
- Interchangeability and Measurement Technology—Surface Roughness Selection and Marking Method
猜你喜欢

Multi-serial port RS485 industrial gateway BL110

Get Qt installation information: including installation directory and various macro addresses

机器学习怎么学?机器学习流程

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?

"104 Maximum Depth of Binary Trees" in LeetCode's Day 12 Binary Tree Series

一文读懂 高性能可预期数据中心网络

Interchangeable Measurement Techniques - Geometric Errors

EasyCVR接入GB28181设备时,设备接入正常但视频无法播放是什么原因?

校园兼职平台项目反思

Qnet Weak Network Test Tool Operation Guide
随机推荐
LeetCode刷题第17天之《3 无重复字符的最长子串》
"3 Longest Substring Without Repeating Characters" on the 17th day of LeetCode brushing
Is there any way for kingbaseES to not read the system view under sys_catalog by default?
MYSQLg高级------回表
快速使用UE4制作”大场景游戏“
【ADI低功耗2k代码】基于ADuCM4050的ADXL363、TMP75的加速度、温度检测及串口打印、蜂鸣器播放音乐(孤勇者)
80端口和443端口是什么?有什么区别?
使用jackson解析json数据详讲
How can users overcome emotional issues in programmatic trading?
Getting Started with Raspberry Pi (5) System Backup
The FTP error code list
Power Cabinet Data Monitoring RTU
UNI-APP_iphone bottom safe area
Interchangeability Measurements and Techniques - Calculation of Deviations and Tolerances, Drawing of Tolerance Charts, Selection of Fits and Tolerance Classes
什么是机器强化学习?原理是什么?
[FPGA] Design Ideas - I2C Protocol
rub the heat - do not open
What should I do if the channel ServerID is incorrect when EasyCVR is connected to a Hikvision Dahua device and selects another cluster server?
【FPGA】day21- moving average filter
typedef defines the structure array type