当前位置:网站首页>洛谷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;
}
边栏推荐
- Pinduoduo store business license related issues
- LeetCode刷题第16天之《239滑动窗口最大值》
- 你不知道的 console.log 替代品
- 机器学习中什么是集成学习?
- The "top pillar" slides, and new growth is extremely difficult to shoulder the heavy responsibility. Is Ali "squatting" to jump higher?
- The FTP error code list
- Map中的getOrDefualt方法
- Interchangeable Measurement Techniques - Geometric Errors
- MYSQLg高级------回表
- 【Yugong Series】August 2022 Go Teaching Course 036-Type Assertion
猜你喜欢
DNS separation resolution and intelligent resolution
Echart地图的省级,以及所有地市级下载与使用
机器学习是什么?详解机器学习概念
这些云自动化测试工具值得拥有
Build Zabbix Kubernetes cluster monitoring platform
Differences and connections between distributed and clustered
Power Cabinet Data Monitoring RTU
QueryDet: Cascading Sparse Query Accelerates Small Object Detection at High Resolution
[C Language] Getting Started
[FPGA] Design Ideas - I2C Protocol
随机推荐
Qnet Weak Network Test Tool Operation Guide
Power Cabinet Data Monitoring RTU
LeetCode Brush Questions Day 11 String Series "58 Last Word Length"
App Basic Framework Construction丨Log Management - KLog
Kubernetes集群搭建Zabbix监控平台
The FTP error code list
快速使用UE4制作”大场景游戏“
一文读懂 高性能可预期数据中心网络
Interchangeability and Measurement Techniques - Tolerance Principles and Selection Methods
What kind of programming trading strategy types can be divided into?
leetCode刷题14天二叉树系列之《 110 平衡二叉树判断》
常见布局效果实现方案
Map中的getOrDefualt方法
"110 Balanced Binary Tree Judgment" in leetCode's 14-day binary tree series
FTP错误代码列表
"104 Maximum Depth of Binary Trees" in LeetCode's Day 12 Binary Tree Series
华南师范宋宇老师课堂对话论文翻译
The impact of programmatic trading and subjective trading on the profit curve!
Detailed explanation of VIT source code
[yu gong series] Go program 035-08 2022 interfaces and inheritance and transformation and empty interface