日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

LLL和小猫

發(fā)布時(shí)間:2024/10/5 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 LLL和小猫 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Description

LLL有?群貓友,每只?貓都站在坐標(biāo)軸上的某個(gè)位置,這群貓友很聽(tīng)LLL的話,每當(dāng)LLL做個(gè)?勢(shì),每只?貓

都會(huì)移動(dòng)恰好X個(gè)單位的距離,要么向左,要么向右

現(xiàn)在告訴你每只?貓?jiān)谝苿?dòng)前的位置,求移動(dòng)之后最左邊的貓與最右邊的貓的最?距離

Input

?多組測(cè)試數(shù)據(jù) 對(duì)于每組數(shù)據(jù),第??輸??個(gè)整數(shù)n (1<=n<=50 ),表?貓的數(shù)量 第??輸?n個(gè)數(shù)pi (-1e8<=pi<=1e8),表?每只貓的位置 第三?輸??個(gè)整數(shù) X(0<=X<=1e8 )

Output

?對(duì)于每組數(shù)據(jù)輸出?個(gè)整數(shù)

Sample Input

3 -3 0 1 3 3 4 7 -7 5 2 -100000000 100000000 100000000 9 3 7 4 6 -10 7 10 9 -5 7 4 -4 0 4 0 4 1 7 0

Sample Output

3 4 0 7 4 0

HINT

?

?

題解:

?

#ifndef debuging #define FIN ; #define FOUT ; #define OUT(x) ; #define ERR(x) ; #endif #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include <cmath> #include <vector> #include <map> #include <set> #include <queue> using namespace std ; long long a[100]; class TaroFriends { public: int getNumber(vector <int> coordinates, int X) { sort(coordinates.begin(),coordinates.end()); int n = coordinates.size(); long long ans = coordinates[n-1] - coordinates[0]; for(int i = 0;i < n-1;i++) { for(int j = 0;j <= i;j++) a[j] = coordinates[j] + X; for(int j = i+1;j < n;j++) a[j] = coordinates[j] - X; sort(a,a+n); ans = min(ans, a[n-1] - a[0] ); } return (int)ans; } }; int main () {int n;while (cin >> n) {vector <int> a(n);for (int i = 0; i < n; i++) {cin >> a[i];}int d; cin >> d;TaroFriends test;cout << test.getNumber(a, d) << endl;}return 0; }

?

總結(jié)

以上是生活随笔為你收集整理的LLL和小猫的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。