这场怎么说呢,打的并不顺利,掉分进行时。C题一直没想明白,呜呜呜
A. Binary Decimal
分类:
纯思维
我的思路:
仔细观察,发现一个数需要加的最大的binary decimal 数的个数就等于这个数每个位上最大的那个数字。
我的代码:
// by LMY
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll weishu(ll a)
{
int s = 0;
while (a >= 1)
{
a = a / 10;
s++;
}
return s;
}
int main()
{
ll t, n, index, a[20] = {0};
cin >> t;
while (t--)
{
index = 0;
cin >> n;
int temp = weishu(n);
while (n > 0)
{
a[index] = n % 10;
n = n / 10;
index++;
}
sort(a, a + temp);
cout << a[temp - 1] << "\n";
}
return 0;
}
B. Putting Plates
分类:
纯思维
我的思路:
在边界每隔一个数放1就好
一开始忘记数组的初始化,wa了一次…
我的代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int t, h, w, i, j;
int a[22][22] = {0};
cin >> t;
while (t--)
{
cin >> h >> w;
for (i = 0; i < h; i++)
{
for (j = 0; j < w; j++)
{
a[i][j] = 0;
}
}
for (i = 0; i < h; i++)
{
for (j = 0; j < w; j++)
{
if ((i == 0 || i == h - 1) && j % 2 == 0)
{
a[i][j] = 1;
}
}
}
for (i = 0; i < h - 2; i++)
{
for (j = 0; j < w; j++)
{
if ((j == 0 || j == w - 1) && i % 2 == 0 && i > 0 && i < h)
a[i][j] = 1;
}
}
for (i = 0; i < h; i++)
{
for (j = 0; j < w; j++)
{
cout << a[i][j];
}
cout << "\n";
}
cout << "\n";
}
return 0;
}
C. Pursuit
分类:
思维,前缀和
我的代码:
(比赛的时候,是在是没想明白这道题,CD两题都是补题时看了大佬的代码,才懂)
#include <bits/stdc++.h>
using namespace std;
const int N = 100050;
typedef long long ll;
int t, n, i, x, y, r, cnt, a[N], b[N], sa[N], sb[N];
int main()
{
scanf("%d", &t);
while (t--)
{
a[N] = {0};
b[N] = {0};
sa[N] = {0};
sb[N] = {0};
x = 0;
y = 0;
scanf("%d", &n);
for (i = 1; i <= n; i++)
scanf("%d", &a[i]);
for (i = 1; i <= n; i++)
scanf("%d", &b[i]);
sort(a + 1, a + n + 1);
sort(b + 1, b + n + 1);
for (i = 1; i <= n; i++)
{
sa[i] = sa[i - 1] + a[i];
sb[i] = sb[i - 1] + b[i];
}
for (r = 0;; r++)
{
x = sa[n] - sa[(n + r) / 4] + r * 100;
y = sb[n] - sb[max(0, (n + r) / 4 - r)];
if (x >= y)
break;
}
printf("%d\n", r);
}
return 0;
}
D. Secret Santa
分类:
纯思维,用数值保存在下标中来统计每个数出现了多少次的思想(new)
我的代码:
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 9;
int n, v[N], a[N], b[N];
int main()
{
int i, j, t;
cin >> t;
while (t--)
{
int len = 1;
for (int i = 1; i <= n; i++)
{
v[i] = b[i] = 0;
}
cin >> n;
for (i = 1; i <= n; i++)
{
cin >> a[i];
v[a[i]]++;
}
for (i = 1; i <= n; i++)
{
if (v[i] == 0)
{
b[len++] = i;
}
}
//没被送礼物的编号
sort(b + 1, b + len + 1, greater<int>());
int num = 0;
for (i = 1, j = 1; i <= n; i++)
{
if (v[a[i]] > 1 && i != b[j])
{
v[a[i]]--;
a[i] = b[j++];
num++;
}
}
cout << n - num << "\n";
for (i = 1; i <= n; i++)
cout << a[i] << " ";
cout << "\n";
}
return 0;
}