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

然后统计即可。

  1. #include <bits/stdc++.h>
  2. #define IOS ios::sync_with_stdio(false)
  3. using namespace std;
  4. #define inf (0x3f3f3f3f)
  5. typedef long long int LL;
  6. const int maxn = 2e5 + ;
  7. struct Node {
  8. int L, R, id;
  9. }one[maxn], two[maxn];
  10. bool cmp1(struct Node a, struct Node b) {
  11. return a.L < b.L;
  12. }
  13. bool cmp2(struct Node a, struct Node b) {
  14. return a.R < b.R;
  15. }
  16. int idForJoke[maxn];
  17. int has[maxn];
  18. set<int>ss;
  19. void work() {
  20. ss.clear();
  21. memset(has, , sizeof has);
  22. int n, m;
  23. scanf("%d%d", &n, &m);
  24. for (int i = ; i <= m; ++i) {
  25. int pos, joke, dis;
  26. scanf("%d%d%d", &pos, &joke, &dis);
  27. one[i].L = max(, pos - dis), one[i].R = min(n, pos + dis), one[i].id = i;
  28. two[i] = one[i];
  29. idForJoke[i] = joke;
  30. }
  31. sort(one + , one + + m, cmp1);
  32. sort(two + , two + + m, cmp2);
  33. int ans = , p1 = , p2 = ;
  34. for (int i = ; i <= n; ++i) {
  35. while (p1 <= m && i >= one[p1].L) {
  36. ss.insert(one[p1].id);
  37. has[idForJoke[one[p1].id]]++;
  38. ++p1;
  39. }
  40. while (p2 <= m && i > two[p2].R) {
  41. ss.erase(two[p2].id);
  42. has[idForJoke[two[p2].id]]--;
  43. ++p2;
  44. }
  45. if (ss.size()) {
  46. ans += has[idForJoke[*ss.rbegin()]] > ;
  47. } else ans++;
  48. }
  49. printf("%d\n", ans);
  50. }
  51.  
  52. int main() {
  53. #ifdef local
  54. freopen("data.txt", "r", stdin);
  55. // freopen("data.txt", "w", stdout);
  56. #endif
  57. int t;
  58. scanf("%d", &t);
  59. while (t--) work();
  60. return ;
  61. }

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方向,上下扩展能有多少种可能,然后相乘即可。

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <assert.h>
  7. #define IOS ios::sync_with_stdio(false)
  8. using namespace std;
  9. #define inf (0x3f3f3f3f)
  10. typedef long long int LL;
  11.  
  12. #include <iostream>
  13. #include <sstream>
  14. #include <vector>
  15. #include <set>
  16. #include <map>
  17. #include <queue>
  18. #include <string>
  19. #include <bitset>
  20. LL n, m;
  21. int k;
  22. const int maxn = + ;
  23. int x[maxn], y[maxn];
  24. LL ans;
  25. void dfs(int cur, int sel, int x1, int y1, int x2, int y2) {
  26. if (cur == k + ) {
  27. if (!sel) return;
  28. LL res = (x1) * (n - x2 + ) * (y1) * (m - y2 + );
  29. if (sel & ) ans -= res;
  30. else ans += res;
  31. return;
  32. }
  33. dfs(cur + , sel + , min(x1, x[cur]), min(y1, y[cur]), max(x2, x[cur]), max(y2, y[cur]));
  34. dfs(cur + , sel, x1, y1, x2, y2);
  35. }
  36.  
  37. void work() {
  38. scanf("%d%d%d", &n, &m, &k);
  39. for (int i = ; i <= k; ++i) {
  40. scanf("%d%d", &x[i], &y[i]);
  41. }
  42. ans = (n + ) * n / * (m + ) * m / ;
  43. dfs(, , inf, inf, -inf, -inf);
  44. cout << ans << endl;
  45. }
  46.  
  47. int main() {
  48. #ifdef local
  49. freopen("data.txt", "r", stdin);
  50. // freopen("data.txt", "w", stdout);
  51. #endif
  52. int t;
  53. scanf("%d", &t);
  54. while (t--) work();
  55. return ;
  56. }

I. Mirrored String II   简单manacher变种不写题解了。

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <assert.h>
  7. #define IOS ios::sync_with_stdio(false)
  8. using namespace std;
  9. #define inf (0x3f3f3f3f)
  10. typedef long long int LL;
  11.  
  12. #include <iostream>
  13. #include <sstream>
  14. #include <vector>
  15. #include <set>
  16. #include <map>
  17. #include <queue>
  18. #include <string>
  19. #include <bitset>
  20. #include <time.h>
  21. const int maxn = 5e3 + ;
  22. char str[maxn];
  23. bool book[maxn];
  24. int p[maxn];
  25. int manacher(char str[], int lenstr) {
  26. str[] = '*';
  27. for (int i = lenstr; i >= ; --i) {
  28. str[i + i + ] = str[i + ];
  29. str[i + i + ] = '#';
  30. }
  31. int id = , maxLen = ;
  32. for (int i = ; i <= * lenstr + ; ++i) {
  33. if (!book[str[i]]) {
  34. p[i] = ;
  35. continue;
  36. }
  37. if (p[id] + id > i) {
  38. p[i] = min(p[id] + id - i, p[ * id - i]);
  39. } else p[i] = ;
  40. while (str[i + p[i]] == str[i - p[i]] && (book[str[i - p[i]]] || str[i - p[i]] == '#')) ++p[i];
  41. if (p[id] + id < p[i] + i) id = i;
  42. maxLen = max(maxLen, p[i]);
  43. }
  44. return maxLen - ;
  45. }
  46. void work() {
  47. scanf("%s", str + );
  48. int lenstr = strlen(str + );
  49. bool flag = false;
  50. for (int i = ; i <= lenstr; ++i) {
  51. if (book[str[i]]) {
  52. flag = true;
  53. break;
  54. }
  55. }
  56. if (!flag) {
  57. printf("0\n");
  58. return;
  59. }
  60. printf("%d\n", manacher(str, lenstr));
  61. }

I

A题待补,还有一题好像是防ak还没看,其他都是简单题,不过还是挺有意思

2017 ACM Arabella Collegiate Programming Contest div2的题,部分题目写个题解的更多相关文章

  1. 2017 ACM Arabella Collegiate Programming Contest(solved 11/13)

    省选考前单挑做点ACM练练细节还是很不错的嘛- 福利:http://codeforces.com/gym/101350 先来放上惨不忍睹的virtual participate成绩(中间跑去食堂吃饭于 ...

  2. 容斥 或者 单调栈 hihocoder #1476 : 矩形计数 和 G. Snake Rana 2017 ACM Arabella Collegiate Programming Contest

    先说一个简单的题目(题目大意自己看去,反正中文):hihocoder上的:http://hihocoder.com/problemset/problem/1476 然后因为这个n和m的矩阵范围是100 ...

  3. 脑洞 博弈 E. Competitive Seagulls 2017 ACM Arabella Collegiate Programming Contest

    题目链接:http://codeforces.com/gym/101350/problem/E 题目大意:给你一个长度为n的方格,方格上面都被染色成了白色.每次染色都是选择白色的,假设目前选择的这块白 ...

  4. 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]必须 ...

  5. 带权并查集: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 ...

  6. gym100676 [小熊骑士限定]2015 ACM Arabella Collegiate Programming Contest

    Kuma Rider久违的第二场训练,这场很水,又在vj的榜单上看到第一场的大哥了,2小时ak,大哥牛啤! A.水 #include<cstdio> #include<iostrea ...

  7. 2015 ACM Arabella Collegiate Programming Contest

    题目链接:https://vjudge.net/contest/154238#overview. ABCDE都是水题. F题,一开始分类讨论,结果似乎写挫了,WA了一发.果断换并查集上,A了. G题, ...

  8. 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 ...

  9. 2017 ACM Amman Collegiate Programming Contest 题解

    [题目链接] A - Watching TV 模拟.统计一下哪个数字最多即可. #include <bits/stdc++.h> using namespace std; const in ...

随机推荐

  1. (转)C语言之原码、反码和补码

    原码.反码和补码 1).数据在内存中存储的时候都是以二进制的形式存储的. int num = 10; 原码.反码.补码都是二进制.只不过是二进制的不同的表现形式. 数据是以补码的二进制存储的. 2). ...

  2. MAC OS Sierra 10.12.6 下对固态硬盘SSD 开启TRIM功能

    这个是对于不是mac原装SSD的情况下才做的操作... 大家都知道,苹果店卖的SSD硬盘那怕就是一个256G的也要1000多人民币,而市场上的也就400-500左右人民币,整整少了一半还要多,可见JS ...

  3. appium 支持输入中文

    加入: desired_caps['unicodeKeyboard'] = True desired_caps['resetKeyboard'] = True 使用输入中文: input_txt = ...

  4. ACM学习历程—FZU 2140 Forever 0.5(计算几何 && 构造)

    Description   Given an integer N, your task is to judge whether there exist N points in the plane su ...

  5. ACM学习历程—HDU1028 Ignatius and the Princess(组合数学)

    Ignatius and the Princess Description        "Well, it seems the first problem is too easy. I w ...

  6. 【LeetCode】062. Unique Paths

    题目: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). ...

  7. 浏览器,tab页显示隐藏的事件监听--页面可见性

    //监听浏览器tab切换,以便在tab切换之后,页面隐藏的时候,把弹幕停止 document.addEventListener('webkitvisibilitychange', function() ...

  8. poj2411铺砖——状压DP

    题目:http://poj.org/problem?id=2411 状态压缩,一行的状态记为一个二进制数,从上往下逐行DP,答案输出最后一行填0的方案数. 代码如下: #include<iost ...

  9. xml约束(转)

    在XML技术里,可以编写一个文档来约束一个XML文档的书写规范,这称之为XML约束. 常用的约束技术XML DTD :XML Schema. XML Schema 也是一种用于定义和描述 XML 文档 ...

  10. 如何解决WAMP Server 与IIS端口冲突问题

    PHP也是一门开发网页的语言,WAMP Server 是它的一个较好的集成开发环境,今日,小编发现好多Wamp Server 安装后启动local host 出现的却是IIS页面!为什么会这样呢? 出 ...