首页 > 其他分享 >E. Klee's SUPER DUPER LARGE Array!!!

E. Klee's SUPER DUPER LARGE Array!!!

时间:2024-11-14 22:31:36浏览次数:1  
标签:Klee int DUPER value LARGE minimum Array

E. Klee's SUPER DUPER LARGE Array!!!

# Klee's SUPER DUPER LARGE Array!!!

题面翻译

题目大意

你将得到一个长度为 的序列 ,请求出 的值,其中

输入格式

本题存在多组测试数据。第一行为一个正整数 ),表示数据组数。对于每组数据分别给出用空格隔开的两个整数 )。

输出格式

对于每组数据,输出一行一个整数

题目描述

Klee has an array of length containing integers in that order. Klee wants to choose an index ( ) such that is minimized. Note that for an arbitrary integer , represents the absolute value of .

Output the minimum possible value of .

输入格式

The first line contains ( ) — the number of test cases.

Each test case contains two integers and ( ) — the length of the array and the starting element of the array.

输出格式

For each test case, output the minimum value of on a new line.

样例 #1

样例输入 #1

4
2 2
7 2
5 3
1000000000 1000000000

样例输出 #1

1
5
1
347369930

提示

In the first sample, . When is chosen, . It can be shown this is the minimum possible value of .

In the third sample, . When is chosen, . It can be shown this is the minimum possible value of .

题解

#include <bits/stdc++.h>
#define int long long
using namespace std;
int f(int x,int b,int c){
    return (int)abs(x*x+b*x-c);
}
signed main(){
    int t,n,k;
    cin>>t;
    while(t--){
        cin>>n>>k;
        int b=2*k-1,c=(n*(2*k+n-1)/2);
        double delta=1.0*b*b+4.0*c;
        double x=1.0*(sqrt(delta)-1.0*b)/2.0;
        int nx=(int)x;
        cout<<min(f(nx,b,c),f(nx+1,b,c))<<endl;
    }
    return 0;
}

 

标签:Klee,int,DUPER,value,LARGE,minimum,Array
From: https://www.cnblogs.com/letgogogogo/p/18546979

相关文章