当前位置:网站首页>洛谷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;
}
边栏推荐
- CTO said that the number of rows in a MySQL table should not exceed 2000w, why?
- Is there any way for kingbaseES to not read the system view under sys_catalog by default?
- EasyCVR接入GB28181设备时,设备接入正常但视频无法播放是什么原因?
- Interchangeable Measurement Techniques - Geometric Errors
- 【组成原理 九 CPU】
- Kubernetes集群搭建Zabbix监控平台
- 直播软件搭建,流式布局,支持单选、多选等
- Detailed explanation of VIT source code
- Echart地图的省级,以及所有地市级下载与使用
- 机器学习可以应用在哪些场景?机器学习有什么用?
猜你喜欢

【FPGA】SDRAM

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

"3 Longest Substring Without Repeating Characters" on the 17th day of LeetCode brushing

快速使用UE4制作”大场景游戏“

【FPGA】day22-SPI协议回环

The development of the massage chair control panel makes the massage chair simple and intelligent

A simple JVM tuning, learn to write it on your resume

电力机柜数据监测RTU

你不知道的 console.log 替代品

Qnet弱网测试工具操作指南
随机推荐
Will oracle cardinality affect query speed?
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?
Qnet弱网测试工具操作指南
Description of ESB product development steps under cloud platform
Enter the starting position, the ending position intercepts the linked list
【FPGA】SDRAM
shell monitors gpu usage
MYSQLg高级------聚簇索引和非聚簇索引
直播平台开发,Flutter,Drawer侧滑
QueryDet: Cascading Sparse Query Accelerates Small Object Detection at High Resolution
使用百度EasyDL实现森林火灾预警识别
MYSQLg advanced ------ return table
typedef defines the structure array type
"125 Palindrome Verification" of the 10th day string series of LeetCode brushing questions
Leetcode 669. 修剪二叉搜索树
The "top pillar" slides, and new growth is extremely difficult to shoulder the heavy responsibility. Is Ali "squatting" to jump higher?
Homework 8.10 TFTP protocol download function
js 将字符串作为js执行代码使用
Getting Started with Raspberry Pi (5) System Backup
[C Language] Getting Started