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\) 这是必须要满足的 既然 ...
随机推荐
- SRC信息收集方法论
"感谢您阅读本篇博客!如果您觉得本文对您有所帮助或启发,请不吝点赞和分享给更多的朋友.您的支持是我持续创作的动力,也欢迎留言交流,让我们一起探讨技术,共同成长!谢谢!" SRC信息 ...
- 【笔记】Cross Join&lag与lead函数
Oracle Cross Join交叉连接 语法 CROSS JOIN 指定第一个表的所有行与第二个表的所有行连接.如果 table1 中有"x"行,table2 中有" ...
- 力扣344(java & python)-反转字符串(简单)
题目: 编写一个函数,其作用是将输入的字符串反转过来.输入字符串以字符数组 s 的形式给出. 不要给另外的数组分配额外的空间,你必须原地修改输入数组.使用 O(1) 的额外空间解决这一问题. 示例 1 ...
- 阿里云数字化安全生产平台 DPS V1.0 正式发布!
简介:数字化安全生产平台则帮助客户促进业务与 IT 的全面协同,从业务集中监控.业务流程管理.应急指挥响应等多维度来帮助客户建立完善专业的业务连续性保障体系. 作者:银桑.比扬 阿里云创立于 200 ...
- 日志服务SLS 助力识货 APP,解决业务数据采集查询监控问题
简介: 日志服务SLS 助力识货 APP,解决业务数据采集查询监控问题 更多存储标杆案例欢迎点击下方链接查看 阿里云存储标杆案例样板间 公司介绍识货APP是虎扑体育旗下的导购应用,致力于为广大年轻用户 ...
- Hologres揭秘:高性能原生加速MaxCompute核心原理
简介: Hologres技术揭秘系列持续更新中,本期我们将带来Hologres高性能原生加速查询MaxCompute的技术原理解析. Hologres(中文名交互式分析)是阿里云自研的一站式实时数仓, ...
- [FE] iframe 相关选项 x-frame-options: 设置 meta 标签无效 & helmet
The X-Frame-Options HTTP 响应头是用来给浏览器 指示允许一个页面 可否在 <frame>, <iframe>, <embed> 或者 < ...
- [Blockchain] (Binance Smart Chain) BSC 测试网 BNB 水龙头
测试网BNB水龙头 https://testnet.binance.org/faucet-smart 测试网区块浏览器 https://testnet.bscscan.com 主网区块浏览器 http ...
- WPF 探索任务管理器的进程分组逻辑
在看到 Win10 或 Win11 的 Task Manager 任务管理器时,不知大家是否有一个疑问,在 进程 标签里的应用进程是如何分组的.为什么有些组能包含很多个不同的进程,有些只能包含一个.本 ...
- LVGL 字体
一.LVGL 内置字体 LVGL有几种不同大小的内置字体,可以通过 LV_FONT_MONTSERRAT_X 定义在 lv_conf.h 中启用. 普通字体 包含所有ASCII字符,度数符号(U + ...