A.开宝箱,分二种情况.1,宝箱在最远的地方,因此我们只需要把钥匙顺路拿就可以打开宝箱,输出宝箱的坐标.2,钥匙在最远的地方,因此我们遇到宝箱先带着宝箱走,如果可以撑到拿到钥匙就输出钥匙的坐标,如果没体力就放下宝箱,去拿要钥匙再回来开宝箱,输出宝箱+(钥匙-宝箱-体力)*2;
// Problem: A. Treasure Chest
// Contest: Codeforces - Educational Codeforces Round 157 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1895/problem/A
// Memory Limit: 512 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <iostream>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 2e6 + 9;
int a[N];
void solve() {
int x,y,z;
cin>>x>>y>>z;
int ans=0;
if(z+x>=y){
ans=max(x,y);
}else{
ans=z+x+(y-z-x)*2;
}
cout<<ans<<'\n';
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int q;
cin >> q;
while (q--) {
solve();
}
return 0;
}
B. 找出最小距离,模拟一下可以发现,如果点是单调增或者单调减的话,就不会存在重复的路径,或者存在有个点把每个路径距离表示出来可以发现,距离只和xn,x1,y1,yn有关,因此给数组排序就可以得到答案。
// Problem: B. Points and Minimum Distance
// Contest: Codeforces - Educational Codeforces Round 157 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1895/problem/B
// Memory Limit: 512 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <iostream>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 2e6 + 9;
int a[N];
void solve() {
int n;
cin>>n;
for(int i=1;i<=2*n;i++){
cin>>a[i];
}
sort(a+1,a+1+2*n);
int ans=a[n]-a[1]+a[2*n]-a[n+1];
cout<<ans<<'\n';
for(int i=1;i<=n;i++){
cout<<a[i]<<" "<<a[n+i]<<"\n";
}
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int q;
cin >> q;
while (q--) {
solve();
}
return 0;
}