本来早上要补的,vp的时候玩了一会游戏然后没用然后了
Dashboard - Codeforces Round #783 (Div. 2) - Codeforces
下午上课补了,真的
不写long long谁是狗,真的
A:从1,1到n,m,不能连续走两格同一个方向,求最小步数
先统一n小m大,从1,1走到n,n要n*2步,且最后一步往右,因此后面直接折叠往下走就ok
需要特判
#include<iostream>
using namespace std;
int main()
{
int _,n,m;
cin >> _;
while (_--)
{
int ans;
cin >> n >> m;
n = n - 1;
m = m - 1;
if (n > m) swap(n, m);
int k = m - n;
if (k % 2 == 0)
{
ans = n + n + k * 2;
}
else
{
ans = n + n + (k - 1) * 2 + 1;
}
if (n == 0 && m > 1)ans = -1;
cout << ans << "\n";
}
}
B:按照从大到小排列,最大值使用2次,最小值使用0次,其他使用1次,ok
十年oi一场空,不写longlong见祖宗
#include<iostream>
#include<algorithm>
using namespace std;
int x[100005];
int main()
{
int _,n,m;
cin >> _;
while (_--)
{
long long ans = 0;
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> x[i];
ans += x[i];
}
if (n > m) {
cout << "NO" << '\n';
continue;
}
sort(x + 1, x + 1 + n);
ans = ans + n + x[n] - x[1];
if (ans > m)
cout << "NO\n";
else
cout << "YES\n";
}
}
C:枚举值为0的位,形成山谷(bushi),复杂度(n^2)
谁能想到我wa是因为longlong 和最大值初始化的时候太小了捏
304

被折叠的 条评论
为什么被折叠?



