ABC317题解报告
我直接从第三题开始讲了。
把数组 \(A\) 从大到小排序。
然后从前往后把前 \(q\) 个数加起来,然后判断这 \(q\) 个数的和与 \(d\) 的大小关系,如果大了就变成 \(d\)。
然后有些细节就看代码吧。
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 2e5 + 10;
int n,d,p;
int a[maxn];
int cnt,sum;
bool cmp(int a,int b)
{
return a > b;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin >> n >> d >> p;
int ans = 0;
for(int i = 1;i <= n;i++)
{
cin >> a[i];
ans += a[i];
}
sort(a + 1,a + n + 1,cmp);
for(int i = 1;i <= n;i++)
{
sum += a[i];
cnt++;
if(cnt >= d && sum <= p)
{
break;
}
if(cnt == d)
{
if(sum >= p)
{
cnt = 0;
ans -= sum - p;
sum = 0;
}
}
}
if(sum >= p)
{
ans -= sum - p;
}
cout << ans;
return 0;
}
看到 \(n \le 16\),想到状压 DP。
然后就没有然后了, DP式就是很普通的 DP 式。
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,ans = -1e9;
int d[20][20];
int dp[1 << 17];
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin >> n;
for(int i = 0;i < n;i++)
{
for(int j = 0;j < n;j++)
{
if(i != j && i < j)
cin >> d[i][j];
}
}
for(int i = 0;i < (1 << n);i++)
{
for(int j = 0;j < n;j++)
{
if(!(i & (1 << j)))
{
continue;
}
for(int k = j + 1;k < n;k++)
{
if(!(i & (1 << k)))
{
continue;
}
int befor = i xor (1 << j) xor (1 << k);
dp[i] = max(dp[befor] + d[j][k],dp[i]);
}
}
}
for(int i = 0;i < (1 << n);i++)
{
ans = max(ans,dp[i]);
// cout << dp[i] << " " << i << '\n';
}
cout << ans;
return 0;
}
/*
16
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1
1 1 1 1
1 1 1
1 1
1
*/
有很多种方法。
比如liangbowen先生说的:e你直接从后往前枚举 i 不就做完了。
谔谔,大家的方法都比我高级。
我是直接容斥。
首先先算出以这个点为 \(k\) 的组数并且忽略第二条。
然后减去 \(a_i = a_j = a_k\) 的情况即可。
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 3e5 + 10;
int n,ans;
int cnt[maxn],sum[maxn];
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin >> n;
for(int i = 1;i <= n;i++)
{
int x;
cin >> x;
ans += cnt[x] * (i - 1) - sum[x];
sum[x] += i;
cnt[x]++;
}
for(int i = 1;i <= n;i++)
{
ans -= cnt[i] * (cnt[i] - 1) * (cnt[i] - 2) / 6;
}
cout << ans;
return 0;
}
但是呢,你有可能对 ans += cnt[x] * (i - 1) - sum[x]; 有疑问,我们画个图就知道了。

每个物品搭配每只脚,能不能取到临界值组成的 \(2n^2\) 个点。
那么暴力判断每个点行不行。
然后判断每个关键点之后的一个点可不可以,可以的话那整个闭区间就可以。
// LUOGU_RID: 123641746
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 210;
int n,cnt,ans,a[maxn],b[maxn];
int c[maxn * maxn * 2],tmp[maxn];
int X;
bool cmp(int x,int y)
{
return abs(x - X) < abs(y - X);
}
bool check(int x)
{
X = x;
for(int i = 1;i <= n;i++)
{
tmp[i] = a[i];
}
sort(tmp + 1,tmp + n + 1,cmp);
for(int i = 1;i <= n;i++)
{
if(tmp[i] < x - b[i] || tmp[i] > x + b[i])
{
return 0;
}
}
return 1;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin >> n;
for(int i = 1;i <= n;i++)
{
cin >> a[i];
}
for(int i = 1;i <= n;i++)
{
cin >> b[i];
}
for(int i = 1;i <= n;i++)
{
for(int j = 1;j <= n;j++)
{
c[++cnt] = a[i] - b[j];
c[++cnt] = a[i] + b[j];
}
}
sort(c + 1,c + cnt + 1);
cnt = unique(c + 1,c + cnt + 1) - c - 1;
for(int i = 1;i <= cnt;i++)
{
if(check(c[i]))
{
ans++;
}
}
for(int i = 1;i < cnt;i++)
{
if(check(c[i] + 1))
{
ans += c[i + 1] - c[i] - 1;
}
}
cout << ans;
return 0;
}
ABC317题解报告的更多相关文章
- 2015浙江财经大学ACM有奖周赛(一) 题解报告
2015浙江财经大学ACM有奖周赛(一) 题解报告 命题:丽丽&&黑鸡 这是命题者原话. 题目涉及的知识面比较广泛,有深度优先搜索.广度优先搜索.数学题.几何题.贪心算法.枚举.二进制 ...
- cojs 强连通图计数1-2 题解报告
OwO 题目含义都是一样的,只是数据范围扩大了 对于n<=7的问题,我们直接暴力搜索就可以了 对于n<=1000的问题,我们不难联想到<主旋律>这一道题 没错,只需要把方程改一 ...
- cojs 二分图计数问题1-3 题解报告
OwO 良心的FFT练手题,包含了所有的多项式基本运算呢 其中一部分解法参考了myy的uoj的blog 二分图计数 1: 实际是求所有图的二分图染色方案和 我们不妨枚举这个图中有多少个黑点 在n个点中 ...
- 题解报告:hdu 1398 Square Coins(母函数或dp)
Problem Description People in Silverland use square coins. Not only they have square shapes but also ...
- 题解报告:hdu 2069 Coin Change(暴力orDP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2069 Problem Description Suppose there are 5 types of ...
- 题解报告:hdu 1028 Ignatius and the Princess III(母函数or计数DP)
Problem Description "Well, it seems the first problem is too easy. I will let you know how fool ...
- CF Educational Round 78 (Div2)题解报告A~E
CF Educational Round 78 (Div2)题解报告A~E A:Two Rival Students 依题意模拟即可 #include<bits/stdc++.h> us ...
- CF1169(div2)题解报告
CF1169(div2)题解报告 A 不管 B 首先可以证明,如果存在解 其中必定有一个数的出现次数大于等于\(\frac{m}{2}\) 暴力枚举所有出现次数大于等于$\frac{m}{2} $的数 ...
- CFEducational Codeforces Round 66题解报告
CFEducational Codeforces Round 66题解报告 感觉丧失了唯一一次能在CF上超过wqy的机会QAQ A 不管 B 不能直接累计乘法打\(tag\),要直接跳 C 考虑二分第 ...
- CF Round #580(div2)题解报告
CF Round #580(div2)题解报告 T1 T2 水题,不管 T3 构造题,证明大约感性理解一下 我们想既然存在解 \(|a[n + i] - a[i]| = 1\) 这是必须要满足的 既然 ...
随机推荐
- CF1535F String Distance
\(CF1535F\ \ String\ Distance\) 题意 给 \(n\) 个长度均为 \(len\) 的字符串 \(T_1,T_2,\dots T_n\),定义 \(f(a,b)\) 为将 ...
- OpenYurt 之 Yurthub 数据过滤框架解析
简介:OpenYurt 是业界首个非侵入的边缘计算云原生开源项目,通过边缘自治,云边协同,边缘单元化,边缘流量闭环等能力为用户提供云边一体化的使用体验.在 Openyurt 里边缘网络可以使用数据过滤 ...
- 快手基于 Flink 的持续优化与实践
简介: 快手基于 Flink 的持续优化与实践的介绍. 一.Flink 稳定性持续优化 第一部分是 Flink 稳定性的持续优化.该部分包括两个方面,第一个方面,主要介绍快手在 Flink Kafka ...
- dotnet 读 WPF 源代码笔记 为什么自定义的 UserControl 用户控件不能跨程序集继承
从设计上,用户控件 UserControl 就不是一个合适用来多次继承的类型,更不要说进行跨程序集继承自定义的 UserControl 用户控件.对于大部分的用户控件来说,都是采用组合现有的控件来实现 ...
- 5.k8s Service四层负载:服务端口暴露
题目一:暴露服务service 设置配置环境: [candidate@node-1] $ kubectl config use-context k8s Task 请重新配置现有的 deployment ...
- 基于FPGA的二进制转BCD
BCD码(nary-Coded Decimal)又称二-十进制代码,亦称二进码十进数.是一种二进制的数字编码形式,用二进制编码的十进制代码.这种编码形式利用了四个位元来储存一个十进制的数码. 在数字 ...
- Quartus prime 的安装步骤:
- 解密Prompt系列28. LLM Agent之金融领域摸索:FinMem & FinAgent
本章介绍金融领域大模型智能体,并梳理金融LLM的相关资源.金融领域的大模型智能体当前集中在个股交易决策这个相对简单的场景,不需要考虑多资产组合的复杂场景.交易决策被简化成市场上各个信息,包括技术面,消 ...
- CCE云原生混部场景下的测试案例
本文分享自华为云社区<CCE云原生混部场景下在线任务抢占.压制离线任务CPU资源.保障在线任务服务质量效果测试>,作者:可以交个朋友. 背景 企业的 IT 环境通常运行两大类进程,一类是在 ...
- addEventListener添加事件监听
removeEventListener移除事件监听 window.addEventListener('mousedown', e => this.closeMenu(e)) window.add ...