当前位置:网站首页>洛谷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;
}
边栏推荐
猜你喜欢

What is Machine Reinforcement Learning?What is the principle?

"110 Balanced Binary Tree Judgment" in leetCode's 14-day binary tree series

北湖区燕泉街道开展“戴头盔·保安全”送头盔活动

【力扣】22.括号生成

移动端地图开发选择哪家?

校园兼职平台项目反思

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

leetcode刷题第13天二叉树系列之《98 BST及其验证》

LeetCode Brush Questions Day 11 String Series "58 Last Word Length"

Day20 FPGA 】 【 - block the I2C read and write EEPROM
随机推荐
What kind of programming trading strategy types can be divided into?
Will oracle cardinality affect query speed?
set_new_handler(0)是什么意思?有什么用?
【FPGA】day22-SPI协议回环
How to learn machine learning?machine learning process
LeetCode Brush Questions Day 11 String Series "58 Last Word Length"
使用jackson解析json数据详讲
北湖区燕泉街道开展“戴头盔·保安全”送头盔活动
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】day22-SPI protocol loopback
.NET自定义中间件
Interchangeability and Measurement Techniques - Tolerance Principles and Selection Methods
【FPGA】设计思路——I2C协议
Interchangeability and Measurement Technology—Surface Roughness Selection and Marking Method
Rotary array problem: how to realize the array "overall reverse, internal orderly"?"Three-step conversion method" wonderful array
Basic understanding of MongoDB (2)
Get the length of the linked list
.NET service registration
What is third-party payment?
A simple JVM tuning, learn to write it on your resume