A. Minimize!

2024-09-09 05:04
文章标签 minimize

本文主要是介绍A. Minimize!,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

time limit per test

1 second

memory limit per test

256 megabytes

You are given two integers aa and bb (a≤ba≤b). Over all possible integer values of cc (a≤c≤ba≤c≤b), find the minimum value of (c−a)+(b−c)(c−a)+(b−c).

Input

The first line contains tt (1≤t≤551≤t≤55) — the number of test cases.

Each test case contains two integers aa and bb (1≤a≤b≤101≤a≤b≤10).

Output

For each test case, output the minimum possible value of (c−a)+(b−c)(c−a)+(b−c) on a new line.

Example

Input

Copy

 

3

1 2

3 10

5 5

Output

Copy

1
7
0

Note

In the first test case, you can choose c=1c=1 and obtain an answer of (1−1)+(2−1)=1(1−1)+(2−1)=1. It can be shown this is the minimum value possible.

In the second test case, you can choose c=6c=6 and obtain an answer of (6−3)+(10−6)=7(6−3)+(10−6)=7. It can be shown this is the minimum value possible.

解题说明::水题,结果就是b-a

#include <stdio.h>int main() 
{int t;scanf("%d", &t);while (t--){int a, b;scanf("%d%d", &a, &b);printf("%d\n", b - a);}return 0;
}

这篇关于A. Minimize!的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1150229

相关文章

scipy minimize当目标函数需要参数、当约束条件特别特别多时

from scipy.optimize import minimize 求解 官方说明文档 简单开一下开头  官方下面有例子会让人容易明白 注意我们的目的是:为了求出让fun函数最小的最优解x 当遇见目标函数fun带了很多外来参数的时候 以及约束很多很多假设有100个的时候,怎么实现呢 1、优化函数带参数 但是当fun函数是带参数的时候怎么办呢,参

minimize函数约束条件的循环列写(Python)

minimize函数约束条件的循环列写(Python) 我们知道python的scipy.optimize库中的minimize函数经常用来解决最优化问题,它对约束的条件有一定的格式,详见大佬的例子 https://blog.csdn.net/HappyRocking/article/details/92574229?utm_medium=distribute.pc_relevant.none-

Leetcode 3081. Replace Question Marks in String to Minimize Its Value

Leetcode 3081. Replace Question Marks in String to Minimize Its Value 1. 解题思路2. 代码实现 题目链接:3081. Replace Question Marks in String to Minimize Its Value 1. 解题思路 这一题其实感觉还是有点难的,主要一开始确实走了弯路,想着用greedy算法逐

Leetcode 3022. Minimize OR of Remaining Elements Using Operations

Leetcode 3022. Minimize OR of Remaining Elements Using Operations 1. 解题思路2. 代码实现 题目链接:3022. Minimize OR of Remaining Elements Using Operations 1. 解题思路 这道题坦率地说其实不太想写这篇题解,因为其实自己根本没有搞定,甚至说看了大佬的解答也没有搞定

Ceres 源码阅读之 TrustRegionMinimizer::Minimize 函数简析

文章目录 Part.I IntroductionPart.II 源码剖析Chap.I TrustRegionMinimizer 类介绍Chap.II Minimize 函数介绍 Part.I Introduction Ceres 中求解优化问题的迭代求解方法(minimizer_type)有线性搜索方法(LINEAR_SEARCH)、信赖域方法(TRUST_REGION)等,其

Leetcode 3012. Minimize Length of Array Using Operations

Leetcode 3012. Minimize Length of Array Using Operations 1. 解题思路2. 代码实现 题目链接:3012. Minimize Length of Array Using Operations 1. 解题思路 这一题有一点数学题的意思,显然,根据最大公约数相关的知识,我们知道,对任意两个数反复相减,我们即可得到他们的最大公约数。 因此

每日一题 - 231126 - C - Minimize Abs 2

C - Minimize Abs 2 TAG - 双指针 双指针 双指针时间复杂度 - O ( D ) O(\sqrt D) O(D ​) //#include<bits/stdc++.h>using namespace std;#define int long longvoid solve(){int d;scanf("%lld",&d );int ans=d;int i

Leetcode 774. Minimize Max Distance to Gas Station

LWC 69: 774. Minimize Max Distance to Gas Station 传送门:774. Minimize Max Distance to Gas Station Problem: On a horizontal number line, we have gas stations at positions stations[0], stations1, …,

C - Minimize The Integer

思路: (1)注意到总体规律是奇数不能跨越奇数,偶数不能跨越偶数 (2)冒泡不可取; (3)直接队列分别存奇偶,小的往前放就行。 代码: #include<bits/stdc++.h>using namespace std;int main() {int t;cin >> t;cin.tie(0);while(t --){string x;cin >> x;queue<char>

利用scipy中的minimize,method指定为BFGS,提示“Desired error not necessarily achieved due to precision loss”

代码: out = minimize(fun = get_expectation(n,p,initial_ansatz),x0 = initial_ansatz, method="BFGS",jac = True, options={'eps':1e-03,'disp':True,'maxiter':400}) 遇到的问题:“Desired error not necessarily ach