传送门
A 简单的整除
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr), cout.tie(nullptr);
#define met_0(a) memset(a,0,sizeof a)
#define met_1(a) memset(a,-1,sizeof a)
#define mpy(a,b) memcopy(a,sizeof b,b)
#define ll long long
#define ld long double
#define ull unsigned long long
#define endl '\n'
const int N = 100010;
const int M = 110;
const int MOD = 1e9 + 7;
const int EPS = 1e-8;
using namespace std;
void solve() {
int n;
cin >> n;
if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0 || n % 7 == 0)cout << "YES" << endl;
else cout << "NO" << endl;
}
int32_t main() {
IOS;
int h_h;
//cin >> h_h;
h_h = 1;
while (h_h--)solve();
return 0;
}
B 整数划分
就简单的从小到大往后放,当剩余的要小于前一个就加到最后一个一起放
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr), cout.tie(nullptr);
#define met_0(a) memset(a,0,sizeof a)
#define met_1(a) memset(a,-1,sizeof a)
#define mpy(a,b) memcopy(a,sizeof b,b)
#define ll long long
#define ld long double
#define ull unsigned long long
#define endl '\n'
const int N = 100010;
const int M = 110;
const int MOD = 1e9 + 7;
const int EPS = 1e-8;
using namespace std;
void solve() {
int n;
cin >> n;
for (int i = 1; n; i++) {
if (n - i <= i && n - i != 0)continue;
cout << i << ' ';
n -= i;
}
cout << endl;
}
int32_t main() {
IOS;
int h_h;
cin >> h_h;
//h_h = 1;
while (h_h--)solve();
return 0;
}
C 传送阵
就统计数字出现的种类即可
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr), cout.tie(nullptr);
#define met_0(a) memset(a,0,sizeof a)
#define met_1(a) memset(a,-1,sizeof a)
#define mpy(a,b) memcopy(a,sizeof b,b)
#define ll long long
#define ld long double
#define ull unsigned long long
#define endl '\n'
const int N = 100010;
const int M = 110;
const int MOD = 1e9 + 7;
const int EPS = 1e-8;
using namespace std;
void solve() {
int n, m;
cin >> n >> m;
map<int, int> mp;
for (int i = 0; i < m * n; i++) {
int x;
cin >> x;
mp[x]++;
}
cout << mp.size() << endl;
}
int32_t main() {
IOS;
int h_h;
cin >> h_h;
//h_h = 1;
while (h_h--)solve();
return 0;
}`
D 修改后的和
我们通过题目分析可以知道,一定是要从大到小开始减,二且要先间最右边的,一次往左减,因为减去了这和数会影响这个数后面的结果,总体来说就是一个贪心
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0), cout.tie(0);
#define met_0(a) memset(a,0,sizeof a)
#define met_1(a) memset(a,-1,sizeof a)
#define mpy(a,b) memcopy(a,sizeof b,b)
#define int long long
#define ld long double
#define ull unsigned long long
#define endl '\n'
const int N = 100010;
const int M = 110;
const int MOD = 1e9 + 7;
const int EPS = 1e-8;
using namespace std;
void solve() {
int n, m;
cin >> n >> m;
vector<int> a(n);
vector<int> b;
int sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
if (a[i] >= 0)b.push_back(a[i] * (n - i));
}
sort(b.begin(), b.end(), greater<int>());
//cout << sum << endl;
//for (auto i : b)cout << i << ' '; cout << endl;
for (int i = 0; i < min(m, (int)b.size()); i++) {
sum -= b[i];
}
cout << sum << endl;
}
int32_t main() {
IOS;
int h_h;
cin >> h_h;
//h_h = 1;
while (h_h--)solve();
return 0;
}
E 幼稚园的树2
就是简单的推式子,先让树长到超过目标值摈玫瑰裁剪,此后的都是循环,要记得向上取整呢个,而且要超过k,所要去k+1,这里要注意
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr), cout.tie(nullptr);
#define met_0(a) memset(a,0,sizeof a)
#define met_1(a) memset(a,-1,sizeof a)
#define mpy(a,b) memcopy(a,sizeof b,b)
#define ll long long
#define ld long double
#define ull unsigned long long
#define endl '\n'
const int N = 100010;
const int M = 110;
const int MOD = 1e9 + 7;
const int EPS = 1e-8;
using namespace std;
void solve() {
int n, m , k, b;
cin >> n >> m >> k >> b;
vector<int> a(n + 1), c(n + 1);
for (int i = 0; i < n; i++)cin >> a[i];
for (int i = 0; i < n; i++)cin >> c[i];
//cout << n << ' ' << m << ' ' << k << ' ' << b << endl;
vector<int> ans;
m--;
for (int i = 0; i < n; i++) {
int x = (k + 1 - a[i] + c[i] - 1) / c[i];
if (m < x) {
ans.push_back(a[i] + m * c[i]);
continue;
}
else {
int xx = (k + 1 - b + c[i] - 1) / c[i];
int yy = (m - x) % xx;
ans.push_back(b + c[i]*yy);
}
}
for (auto i : ans)cout << i << ' ';
cout << endl;
}
int32_t main() {
IOS;
int h_h;
cin >> h_h;
//h_h = 1;
while (h_h--)solve();
return 0;
}
F 最便宜的构建
最大值最小,很经典的二分,我们可以一每条边的全值从小到大排序,一小标进行二分,最后输出权值即可,最关键的就是怎么写check函数,这里使用并查集来判断连通性,也可以使用dfs都行
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr), cout.tie(nullptr);
#define met_0(a) memset(a,0,sizeof a)
#define met_1(a) memset(a,-1,sizeof a)
#define mpy(a,b) memcopy(a,sizeof b,b)
#define ll long long
#define ld long double
#define ull unsigned long long
#define fi first
#define se seocnd
#define endl '\n'
const int N = 100010;
const int M = 110;
const int MOD = 1e9 + 7;
const int EPS = 1e-8;
using namespace std;
struct S{
int a, b, c;
bool operator<(const S &t)const{
return c<t.c;
}
}g[N];
int fa[N];
int n, m, k;
vector<int> gg[N];
int find(int x){
if(fa[x]!=x)return fa[x]=find(fa[x]);
return fa[x];
}
void Union(int a, int b) {
a = find(a);
b = find(b);
fa[a] = b;
}
bool check(int x) {
met_0(fa);
for (int i = 1; i <= n; i++)fa[i] = i;
for (int i = 1; i <= x; i++)Union(g[i].a, g[i].b);
for (int i = 1; i <= k; i++) {
int node = find(gg[i][0]);
for (auto j: gg[i]) {
if (find(j) != node)return false;
}
}
return true;
}
void solve() {
cin >> n >> m;
for (int i = 1; i <= m; i++)
cin >> g[i].a >> g[i].b >> g[i].c;
sort(g + 1, g + m + 1);
cin >> k;
for (int i = 1; i <= k; i++) {
int x;
cin >> x;
for (int j = 0; j < x; j++) {
int y;
cin >> y;
gg[i].push_back(y);
}
}
int l = 0, r = m - 1;
while (l < r) {
int mid = l + r >> 1;
if (check(mid))r = mid;
else l = mid + 1;
}
cout << g[l].c << endl;
}
int32_t main() {
IOS;
int h_h;
//cin >> h_h;
h_h = 1;
while (h_h--)solve();
return 0;
}