当前位置:网站首页>The 16th Heilongjiang Provincial Collegiate Programming Contest
The 16th Heilongjiang Provincial Collegiate Programming Contest
2022-06-30 21:09:00 【WDLieqi】
目录
D - Doin’ Time
题目思路
可以作为练习区间dp的改后的模板题。题目代码
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 310;
const int mod = 1000003;
int n;
LL p[N];
LL s[N][N], f[N][N];
int main()
{
cin >> n;
for (int i = 1; i <= n; i ++)
cin >> p[i];
for (int i = 1; i <= n; i ++)
{
LL t = 1;
for (int j = i; j <= n; j ++)
t = (t * p[j]) % mod, s[i][j] = t;
}
for (int len = 2; len <= n; len ++)
{
for (int i = 1; i + len - 1 <= n; i ++)
{
int l = i, r = i + len - 1;
f[l][r] = -1;
for (int k = l; k < r; k ++)
{
f[l][r] = max(f[l][r], f[l][k] + f[k + 1][r] + (s[i][k] - s[k + 1][r]) * (s[i][k] - s[k + 1][r]));
}
}
}
cout << f[1][n] << '\n';
return 0;
}
J - JOJO’s Factory
题目思路
因为题目已经给了M的范围即 小于等于2 * n - 3,所以我们可以得出一定不会有像
4 6
1 1
1 2
1 3
2 1
2 2
2 3
这样的数据,所以就可以得出只要不是A里面匹配了n个B就一定可以全部配对。
题目代码
#include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
const int N = 5e5 + 10;
int ma[N], mb[N], n, m;
void solve()
{
cin >> n >> m;
int a = n, b = n;
while (m -- )
{
int x, y;
cin >> x >> y;
ma[x] ++;
mb[y] ++;
if (ma[x] >= n)
a --;
if (mb[y] >= n)
b --;
}
cout << min(a, b) << '\n';
}
int main()
{
IOS // 不加会超时
int T = 1;
//cin >> T;
while (T--)
{
solve();
}
return 0;
}
K. Keep Eating
题目思路
我们可以先将全部的重量合起来 sum,然后一次就吃1重量,最后剩下k个,就直接吃 k / 2 就可以了,注意特判一下 sum 是否大于 k。
题目代码
#include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
void solve()
{
LL n, k;
cin >> n >> k;
LL res1 = 0, res2 = 0;
for (int i = 0; i < n; i ++)
{
int x;
cin >> x;
res1 += x;
}
if (res1 < k)
{
cout << 0 << '\n';
return;
}
res2 += res1 - k + k / 2;
cout << res2 << '\n';
}
int main()
{
IOS int T = 1;
//cin >> T;
while (T--)
{
solve();
}
return 0;
}
边栏推荐
猜你喜欢

On the charm of code language

Radar data processing technology

Introduction of 3D Max fine model obj model into ArcGIS pro (II) key points supplement

【微服务~Nacos】Nacos之配置中心

1.微信小程序页面跳转方法总结;2. navigateTo堆栈到十层不跳转问题

Web APIs 综合案例-Tab栏切换 丨黑马程序员

What about degradation of text generation model? Simctg tells you the answer

【数字IC应届生职业规划】Chap.1 IC行业产业链概述及代表企业大厂汇总

Icml2022 | utility theory of sequential decision making

Lumiprobe protein quantitation - qudye Protein Quantitation Kit
随机推荐
Peking University ACM problems 1004:financial management
Flutter 嵌套地狱?不存在的,ConstraintLayout 来解救!
RP原型资源分享-购物类App
防范未授权访问攻击的十项安全措施
Go语学习笔记 - gorm使用 - 数据库配置、表新增 | Web框架Gin(七)
数字货币:影响深远的创新
报错:Internal error XFS_WANT_CORRUPTED_GOTO at line 1635 of file fs/xfs/libxfs/xfs_alloc.c.
PHP require/include differences
ArcGIS construction and release of simple road network data service and rest call test
Peking University ACM problems 1002:487-3279
SqlServer 获取字符串中数字,中文及字符部分数据
《大厂面试》之JVM篇21问与答
MySQL introduction, detailed installation steps and usage | dark horse programmer
centos——开启/关闭oracle
Iclr'22 spotlight | how to measure the amount of information in neural network weights?
B_QuRT_User_Guide(35)
有趣网站汇总
软工UML画图
Comparison between QT and other GUI Libraries
Metauniverse may become a new direction of Internet development