Educational Codeforces Round 155 (Rated for Div
B. Chips on the Board
题解:贪心
显然我们可以把题意转化为:对于任意一个\((i,j)\),我们可以花费\(a_{i,j}\)的代价占据第\(i\)行和第\(j\)列,求占据所有格子的最小代价
考虑两种情况:
- 在每一行选一个格子
- 在每一列选一个格子
贪心选即可
int n, a[N], b[N];
void solve()
{
cin >> n;
int posa = -1, posb = -1;
for (int i = 1; i <= n; ++i)
{
cin >> a[i];
if (posa == -1 || a[i] < a[posa])
posa = i;
}
for (int i = 1; i <= n; ++i)
{
cin >> b[i];
if (posb == -1 || b[i] < b[posb])
posb = i;
}
int ans = INF, sum = 0;
for (int i = 1; i <= n; ++i)
sum += a[i];
sum += n * b[posb];
ans = min(ans, sum);
sum = 0;
for (int i = 1; i <= n; ++i)
sum += b[i];
sum += n * a[posa];
ans = min(ans, sum);
cout << ans << endl;
}
C. Make it Alternating
题解:组合数学
显然可以将字符串\(s\)分成由连续\(1\)或\(0\)组成的几段区间,那么最小操作次数显然是区间的数量
我们考虑方案数:
对于每段区间,我们必须留下一个数,假设某段区间的长度为\(len\),那么对答案的贡献为:\(ans:=ans\times len\)
那么其他没有被留下的数就要全部被删除,那么删除的顺序任意,假设被删除的数的数量为\(cnt\),那么对答案的贡献为\(ans:=ans \times cnt!\)
int n, fac[N];
void init()
{
fac[0] = 1ll;
for (int i = 1; i < N; ++i)
fac[i] = (fac[i - 1] * i) % mod;
}
void solve()
{
string s;
cin >> s;
n = s.length();
s = " " + s;
int ans1 = 0, ans2 = 1;
for (int i = 1; i < n; ++i)
ans1 += (s[i] == s[i + 1]);
int l, r, f = 0;
for (int i = 1; i < n; ++i)
{
if (!f && s[i] == s[i + 1])
{
f = 1;
l = i;
}
else if (f && s[i] != s[i + 1])
{
f = 0;
r = i;
ans2 *= (r - l + 1);
ans2 %= mod;
}
else if (f && i + 1 == n)
{
f = 0;
r = n;
ans2 *= (r - l + 1);
ans2 %= mod;
}
}
if (f)
ans2 = ans2 * (n - l + 1) % mod;
ans2 = ans2 * fac[ans1] % mod;
cout << ans1 << " " << ans2 << endl;
}
D. Sum of XOR Functions
题解:按位计算贡献
- 我们发现,对于二进制中某一位\(i\)来说,我们考虑其对答案的贡献 :
\[2^i \sum_{r = 1}^n \sum_{l=1}^r g(l,r)(r - l + 1)
\]\(g(l,r)\)为第\(i\)位二进制在\([l,r]\)中\(1\)的个数,如果\(1\)为奇数,则\(g(l,r)=1\),否则\(g(l,r) = 0\)
那么题目就转化为:对于一个\(01\)序列,固定右端点\(r\),求有多少个左端点\(l\)使得\(g(l,r)=1\)
我们定义\(pre[i]\)为\([1,i]\)的前缀异或和,那么\(pre[r] \oplus pre[l-1] = 1\)就代表\(g(l,r)=1\)
那么我们完全可以对前缀维护一个\(cnt\)和\(sum\)
所以复杂度为 \(O(30n)\)
int n, a[N];
ll add(ll a, ll b) { return (a + b) % mod; }
ll sub(ll a, ll b) { return ((a - b) % mod + mod) % mod; }
void solve()
{
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i];
int ans = 0ll;
// 考虑每一位二进制对答案产生的贡献
for (int i = 0; i <= 30; ++i)
{
vector<int> vec(n + 10), pre(n + 10), cnt(2), sum(2);
int res = 0ll;
cnt[0]++; // pre[0] = 0
for (int j = 1; j <= n; ++j)
{
vec[j] = (a[j] >> i & 1);
pre[j] = (pre[j - 1] ^ vec[j]);
cnt[pre[j]]++;
sum[pre[j]] += j;
res = add(res, sub((cnt[pre[j] ^ 1] * (j) % mod), sum[pre[j] ^ 1]));
}
ans = add(ans, (1ll << i) * res % mod);
}
cout << ans << endl;
}
Educational Codeforces Round 155 (Rated for Div的更多相关文章
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- Educational Codeforces Round 39 (Rated for Div. 2) G
Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...
- Educational Codeforces Round 48 (Rated for Div. 2) CD题解
Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...
- Educational Codeforces Round 60 (Rated for Div. 2) 题解
Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...
随机推荐
- 推荐一款流量录制回放工具:jvm-sandbox-repeater
在软件开发和测试过程中,我们经常会遇到需要对网络请求进行录制和回放的需求,以便进行调试.测试和分析.为了模拟真实的用户请求,我们通常会使用各种流量录制回放工具来记录并重放网络请求. 其中,jvm-sa ...
- 知乎问题:为什么很多web项目还是使用 px,而不是 rem?
阅读过几篇关于 px rem 的文章,感觉 rem 很强大.但是自己接触到的公司项目全部都使用 px,想知道为什么.是我司技术更新落后了吗? 我们当然有在用 vw 和 vh,但是只是在 layout ...
- 升讯威在线客服系统如何高性能同时支持 MySQL 和 SQL Server
升讯威在线客服与营销系统是基于 .net core / WPF 开发的一款在线客服软件,宗旨是: 开放.开源.共享.努力打造 .net 社区的一款优秀开源产品. 前段时间我发表了一系列文章,开始介绍基 ...
- Project: Kill e
接到上级任务,今天来暗杀 \(e\) 据说杀死 \(e\) 的方式就是把他算出来,好吧,现在我们还是来算一下 考虑使用如下代数式求解 \[e\ \text{site:baidu.com} \] 虽然我 ...
- Java poi 读取 word 、 pdf
从各个博客 CV 出来的,不好意思 pom <dependency> <groupId>org.apache.poi</groupId> <artifactI ...
- Java日期时间API系列20-----Jdk8中java.time包中的新的日期时间API类,ZoneId时区ID大全等。
Java日期时间API系列19-----Jdk8中java.time包中的新的日期时间API类,ZonedDateTime与ZoneId和LocalDateTime的关系,ZonedDateTime格 ...
- Oracle 23c 新特性实操体验优质文章汇总 | 有奖征文进行中欢迎参与
继4月3日甲骨文宣布推出免费开发者版 Oracle Database 23c后,墨天轮社区发起 "Oracle 23c 免费开发者版特性体验"有奖征文活动,邀请大家分享Oracle ...
- 2022年7月中国数据库排行榜:墨天轮榜单榜眼易主,PolarDB得分涨幅最大
信创元年,后起之秀,大有可为.2022年7月的 墨天轮中国数据库流行度排行榜 风起云涌,本月排行榜共有232个数据库参与排名,相比上月,新增 ShuangzhaoDB 数据库.榜单前十名的唯一变化是达 ...
- vue3自动导入 api ,不需要多次导入 api 了
安装插件 npm i -D unplugin-auto-import 配置 vite.config.js export default defineConfig({ plugins: [ vue( ...
- 开源的口袋妖怪自走棋「GitHub 热点速览」
作为一名 90 后,我对口袋妖怪(宝可梦)游戏有着特殊的感情,满满的都是回忆.如果你也喜欢宝可梦主题的游戏,这款开源的宝可梦自走棋游戏 pokemonAutoChess 一定要试试,它采用战棋(自走棋 ...


