GTW likes math(BC 1001)

GTW likes math

Accepts: 472

Submissions: 2140

Time Limit: 2000/1000 MS (Java/Others)

Memory Limit: 131072/131072 K (Java/Others)

问题描述

某一天,GTW听了数学特级教师金龙鱼的课之后,开始做数学《从自主招生到竞赛》。然而书里的题目太多了,GTW还有很多事情要忙(比如把妹),于是他把那些题目交给了你。每一道题目会给你一个函数f(x)=ax2+bx+cf(x)=求这个函数在整数区间[l,r]之间的最值。

输入描述

第一行一个整数T,表示数据组数。(T≤1000T\leq 1000T≤1000)
对于每一组数据,有一行,共五个整数a,b,c,l,r。(∣a∣≤100,∣b∣≤100,∣c∣≤100,∣l∣≤100,∣r∣≤100,l<=r)

输出描述

对于每一组数据,共一行两个整数max,min,表示函数在整数区间[l,r][l,r][l,r]中的最大值和最小值。

输入样例

1
1 1 1 1 2

输出样例

7 3

Hint

f1=3,f2=7f_1=3,f_2=7f?1??=3,f?2??=7,最大值=7,最小值=3
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 using namespace std;
 5 int a,b,c,l,r;
 6 int func(int x)
 7 {
 8     return x*x*a+b*x+c;
 9 }
10 int main()
11 {
12     int T,i,j;
13     int x,y;
14     freopen("in.txt","r",stdin);
15     cin>>T;
16     while(T--)
17     {
18         scanf("%d %d %d %d %d",&a,&b,&c,&l,&r);
19         int Min=1000000,Max=-1000000;
20         if(a==0)
21         {
22             Max=max(b*r+c,b*l+c);
23             Min=min(b*r+c,b*l+c);
24         }
25         else
26         {
27             for(int i=l;i<=r;i++)
28             {
29                 int k=func(i);
30                 //cout<<k<<endl;
31                 Max=max(Max,k);
32                 Min=min(Min,k);
33             }
34         }
35         printf("%d %d\n",Max,Min);
36     }
37 }
				
时间: 2024-10-13 12:05:17

GTW likes math(BC 1001)的相关文章

GTW likes math(简单数学)

GTW likes math Accepts: 472 Submissions: 2140 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Problem Description After attending the class given by Jin Longyu, who is a specially-graded teacher of Mathematics, GTW

HDU 5596/BestCoder Round #66 (div.2) GTW likes math 签到

GTW likes math Memory Limit: 131072/131072 K (Java/Others) 问题描述 某一天,GTW听了数学特级教师金龙鱼的课之后,开始做数学<从自主招生到竞赛>.然而书里的题目太多了,GTW还有很多事情要忙(比如把妹),于是他把那些题目交给了你.每一道题目会给你一个函数f(x)=ax^2+bx+cf(x)=ax?2??+bx+c,求这个函数在整数区间[l,r][l,r]之间的最值. 输入描述 第一行一个整数T,表示数据组数.(T\leq 1000T≤

hdu 5595 GTW likes math(暴力枚举查询)

思路:直接暴力枚举区间[l,r]的整数值,然后max和min就可以了. AC代码: 1 #pragma comment(linker, "/STACK:1024000000,1024000000") 2 #include<iostream> 3 #include<cstdio> 4 #include<cstring> 5 #include<cmath> 6 #include<math.h> 7 #include<algo

GTW likes gt(BC 模拟 or 优先队列)

GTW likes gt Accepts: 54 Submissions: 782 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) 从前,有nnn只萌萌的GT,他们分成了两组在一起玩游戏.他们会排列成一排,第iii只GT会随机得到一个能力值bib_ib?i??.在第iii秒的时候,第iii只GT可以消灭掉所有排在他前面的和他不是同一组的且能力值小于他的GT.为了使游戏更加有趣,G

hdu-5597 GTW likes function(欧拉函数+找规律)

题目链接: GTW likes function Time Limit: 4000/2000 MS (Java/Others)     Memory Limit: 131072/131072 K (Java/Others) Problem Description Now you are given two definitions as follows. f(x)=∑xk=0(−1)k22x−2kCk2x−k+1,f0(x)=f(x),fn(x)=f(fn−1(x))(n≥1) Note that

HDU5597/BestCoder Round #66 (div.2) GTW likes function 打表欧拉函数

GTW likes function Memory Limit: 131072/131072 K (Java/Others) 问题描述 现在给出下列两个定义: f(x)=f_{0}(x)=\sum_{k=0}^{x}(-1)^{k}2^{2x-2k}C_{2x-k+1}^{k},f_{n}(x)=f(f_{n-1}(x))(n\geq 1)f(x)=f?0??(x)=∑?k=0?x??(−1)?k??2?2x−2k??C?2x−k+1?k??,f?n??(x)=f(f?n−1??(x))(n≥1

hdu 5596 GTW likes gt

Problem Description Long long ago, there were n adorkable GT. Divided into two groups, they were playing games together, forming a column. The i−th GT would randomly get a value of ability bi. At the i−th second, the i−th GT would annihilate GTs who

BestCoder Round #66 (div.2)B GTW likes gt

思路:一个O(n)O(n)的做法.我们发现b_1,b_2,...,b_xb?1??,b?2??,...,b?x??都加11就相当于b_{x+1},b_{x+2},...,b_nb?x+1??,b?x+2??,...,b?n??都减11.然后我们可以倒着做,记一下最大值,如果遇到了修改操作,就把最大值减11,然后判断一下这个人会不会被消灭掉,然后再更新一下最大值. 1 #define cn(i,p,q) for(int i=p;i<=q;i++) 2 #define cn1(i,p,q) for(

BestCoder Round #66 (div.2) hdu5592

GTW likes math Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 942    Accepted Submission(s): 426 Problem Description After attending the class given by Jin Longyu, who is a specially-graded t