2017 ACM Arabella Collegiate Programming Contest div2的题,部分题目写个题解
F. Monkeying Around 维护点在多少个线段上
http://codeforces.com/gym/101350/problem/F
题意:有m个笑话,每个笑话的区间是[L, R],笑话种类有1e5,一开始所有猴子都在凳子上,听到一个笑话,就倒下,但是如果是听过的笑话,就重新回到凳子上。问最终有多少个猴子在凳子上。
相当于有1e5个线段,如果我们能知道第i个猴子,被多少个线段覆盖了,那么可以找出那些线段中的最后那一条,就是最后覆盖上去的那一条,那条线段是哪一个笑话,设为k,如果这个笑话覆盖这个猴子的次数 > 1,那么这个猴子将会回到凳子上。也就是只和最后一步有关
那么,假如有线段:
按左端点排序:[1, 100], [2, 2] ,一个扫描变量p1 = 1开始
按右端点排序:[2, 2], [1, 100], 一个扫描变量p2 = 1开始
就能很快判断到第i个猴子被那些线段覆盖了。
按顺序枚举每一个猴子i,比如i = 2
那么,把i >= segment1[p1].L的都表明这条线段能覆盖i
吧i > segment2[p2].R的都表明这条线段已经离开了i
然后统计即可。
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;
const int maxn = 2e5 + ;
struct Node {
int L, R, id;
}one[maxn], two[maxn];
bool cmp1(struct Node a, struct Node b) {
return a.L < b.L;
}
bool cmp2(struct Node a, struct Node b) {
return a.R < b.R;
}
int idForJoke[maxn];
int has[maxn];
set<int>ss;
void work() {
ss.clear();
memset(has, , sizeof has);
int n, m;
scanf("%d%d", &n, &m);
for (int i = ; i <= m; ++i) {
int pos, joke, dis;
scanf("%d%d%d", &pos, &joke, &dis);
one[i].L = max(, pos - dis), one[i].R = min(n, pos + dis), one[i].id = i;
two[i] = one[i];
idForJoke[i] = joke;
}
sort(one + , one + + m, cmp1);
sort(two + , two + + m, cmp2);
int ans = , p1 = , p2 = ;
for (int i = ; i <= n; ++i) {
while (p1 <= m && i >= one[p1].L) {
ss.insert(one[p1].id);
has[idForJoke[one[p1].id]]++;
++p1;
}
while (p2 <= m && i > two[p2].R) {
ss.erase(two[p2].id);
has[idForJoke[two[p2].id]]--;
++p2;
}
if (ss.size()) {
ans += has[idForJoke[*ss.rbegin()]] > ;
} else ans++;
}
printf("%d\n", ans);
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
int t;
scanf("%d", &t);
while (t--) work();
return ;
}
G. Snake Rana 容斥原理 + 数学
题意是给定一个n * m(n, m <= 1e4)的地图,有k <= 20个污点,问有多少个子矩形,不包含任何一个污点
首先要知道n * m的矩形里面,一共有多少个子矩形。
对于列来说,可以选择边长是1, 2, ... m,分别有m种、m - 1种、m - 2 ... 1种选法。
对于行来说,可以选择边长是1, 2, ....n, 分别有n种、n - 1种,....1种选法。
所以一共(1 + .... + n) * (1 + .... + m) = (n + 1) * n / 2 * (m + 1) * m / 2种
1 << k暴力枚举哪一个点在里面,容斥原理奇减偶加
若包含x个点,那这x个点肯定围成一个矩形,那么有多少个矩形包含这个矩形呢?

如法炮制,算出在y方向,左右扩展能有多少个矩形,x方向,上下扩展能有多少种可能,然后相乘即可。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
LL n, m;
int k;
const int maxn = + ;
int x[maxn], y[maxn];
LL ans;
void dfs(int cur, int sel, int x1, int y1, int x2, int y2) {
if (cur == k + ) {
if (!sel) return;
LL res = (x1) * (n - x2 + ) * (y1) * (m - y2 + );
if (sel & ) ans -= res;
else ans += res;
return;
}
dfs(cur + , sel + , min(x1, x[cur]), min(y1, y[cur]), max(x2, x[cur]), max(y2, y[cur]));
dfs(cur + , sel, x1, y1, x2, y2);
} void work() {
scanf("%d%d%d", &n, &m, &k);
for (int i = ; i <= k; ++i) {
scanf("%d%d", &x[i], &y[i]);
}
ans = (n + ) * n / * (m + ) * m / ;
dfs(, , inf, inf, -inf, -inf);
cout << ans << endl;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
int t;
scanf("%d", &t);
while (t--) work();
return ;
}
I. Mirrored String II 简单manacher变种不写题解了。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
#include <time.h>
const int maxn = 5e3 + ;
char str[maxn];
bool book[maxn];
int p[maxn];
int manacher(char str[], int lenstr) {
str[] = '*';
for (int i = lenstr; i >= ; --i) {
str[i + i + ] = str[i + ];
str[i + i + ] = '#';
}
int id = , maxLen = ;
for (int i = ; i <= * lenstr + ; ++i) {
if (!book[str[i]]) {
p[i] = ;
continue;
}
if (p[id] + id > i) {
p[i] = min(p[id] + id - i, p[ * id - i]);
} else p[i] = ;
while (str[i + p[i]] == str[i - p[i]] && (book[str[i - p[i]]] || str[i - p[i]] == '#')) ++p[i];
if (p[id] + id < p[i] + i) id = i;
maxLen = max(maxLen, p[i]);
}
return maxLen - ;
}
void work() {
scanf("%s", str + );
int lenstr = strlen(str + );
bool flag = false;
for (int i = ; i <= lenstr; ++i) {
if (book[str[i]]) {
flag = true;
break;
}
}
if (!flag) {
printf("0\n");
return;
}
printf("%d\n", manacher(str, lenstr));
}
I
A题待补,还有一题好像是防ak还没看,其他都是简单题,不过还是挺有意思
,
2017 ACM Arabella Collegiate Programming Contest div2的题,部分题目写个题解的更多相关文章
- 2017 ACM Arabella Collegiate Programming Contest(solved 11/13)
省选考前单挑做点ACM练练细节还是很不错的嘛- 福利:http://codeforces.com/gym/101350 先来放上惨不忍睹的virtual participate成绩(中间跑去食堂吃饭于 ...
- 容斥 或者 单调栈 hihocoder #1476 : 矩形计数 和 G. Snake Rana 2017 ACM Arabella Collegiate Programming Contest
先说一个简单的题目(题目大意自己看去,反正中文):hihocoder上的:http://hihocoder.com/problemset/problem/1476 然后因为这个n和m的矩阵范围是100 ...
- 脑洞 博弈 E. Competitive Seagulls 2017 ACM Arabella Collegiate Programming Contest
题目链接:http://codeforces.com/gym/101350/problem/E 题目大意:给你一个长度为n的方格,方格上面都被染色成了白色.每次染色都是选择白色的,假设目前选择的这块白 ...
- 2017 ACM Arabella Collegiate Programming Contest(solved 9/13, complex 12/13)
A.Sherlock Bones 题意: 给出长度为n的01串,问f(i,j)=f(j,k),(i<j<k)的i,j,k取值种数.其中f(i,j)表示[i,j]内1的个数, 且s[j]必须 ...
- 带权并查集:CF-2015 ACM Arabella Collegiate Programming Contest(F题)
F. Palindrome Problem Description A string is palindrome if it can be read the same way in either di ...
- gym100676 [小熊骑士限定]2015 ACM Arabella Collegiate Programming Contest
Kuma Rider久违的第二场训练,这场很水,又在vj的榜单上看到第一场的大哥了,2小时ak,大哥牛啤! A.水 #include<cstdio> #include<iostrea ...
- 2015 ACM Arabella Collegiate Programming Contest
题目链接:https://vjudge.net/contest/154238#overview. ABCDE都是水题. F题,一开始分类讨论,结果似乎写挫了,WA了一发.果断换并查集上,A了. G题, ...
- 2017 ACM Jordanian Collegiate Programming Contest
A. Chrome Tabs 当$n=1$时答案为$0$,当$k=1$或$k=n$时答案为$1$,否则答案为$2$. #include<cstdio> int T,n,k; int mai ...
- 2017 ACM Amman Collegiate Programming Contest 题解
[题目链接] A - Watching TV 模拟.统计一下哪个数字最多即可. #include <bits/stdc++.h> using namespace std; const in ...
随机推荐
- 重新拾取:ASP.NET Core WebApi 使用Swagger支持授权认证
园子里已经有很多.NET Core 集成Swagger的文章,但对于使用授权的介绍蛮少的. public static class SwaggerServiceExtensions { public ...
- html制作细线表格
关于这个细线表格的制作方法,百度一下可能就会有答案告诉你设置这几个值:给table设置border="0" cellspacing="1" bgcolor=&q ...
- 「UVA557」 Burger(概率
本题征求翻译.如果你能提供翻译或者题意简述,请 提交翻译 ,感谢你的贡献. 题目描述 PDF 输入输出格式 输入格式: 输出格式: 输入输出样例 输入样例#1: 复制 3 6 10 256 输出样例# ...
- Virtual Codeforces Round #392 (Div. 2)
下午闲来无事开了一场Virtual participation 2h就过了3道水题...又跪了..这只是Div. 2啊!!! 感觉这次直接就是跪在了读题上,T1,T2读题太慢,T3还把题读错了 要是让 ...
- WPF ListView VisualPanel
<ItemsPanelTemplate x:Key="ItemsPanelTemplate1"> &l ...
- LINUX socket网络编程
1. 网络中进程之间如何通信 进 程通信的概念最初来源于单机系统.由于每个进程都在自己的地址范围内运行,为保证两个相互通信的进 程之间既互不干扰又协调一致工作,操作系统为进程通信提供了相应设施,如 U ...
- CF-811A
A. Vladik and Courtesy time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Oracle tns 协议
下面是翻译国外的一篇博客,原文连接如下: https://thesprawl.org/research/oracle-tns-protocol/ 简介 TNS(Transparent Network ...
- UVa 11404 Palindromic Subsequence (LCS)
题意:给定一个字符串,问删除一些字符,使得它成为一个最长回访串,如果有多个,输出字典序最小的那个. 析: 我们可以把原字符串反转,然后求两个串的LCS,就得到最长回文串,不过要注意一些细节. 代码如下 ...
- 转换为标准IPv4格式
Insus.NET刚写了一个函数,把一个IP地址转换为标准格式,即每段位均是由3个数字组成. SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- = ...