“华为杯”大连理工大学第12届大学生程序设计大赛
Posted kzns
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了“华为杯”大连理工大学第12届大学生程序设计大赛相关的知识,希望对你有一定的参考价值。
E 膜法项链
#include <cstdio>
#include <algorithm>
using namespace std;
#define Nmax 1000010
int A[Nmax*2];
int N, W;
long long cnt[Nmax * 2];
void adin(int x, int lx, int rx, int a) {
int l, r;
l = x - lx;
r = max(rx - max(x, N+1), 0);
cnt[rx-r-x+1] += a;
cnt[rx-r-x+1+r] -= a;
cnt[rx-r-x+1+l] -= a;
cnt[rx-r-x+1+l+r] += a;
}
int main() {
scanf("%d %d", &N, &W);
for (int i = 1; i <= N; i++) {
scanf("%d", A+i);
A[N+i] = A[i];
}
int ls[Nmax][2], t = 0;
ls[0][0] = 0;
ls[0][1] = 0;
t = 1;
for (int i = 1; i <= N*2; i++) {
while (ls[t-1][0] >= A[i]) {
t--;
adin(ls[t][1], ls[t-1][1], i, ls[t][0]);
}
ls[t][0] = A[i];
ls[t][1] = i;
t++;
}
while (t > 1) {
t--;
adin(ls[t][1], ls[t-1][1], N*2+1, ls[t][0]);
}
for (int i = 2; i <= N; i++)
cnt[i] += cnt[i-1];
for (int i = 2; i <= N; i++)
cnt[i] += cnt[i-1];
long long ans = 0x7fffffffffffffffll;
for (int i = 1; i <= N; i++) {
ans = min(ans, cnt[i] + (long long)W*(i-1));
}
printf("%lld
", ans);
return 0;
}
J 更强的未来道具FG-C193
#include <cstdio>
#include <algorithm>
using namespace std;
#define Nmax 100010
int N;
int re[Nmax*2];
int len2;
int fa[Nmax*2];
int cnt[Nmax*2];
int FA(int x) {
if (fa[x] == x)
return x;
else
return fa[x] = FA(fa[x]);
}
void marge(int x, int y) {
x = FA(x);
y = FA(y);
if (x != y) {
if (cnt[x] < cnt[y])
fa[x] = y;
else if (cnt[y] < cnt[x])
fa[y] = x;
else {
fa[y] = x;
cnt[x]++;
}
}
}
void manacher() {
int r = -1, c = -1;
int l;
for (int i = 0; i < len2; i++) {
if (i <= r) {
l = min(re[c-(i-c)], r-i+1);
}
else
l = 1;
while (l < re[i]) {
marge(i-l, i+l);
l++;
}
if (i+re[i]-1 > r) {
r = i+re[i]-1;
c = i;
}
}
}
char s[Nmax*2];
int main() {
scanf("%d", &N);
len2 = N*2+1;
for (int i = 0; i < len2; i++)
fa[i] = i;
re[0] = 1;
for (int i = 1; i < len2; i++) {
scanf("%d", re+i);
if (i&1) {
re[i] = re[i]*2;
}
else {
re[i] = re[i]*2+1;
}
}
manacher();
int M;
scanf("%d", &M);
int x;
char c;
int ans = 0;
for (int i = 0; i < M; i++) {
scanf("%d %c", &x, &c);
x = FA(1+x*2);
if (s[x]) {
if (s[x] != c)
ans = -1;
}
else {
s[x] = c;
}
}
if (ans == -1) {
printf("-1
");
return 0;
}
for (int i = 0; i < N; i++) {
if (!s[FA(1+i*2)]) {
printf("%d ", i);
ans++;
}
}
if (!ans) {
for (int i = 0; i < N; i++) {
printf("%c", s[FA(1+i*2)]);
}
}
return 0;
}
K 取模运算
#include <cstdio>
using namespace std;
#define spl 317
int ls[100010];
int cnt[100010];
int mp[spl+3][spl+3];
int N, M;
int main() {
scanf("%d %d", &N, &M);
int a;
for (int i = 1; i <= N; i++) {
scanf("%d", &a);
ls[i] = a;
cnt[a]++;
for (int i = 1; i < spl; i++) {
mp[i][a%i]++;
}
}
int op, x, y;
int ans;
for (int i = 0; i < M; i++) {
scanf("%d %d %d", &op, &x, &y);
if (op == 1) {
cnt[ls[x]]--;
for (int i = 1; i < spl; i++)
mp[i][ls[x]%i]--;
ls[x] = y;
cnt[y]++;
for (int i = 1; i < spl; i++) {
mp[i][y%i]++;
}
}
else {
if (y < spl) {
ans = mp[y][x];
}
else {
ans = 0;
for (; x <= 100000; x += y) {
ans += cnt[x];
}
}
printf("%d
", ans);
}
}
return 0;
}
以上是关于“华为杯”大连理工大学第12届大学生程序设计大赛的主要内容,如果未能解决你的问题,请参考以下文章
2018年“华为杯”河北科技大学 “图像识别控制大赛”规则附件
最简单的问题(重庆市第八届大学生程序设计大赛D) (线段树+离线思想)