A题
Problem - A - CodeforcesCodeforces. Programming competitions and contests, programming communityhttps://codeforces.com/contest/1734/problem/A题意:
给个数组,找出最小的可以凑出等边三角形的步骤数。
思路:
排序后,每三个处理一次最小值即可。
代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N = 310;
int T;
int a[N], s[N];
signed main()
{
cin >> T;
while(T--)
{
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++ i) scanf("%d", &a[i]);
sort(a, a + n + 1);
int ans = 0x3f3f3f3f, sum = 1, dan = 0;
for (int i = 1; i <= n - 2; ++ i)
ans = min(ans, a[i + 2] - a[i]);
printf("%d\n", ans);
}
return 0;
}
B题
Problem - B - CodeforcesCodeforces. Programming competitions and contests, programming communityhttps://codeforces.com/contest/1734/problem/B题意:
金字塔点灯,要求每层金字塔都需要路径亮灯数相同。
思路:
根据观察,除了第一二层之外,其余层除了第一个和最后一个是1,都是0即可。
代码:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
int T;
signed main()
{
cin >> T;
while(T--)
{
int n;
scanf("%d", &n);
for(int i = 1; i <= n; ++ i)
{
if(i == 1 || i == 2) for(int j = 1; j <= i; ++ j) printf("%d ", 1);
else {
for(int j = 1; j <= i; ++ j)
{
if(j == 1 || j == i) printf("%d ", 1);
else printf("%d ", 0);
}
}
puts("");
}
}
return 0;
}
C题
Problem - C - CodeforcesCodeforces. Programming competitions and contests, programming communityhttps://codeforces.com/contest/1734/problem/C题意:
给定一个字符串,代表T数组中没有而S中没有的数,每次可以进行的操作是用某个数的最小倍数来删除从而最终使S -> T,每次使用的数都将加到结果中, 我们需要求的是最小代价。
例如: 1 2 3 4 5 6 7 和 1 2 4 7,结果为3 + 3 + 5 = 11
思路:
枚举每个k,直到遇到不能删除的为止(不是第一小的倍数),然后一直往后枚举即可。
代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int N = 1e6 + 10;
int T;
void solve() {
int n;string t;
cin >> n >> t;
int64_t ans = 0;
for (int i = 1;i <= n;i++) {
for (int j = i;j <= n;j += i) {
if (t[j - 1] == '1') break;
if (t[j - 1] == '0') {
t[j - 1] = '2';
ans += i;
}
}
}
cout << ans << "\n";
}
signed main()
{
scanf("%d", &T);
while(T--)
{
solve();
}
return 0;
}