A.Insert
思路:给一个数组,在第k个数后面插入x,可以先输出数组前k个数,然后输出x,最后输出最后的一部分数
ac代码:
/* ʕ•̀ ω • ʔ *˘︶˘*).。.:*♡ (∗ᵒ̶̶̷̀ω˂̶́∗)੭₎₎̊₊♡ (⋈◍>◡<◍) ʕ•̫͡• ʔ•̫͡•ཻʕ•̫͡•ʔ•͓͡•ʔ.•♫•♬ •♬•♫•.✿.。.:* ☆ .:**:.☆*.:。.✿ *★°*:.☆:*.°★*
●▂● ●0● ●︿● ●ω● ●﹏● ●△● ●▽● ♡⃝ ʜᴇʟʟᴏ •ᴗ• ☽⋆
∩ ∩ ̋(๑˃́ꇴ˂̀๑) ᐕ)⁾⁾ *:ஐ (๑´ᵕ`) ஐ:* *ଘ(੭*ˊᵕˋ)੭* (੭ˊᵕˋ)੭* ੈ✩˚
>(>_<)<
I I
I I ʕง•ᴥ•ʔง
IU UI
I I ꉂꉂ꒰•̤▿•̤*ૢ꒱
≧▂≦ ≧0≦ ≧︿≦ ≧ω≦ ≧﹏≦ ≧△≦ ꒰๑˃͈꒵˂͈๑꒱
☗♪叮☖叮♫ ☗铛♪ ☖♫☗♪叮☖叮♫ ☗铛♪ ☖♫☗♪叮☖叮♫ ☗铛♪ ☖♫☗♪叮☖叮♫ ☗铛♪ ☖♫
(~o▔▽▔)~o o~(▔▽▔o~) ‿︵‿︵‿︵୨˚̣̣̣͙୧ - - - -୨˚̣̣̣͙୧‿︵‿︵‿︵
*/
#include<bits/stdc++.h>
using namespace std;
#define lll __int128
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> PII;
const int mod=1e9+7;
inline ll read()
{
ll x = 0, y = 1;
char c = getchar();
while (!isdigit(c))
{
if (c == '-')
y = -1;
c = getchar();
}
while (isdigit(c))
{
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return x *= y;
}
inline void write(ll x)
{
if (x < 0)
x = -x, putchar('-');
ll sta[35], top = 0;
do
sta[top++] = x % 10, x /= 10;
while (x);
while (top)
putchar(sta[--top] + '0');
}
const int N = 2e5 + 10;
int a[N];
void Miraitowa(){
ll n, k, x;
cin >> n >> k >> x;
for (int i = 1; i <= n;i++)
cin >> a[i];
for (int i = 1; i <= k;i++)
cout << a[i] << " ";
cout << x << " ";
for (int i = k + 1; i <= n;i++)
cout << a[i] << " ";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
// int t;
// cin>>t;
// while(t--)
Miraitowa();
return 0;
};
B - Intersection of Cuboids
思路:给两个立方体,判断相交部分是不是正体积,立方体是三维状态,我们可以考虑每一维度,当压缩到每一维度的时候就是两条线段,判断两条线段是不是有相交部分即可,若是三个维度都有相交部分的话就是Yes
ac代码:
/* ʕ•̀ ω • ʔ *˘︶˘*).。.:*♡ (∗ᵒ̶̶̷̀ω˂̶́∗)੭₎₎̊₊♡ (⋈◍>◡<◍) ʕ•̫͡• ʔ•̫͡•ཻʕ•̫͡•ʔ•͓͡•ʔ.•♫•♬ •♬•♫•.✿.。.:* ☆ .:**:.☆*.:。.✿ *★°*:.☆:*.°★*
●▂● ●0● ●︿● ●ω● ●﹏● ●△● ●▽● ♡⃝ ʜᴇʟʟᴏ •ᴗ• ☽⋆
∩ ∩ ̋(๑˃́ꇴ˂̀๑) ᐕ)⁾⁾ *:ஐ (๑´ᵕ`) ஐ:* *ଘ(੭*ˊᵕˋ)੭* (੭ˊᵕˋ)੭* ੈ✩˚
>(>_<)<
I I
I I ʕง•ᴥ•ʔง
IU UI
I I ꉂꉂ꒰•̤▿•̤*ૢ꒱
≧▂≦ ≧0≦ ≧︿≦ ≧ω≦ ≧﹏≦ ≧△≦ ꒰๑˃͈꒵˂͈๑꒱
☗♪叮☖叮♫ ☗铛♪ ☖♫☗♪叮☖叮♫ ☗铛♪ ☖♫☗♪叮☖叮♫ ☗铛♪ ☖♫☗♪叮☖叮♫ ☗铛♪ ☖♫
(~o▔▽▔)~o o~(▔▽▔o~) ‿︵‿︵‿︵୨˚̣̣̣͙୧ - - - -୨˚̣̣̣͙୧‿︵‿︵‿︵
*/
#include<bits/stdc++.h>
using namespace std;
#define lll __int128
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> PII;
const int mod=1e9+7;
inline ll read()
{
ll x = 0, y = 1;
char c = getchar();
while (!isdigit(c))
{
if (c == '-')
y = -1;
c = getchar();
}
while (isdigit(c))
{
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return x *= y;
}
inline void write(ll x)
{
if (x < 0)
x = -x, putchar('-');
ll sta[35], top = 0;
do
sta[top++] = x % 10, x /= 10;
while (x);
while (top)
putchar(sta[--top] + '0');
}
void Miraitowa(){
int a, b, c, d, e, f;
cin >> a >> b >> c >> d >> e >> f;
int g, h, i, j, k, l;
cin >> g >> h >> i >> j >> k >> l;
if(max(b,e)<=min(h,k)||min(b,e)>=max(h,k))
cout << "No" << endl;
else if (max(a, d) <= min(g, j) || min(a, d) >= max(g, j))
cout << "No" << endl;
else if (max(c, f) <= min(i, l) || min(c, f) >= max(i, l))
cout << "No" << endl;
else cout << "Yes" << endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
// int t;
// cin>>t;
// while(t--)
Miraitowa();
return 0;
};
C - Make Them Narrow
思路:给一个序列A,删除K个,将剩下的元素重新排列B好后求最小值:B中的最大值减去最小值
先对A进行排序,若是我们删去的是中间的数对最小值无影响,所以我们需要删去前面若干和后面若干,因此我们可以枚举,前面删去i个,那么后面则删去n-i个
ac代码:
/* ʕ•̀ ω • ʔ *˘︶˘*).。.:*♡ (∗ᵒ̶̶̷̀ω˂̶́∗)੭₎₎̊₊♡ (⋈◍>◡<◍) ʕ•̫͡• ʔ•̫͡•ཻʕ•̫͡•ʔ•͓͡•ʔ.•♫•♬ •♬•♫•.✿.。.:* ☆ .:**:.☆*.:。.✿ *★°*:.☆:*.°★*
●▂● ●0● ●︿● ●ω● ●﹏● ●△● ●▽● ♡⃝ ʜᴇʟʟᴏ •ᴗ• ☽⋆
∩ ∩ ̋(๑˃́ꇴ˂̀๑) ᐕ)⁾⁾ *:ஐ (๑´ᵕ`) ஐ:* *ଘ(੭*ˊᵕˋ)੭* (੭ˊᵕˋ)੭* ੈ✩˚
>(>_<)<
I I
I I ʕง•ᴥ•ʔง
IU UI
I I ꉂꉂ꒰•̤▿•̤*ૢ꒱
≧▂≦ ≧0≦ ≧︿≦ ≧ω≦ ≧﹏≦ ≧△≦ ꒰๑˃͈꒵˂͈๑꒱
☗♪叮☖叮♫ ☗铛♪ ☖♫☗♪叮☖叮♫ ☗铛♪ ☖♫☗♪叮☖叮♫ ☗铛♪ ☖♫☗♪叮☖叮♫ ☗铛♪ ☖♫
(~o▔▽▔)~o o~(▔▽▔o~) ‿︵‿︵‿︵୨˚̣̣̣͙୧ - - - -୨˚̣̣̣͙୧‿︵‿︵‿︵
*/
#include<bits/stdc++.h>
using namespace std;
#define lll __int128
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> PII;
const int mod=1e9+7;
inline ll read()
{
ll x = 0, y = 1;
char c = getchar();
while (!isdigit(c))
{
if (c == '-')
y = -1;
c = getchar();
}
while (isdigit(c))
{
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return x *= y;
}
inline void write(ll x)
{
if (x < 0)
x = -x, putchar('-');
ll sta[35], top = 0;
do
sta[top++] = x % 10, x /= 10;
while (x);
while (top)
putchar(sta[--top] + '0');
}
const int N = 3e5 + 10;
ll a[N];
void Miraitowa(){
ll n, k;
cin >> n >> k;
for (int i = 1; i <= n;i++)
cin >> a[i];
sort(a + 1, a + 1 + n);
ll ans = 1e18;
for (int i = 0; i <= k; i++)
{
ll j = n - (k - i);
ans = min(ans, a[j] - a[i+1]);
}
cout << ans << endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
// int t;
// cin>>t;
// while(t--)
Miraitowa();
return 0;
};
E - Tree and Hamilton Path 2
思路:给一个图,求从一个点出发能到所有点所需要的最小的路径和
哈密顿路径问题,每个点都经过一次,首先我们要考虑从一个点出发,每个点都经过一次然后再回到原点后,我们发现路径为所有权值的和的二倍,然后我们要从一个点出发到另一个点后就不回来了,因为我们要的是和最小,所以我们要求图中一个点到另一个点的最远距离,即树的最长直径问题
ac代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5+10, M = 2 * N;
ll n;
ll h[N], e[M], ne[M], w[M], idx;
ll ans;
void add(int a, int b, int c)
{
e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++;
}
ll dfs(int u, int father)
{
ll dist = 0, d1 = 0, d2 = 0;
for (int i = h[u]; i != -1; i = ne[i])
{
int j = e[i];
if (j == father)
continue;
ll d = dfs(j, u) + w[i];
dist = max(d, dist);
if (d >= d1)
d2 = d1, d1 = d;
else if (d > d2)
d2 = d;
}
ans = max(ans, d1 + d2);
return dist;
}
int main()
{
cin >> n;
memset(h, -1, sizeof h);
ll res = 0;
for (int i = 0; i < n - 1; i++)
{
int a, b, c;
cin >> a >> b >> c;
res += c;
add(a, b, c), add(b, a, c);
}
dfs(1, -1);
cout << res*2-ans << endl;
}