https://www.lydsy.com/JudgeOnline/problem.php?id=3718

有时候,要透过题面看到本质

题意 你的老板命令你将停车场里的车移动成他想要的样子。
停车场是一个长条矩形,宽度为w。我们以其左下角顶点为原点,坐标轴平行于矩形的边,建立直角坐标系。停车场很长,我们可以认为它一直向右边伸展到无穷远处。
车都是边平行于坐标轴的矩形,大小可能不同。你可以将车任意地平移(但不能旋转),只要他们不超出停车场的边界,且不能互相碰撞,但紧挨着是允许的(即任意时刻任两辆车的重叠面积为0)。
你知道目前各辆车的摆放位置,以及老板心中所想的位置。你需要判断是否可以办到老板的任务。

乍一看觉得毫无地方可以下手,仔细一想会贪心的想到去一个个排列,但也觉得不太好做,但是事实上一辆汽车的移动我们可以用三个条件来描述,他的起始点s,他的终点e,他的宽度w,如果有两辆车满足 s1 < s2 && e1 > e2 && w1 + w2 > W的时候,就是否定情况,否则位肯定情况。因为在这种情况下的两辆车必定需要并排交错。

这就成了一个三维问题,考虑用排序+树状数组维护前缀最大值解决即可,注意加一个离散化。

  1. #include <map>
  2. #include <set>
  3. #include <ctime>
  4. #include <cmath>
  5. #include <queue>
  6. #include <stack>
  7. #include <vector>
  8. #include <string>
  9. #include <cstdio>
  10. #include <cstdlib>
  11. #include <cstring>
  12. #include <sstream>
  13. #include <iostream>
  14. #include <algorithm>
  15. #include <functional>
  16. using namespace std;
  17. #define For(i, x, y) for(int i=x;i<=y;i++)
  18. #define _For(i, x, y) for(int i=x;i>=y;i--)
  19. #define Mem(f, x) memset(f,x,sizeof(f))
  20. #define Sca(x) scanf("%d", &x)
  21. #define Sca2(x,y) scanf("%d%d",&x,&y)
  22. #define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
  23. #define Scl(x) scanf("%lld",&x);
  24. #define Pri(x) printf("%d\n", x)
  25. #define Prl(x) printf("%lld\n",x);
  26. #define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
  27. #define LL long long
  28. #define ULL unsigned long long
  29. #define mp make_pair
  30. #define PII pair<int,int>
  31. #define PIL pair<int,long long>
  32. #define PLL pair<long long,long long>
  33. #define pb push_back
  34. #define fi first
  35. #define se second
  36. typedef vector<int> VI;
  37. const double eps = 1e-;
  38. const int maxn = 5e4 + ;
  39. const int INF = 0x3f3f3f3f;
  40. const int mod = 1e9 + ;
  41. int N,M,K,W;
  42. int tree[maxn];
  43. struct Point{
  44. int x1,y1,x2,y2;
  45. int id,w;
  46. }s[maxn],e[maxn];
  47. struct Car{
  48. int s,e,w;
  49. }car[maxn];
  50. int Hash[maxn];
  51. int lowbit(int t){
  52. return t & -t;
  53. }
  54. void add(int x,int t){
  55. for(;x <= N ; x+= lowbit(x)) tree[x] = max(tree[x],t);
  56. }
  57. int getmax(int t){
  58. int s = ;
  59. for(;t > ;t -= lowbit(t)) s = max(s,tree[t]);
  60. return s;
  61. }
  62. bool cmp(Car a,Car b){
  63. return a.e > b.e;
  64. }
  65. int main()
  66. {
  67. int T; Sca(T);
  68. while(T--){
  69. Sca2(N,W); Mem(tree,);
  70. For(i,,N){
  71. int x1,y1,x2,y2;
  72. Sca2(x1,y1); Sca2(x2,y2);
  73. car[i].s = Hash[i] = min(x1,x2);
  74. car[i].w = abs(y2 - y1);
  75. }
  76. For(i,,N){
  77. int x1,y1,x2,y2;
  78. Sca2(x1,y1); Sca2(x2,y2);
  79. car[i].e = min(x1,x2);
  80. }
  81. sort(Hash + ,Hash + + N);
  82. int cnt = unique(Hash + ,Hash + + N) - Hash - ;
  83. For(i,,N) car[i].s = lower_bound(Hash + ,Hash + + cnt,car[i].s) - Hash;
  84. sort(car + ,car + + N,cmp);
  85. bool flag = ;
  86. For(i,,N){
  87. int j = i;
  88. for(;car[i].e == car[j].e && j <= N; j++); j--;
  89. for(int k = i ; k <= j ; k ++) if(getmax(car[k].s - ) + car[k].w > W) flag = ;
  90. for(int k = i; k <= j ; k ++) add(car[k].s,car[k].w);
  91. i = j;
  92. }
  93. if(flag) puts("TAK");
  94. else puts("NIE");
  95. }
  96. #ifdef VSCode
  97. system("pause");
  98. #endif
  99. return ;
  100. }

bzoj3718 树状数组的更多相关文章

  1. BZOJ3718[PA2014]Parking——树状数组

    题目描述 你的老板命令你将停车场里的车移动成他想要的样子.停车场是一个长条矩形,宽度为w.我们以其左下角顶点为原点,坐标轴平行于矩形的边,建立直角坐标系.停车场很长,我们可以认为它一直向右边伸展到无穷 ...

  2. 2018.10.29 bzoj3718: [PA2014]Parking(树状数组)

    传送门 显然只用判断两个会相交的车会不会卡住就行了. 直接树状数组维护后缀最大值就行了. 代码: #include<bits/stdc++.h> using namespace std; ...

  3. BZOJ 1103: [POI2007]大都市meg [DFS序 树状数组]

    1103: [POI2007]大都市meg Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2221  Solved: 1179[Submit][Sta ...

  4. bzoj1878--离线+树状数组

    这题在线做很麻烦,所以我们选择离线. 首先预处理出数组next[i]表示i这个位置的颜色下一次出现的位置. 然后对与每种颜色第一次出现的位置x,将a[x]++. 将每个询问按左端点排序,再从左往右扫, ...

  5. codeforces 597C C. Subsequences(dp+树状数组)

    题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standar ...

  6. BZOJ 2434: [Noi2011]阿狸的打字机 [AC自动机 Fail树 树状数组 DFS序]

    2434: [Noi2011]阿狸的打字机 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 2545  Solved: 1419[Submit][Sta ...

  7. BZOJ 3529: [Sdoi2014]数表 [莫比乌斯反演 树状数组]

    3529: [Sdoi2014]数表 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 1399  Solved: 694[Submit][Status] ...

  8. BZOJ 3289: Mato的文件管理[莫队算法 树状数组]

    3289: Mato的文件管理 Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 2399  Solved: 988[Submit][Status][Di ...

  9. 【Codeforces163E】e-Government AC自动机fail树 + DFS序 + 树状数组

    E. e-Government time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...

随机推荐

  1. Upload Files In ASP.NET Core 1.0 (Form POST And JQuery Ajax)

    Uploading files is a common requirement in web applications. In ASP.NET Core 1.0 uploading files and ...

  2. <c:forEach>可以默认的把以逗号分隔的字符串作为一个集合来遍历

    <c:forEach>可以默认的把以逗号分隔的字符串作为一个集合来遍历

  3. hdu-3068(最长回文子串-manacher)

    题意:求一个字符串#include<iostream>#include<algorithm>#include<cstring>using namespace std ...

  4. Android 模块化/热修复/插件化 框架选用

    概念汇总 动态加载:在程序运行的时候,加载一些程序自身原本不存在的文件并运行这些文件里的代码逻辑.动态加载是热修复与插件化实现的基础. 热修复:修改部分代码,不用重新发包,在用户不知情的情况下,给ap ...

  5. JAVA spring配置文件总结

    首先来看一个标准的Spring配置文件 applicationContext.xml <?xml version="1.0" encoding="UTF-8&quo ...

  6. 第二十天 模块 sys os os下path settings random shuit

    一.sys模块 1.sys.argv 命令行参数List,第一个元素是程序本身路径 2.sys.exit(n) 退出程序,正常退出时exit(0) 3.sys.version 获取Pythonn解释程 ...

  7. BZOJ4818 [SDOI2017] 序列计数 【矩阵快速幂】

    题目分析: 一个很显然的同类项合并.注意到p的大小最大为100,考虑把模p意义下相同的求出来最后所有的减去没有质数的做矩阵快速幂即可. 代码: #include<bits/stdc++.h> ...

  8. C Looooops POJ - 2115 (exgcd)

    一个编译器之谜:我们被给了一段C++语言风格的循环 for(int i=A;i!=B;i+=C) 内容; 其中所有数都是k位二进制数,即所有数时膜2^k意义下的.我们的目标时球出 内容 被执行了多少次 ...

  9. 【XSY2166】Hope 分治 FFT

    题目描述 对于一个\(1\)到\(n\)的排列\(a_1,a_2,a_3,\ldots,a_n\),我们定义这个排列的\(P\)值和\(Q\)值: 对于每个\(a_i\),如果存在一个最小的\(j\) ...

  10. 【hdu 5628】Clarke and math (Dirichlet卷积)

    hdu 5628 Clarke and math 题意 Given f(i),1≤i≤n, calculate \(\displaystyle g(i) = \sum_{i_1 \mid i} \su ...