太菜了,只能写800分的题目练练手了
题目大意:
思路:
我们只需要判断能否在硬币掉落之前提前或刚好到达硬币的正下方即可
代码:
void solve()
{
int n;
cin >> n;
int x, y;
for (int i = 0; i < n; i++)
{
cin >> x >> y;
int t = (x == 0 ? 0 : abs(x));
int yy = -t;
if (y - t >= yy - 1)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
800分的菜鸟题
思路:
对k=1和n=1的情况特判一下,然后我们不难知道,k内最多上传1gb,在k+1时也上传1gb(为了得到最小值),然后推出公式即可
代码:
void solve()
{
int n, k;
cin >> n >> k;
if (k == 1)
{
cout << n << endl;
return;
}
if (n == 1)
{
cout << 1 << endl;
return;
}
else
{
cout << (n - 1) * k + 1 << endl;
return;
}
}
思路:
数据范围很小,直接枚举从1到10就行
代码:
void solve()
{
int x1, x2, x3;
cin >> x1 >> x2 >> x3;
int ans = 100;
int sum;
for (int i = 1; i <= 10; i++)
{
sum = abs(x1 - i) + abs(x2 - i) + abs(x3 - i);
if (ans > sum)ans = sum;
}
cout << ans << endl;
}
Problem - 1984A - Codeforces(最开始没看到数组是递增的,服了)
思路:
判断数组极值是否为0,不是的话任选一个数单独一组,其余数一组即可(不能选边界两个数)
代码:
void solve()
{
int n;
cin >> n;
vector<int>a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vector<char>b(n, 'B');
if (a[n - 1] - a[0] != 0)
{
b[1] = 'R';
cout << "YES" << endl;
for (int i = 0; i < n; i++)
cout << b[i];
cout << endl;
}
else
{
cout << "NO" << endl;
}
}
C-小红充电_牛客周赛 Round 51 (nowcoder.com)
思路:
刚写的时候没考虑周全,只判断了两种情况(能快充和不能快充),其实还有一个情况(在不能快充时我们把电量消耗到可以快充的大小,再进行快充,最后判断一下哪一种情况的耗电量最小即可)
代码:
void solve()
{
ll x, y, t, a, b, c;
cin >> x >> y >> t >> a >> b >> c;
double ans = 0, res = 0;
if (x <= t)
{
ans = (100 - x) * 1.0 / c;
res = (100 - x) * 1.0 / c;
}
else
{
res += (x - t) * 1.0 / y;
res += (100 - t) * 1.0 / c;
ans = (100 - x) * 1.0 / b;
}
ans = min(ans, res);
printf("%.9lf", ans);
return;
}
E-小红走矩阵_牛客周赛 Round 51 (nowcoder.com)
一直给我报编译错误也不知道为啥(vs和dev都不报错,就牛客报错)
思路:
看到最短直接开始bfs,我们从数据范围的两头进行二分广搜,一步步缩小数据范围,最后直接输出就行了
代码:
//一直编译错误,该死的牛客网
ll vis[505][505];
ll a[505][505];
int n;
int bfs(int ans)
{
if (a[1][1] > ans)
return 0;
queue<int>p, q;
p.push(1);
q.push(1);
vis[1][1] = 1;
int next[4][2] = { {0,1},{0,-1},{1,0},{-1,0} };
while (!q.empty())
{
int xx = p.front();
int yy = q.front();
p.pop();
q.pop();
for (int i = 0; i < 4; i++)
{
int tx = xx + next[i][0];
int ty = yy + next[i][1];
if (tx<1 || tx>n || ty<1 || ty>n || a[tx][ty] > ans || vis[tx][ty] == 1)continue;
else
{
vis[tx][ty] = 1;
p.push(tx);
q.push(ty);
if (tx == n && ty == n)
return 1;
}
}
}
}
void solve()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
cin >> a[i][j];
}
}
int l = 0, r = 1e9;
while (l < r)
{
int mid = (l + r) >> 1;
if (bfs(mid))
r = mid;
else
l = mid + 1;
}
cout << l << endl;
return;
}
B - Vertical Reading (atcoder.jp)
思路:
void solve()
{
string s, t;
cin >> s >> t;
for (int i = 1; i < s.size(); i++)
{
for (int j = 0; j < i; j++)
{
string now = "";
for (int k = j; k < s.size(); k++)
{
now += s[i];
}
if (now == t)
{
cout << "Yes" << endl;
return;
}
}
}
cout << "No" << endl;
}
思路:
每个盒子里只能放一个物品,我们找到盒子里多于一个物品盒子,把最大的留下,小的全部转移即可
代码:
void solve()
{
int n;
cin >> n;
vector<int>a(n);
vector<int>w(n);
vector<int>z(n);
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> w[i];
for (int i = 0; i < n; i++)
{
a[i]--;
z[a[i]] = max(z[a[i]], w[i]);
}
int sum1 = accumulate(w.begin(), w.end(), 0);
int sum2 = accumulate(z.begin(), z.end(), 0);
int ans = sum1 - sum2;
cout << ans << endl;
}