标签:sum code 队列 mes line ble ++i ons math
这道题放在了 T4 的位置,以为很难,然后结束之后机房某现场 AC 的神仙告诉我这就是道简单贪心……
我一开始还不信,结果最后发现真的是贪心。
首先先将所有 \(x_i\) 初始化为 1,计算出这一块的 \(\sum F_i(x_i)\)。
然后对于每一个 \(x_i\),定义 \(d_i=F_i(x_i+1)-F_i(x_i)\)。
将这玩意放到优先队列里面,然后每一次取出 \(d_i\) 最小的,更新 \(x_i \leftarrow x_i+1\),更新答案,更新 \(d_i\),重新丢回优先队列里面。
当 \(\sum x_i=m\) 的时候就可以输出答案了。
Code:
/*
========= Plozia =========
Author:Plozia
Problem:Contest-Day1-subxor
Date:2021/6/7
Remarks:60pts
========= Plozia =========
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 1e5 + 10;
int n;
LL a[MAXN], sum[MAXN], ans;
int Read()
{
int sum = 0, fh = 1; char ch = getchar();
for (; ch < ‘0‘ || ch > ‘9‘; ch = getchar()) fh -= (ch == ‘-‘) << 1;
for (; ch >= ‘0‘ && ch <= ‘9‘; ch = getchar()) sum = sum * 10 + ch - ‘0‘;
return sum * fh;
}
int main()
{
// freopen("subxor.in", "r", stdin);
// freopen("subxor.out", "w", stdout);
n = Read();
for (register int i = 1; i <= n; ++i) a[i] = Read();
for (register int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + a[i];
for (register int l = 1; l <= n; ++l)
for (register int r = l; r <= n; ++r)
{
int d = sum[r] - sum[l - 1];
ans = ans ^ d;
}
printf("%lld\n", ans);
return 0;
}
标签:sum code 队列 mes line ble ++i ons math
原文地址:https://www.cnblogs.com/Plozia/p/14859198.html