2015 USP-ICMC gym 100733 J. Summer Wars

J. Summer Wars
time limit per test
2.0 s
memory limit per test
64 MB
input
standard input
output
standard output

The mafia is finally resting after a year of hard work and not so much money. Mafianca, the little mascot of the gang wanted to go to the beach.

Little did they know that the rival gang had prepared a trap to the little girl and her rubber duck. They know that Mafianca, despite loving the beach, hates water. So they set up some water sprayers to ruin her day. The beach can be seen as a plane. The sprayers are located at different (x, y) points along the shore. Each sprayer is so strong that it creates an infinite line of water, reaching every point with x-coordinate equal to the sprayer.

Mafianca's bodyguards figured this plan out. They didn't have the time to destroy the sprayers, so they decided to do something else. Lying around on the beach was a piece of modern art: a bunch of walls, represented by horizontal line segments, painted by some futuristic anonymous artist. Those walls can be moved, but they can only be moved together and horizontally.

The bodyguards decided that they would try to move this piece of art in order to block the most sprayers they can. A sprayer is blocked if there's at least one wall in both of its sides.

How many sprayers can they block?

Input

Input begins with the number of sprayers, n (1 ≤ n ≤ 1000) and the number of walls in the modern art, m (1 ≤ m ≤ 1000).

Follows n lines, each with two intergers, y and x (0 ≤ y, x ≤ 106), indicating that there's a sprayer at position x, y.

Then follows m lines, each with three integers: yxbegin and xend (0 ≤ y ≤ 106) and (0 ≤ xbegin < xend ≤ 106) denoting a wall in the modern art has y-coordinate y, begins at xbegin and ends at xend. No wall will have a y-coordinate shared with a sprayer and the walls with same ywill not intersect.

Output

Print the number of sprayers that can be blocked.

Examples
input
Copy
1 1
2 2
3 1 3
output
Copy
0
input
Copy
2 5
2 3
2 6
1 0 2
4 0 4
0 2 3
1 4 5
3 5 7
output
Copy
2
input
Copy
4 5
2 3
2 8
2 20
5 1
1 0 2
4 0 4
0 2 3
1 4 5
3 5 7
output
Copy
2
input
Copy
3 4
2 0
2 4
4 7
1 0 2
3 1 3
5 0 2
5 3 4
output
Copy
2
Note

In the test case #4, the beach looks like this:

A solution would be

思路:枚举所有的移动长度的话,每个星星对整体的贡献都是多段区间。因为只有最终一次查询,我们建立一个差分数组。
将线段按x排序后,类似差分方法,左端点在set里入y,右端点出y,对于每个星星,只需判断集合中的y和星星的y之间的关系。
然后用星星的x计算出相对位移O(m)更新差分数组。最后求差分数组前缀和最大值。复杂度O(nmlog(m) + D)。
  1 #include <iostream>
  2 #include <fstream>
  3 #include <sstream>
  4 #include <cstdlib>
  5 #include <cstdio>
  6 #include <cmath>
  7 #include <string>
  8 #include <cstring>
  9 #include <algorithm>
 10 #include <queue>
 11 #include <stack>
 12 #include <vector>
 13 #include <set>
 14 #include <map>
 15 #include <list>
 16 #include <iomanip>
 17 #include <cctype>
 18 #include <cassert>
 19 #include <bitset>
 20 #include <ctime>
 21 
 22 using namespace std;
 23 
 24 #define pau system("pause")
 25 #define ll long long
 26 #define pii pair<int, int>
 27 #define pb push_back
 28 #define mp make_pair
 29 #define clr(a, x) memset(a, x, sizeof(a))
 30 
 31 const double pi = acos(-1.0);
 32 const int INF = 0x3f3f3f3f;
 33 const int MOD = 1e9 + 7;
 34 const double EPS = 1e-9;
 35 const int D = 1e6;
 36 
 37 /*
 38 #include <ext/pb_ds/assoc_container.hpp>
 39 #include <ext/pb_ds/tree_policy.hpp>
 40 
 41 using namespace __gnu_pbds;
 42 tree<pli, null_type, greater<pli>, rb_tree_tag, tree_order_statistics_node_update> T;
 43 */
 44 
 45 int n, m;
 46 struct point {
 47     int x, y;
 48     point () {}
 49     point (int x, int y) : x(x), y(y) {}
 50     bool operator < (const point &p) const {
 51         return x < p.x;
 52     }
 53 } P[1015];
 54 int cnt[2000015], con[2015], tcnt[2015];
 55 map<int, int> mmp;
 56 set<int> ss;
 57 pii p[2015];
 58 int main() {
 59     scanf("%d%d", &n, &m);
 60     for (int i = 1; i <= n; ++i) {
 61         scanf("%d%d", &P[i].y, &P[i].x);
 62     }
 63     for (int i = 1; i <= m; ++i) {
 64         int y, xs, xe;
 65         scanf("%d%d%d", &y, &xs, &xe);
 66         p[i * 2 - 1] = pii(xs, y);
 67         p[i * 2] = pii(xe + 1, y - 2 * D);
 68         mmp[xs]; mmp[xe + 1];
 69     }
 70     int cnt_index = 0;
 71     for (map<int, int>::iterator it = mmp.begin(); it != mmp.end(); ++it) {
 72         it -> second = ++cnt_index;
 73         con[cnt_index] = it -> first;
 74     }
 75     sort(p + 1, p + 2 * m + 1);
 76     for (int i = 1; i <= n; ++i) {
 77         ss.clear();
 78         clr(tcnt, 0);
 79         for (int j = 1; j <= 2 * m; ) {
 80             int k = j;
 81             while (k <= 2 * m && p[k].first == p[j].first) {
 82                 if (p[k].second < 0) ss.erase(p[k].second + 2 * D);
 83                 else ss.insert(p[k].second);
 84                 ++k;
 85             }
 86             if (ss.lower_bound(P[i].y) != ss.begin() && ss.lower_bound(P[i].y) != ss.end()) {
 87                 tcnt[mmp[p[j].first]] = 1;
 88             } else {
 89                 tcnt[mmp[p[j].first]] = 0;
 90             }
 91             j = k;
 92         }
 93         for (int j = 1; j < cnt_index; ++j) {
 94             if (tcnt[j]) {
 95                 ++cnt[D + con[j] - P[i].x];
 96                 --cnt[D + con[j + 1] - P[i].x];
 97             }
 98         }
 99     }
100     int ans = cnt[0];
101     for (int i = 1; i <= 2 * D; ++i) {
102         cnt[i] += cnt[i - 1];
103         ans = max(ans, cnt[i]);
104     }
105     printf("%d\n", ans);
106     return 0;
107 }
View Code

 

转载于:https://www.cnblogs.com/BIGTOM/p/9261297.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: emd-icm42670-p_examples-2.1.2.pdf.rar 是一个压缩文件,其中包含了 ICM-42670-P 芯片的示例代码及文档。ICM-42670-P 是一款低功耗、高性能的惯性测量单元(IMU)传感器,可以用于测量物体的加速度、角速度和方向等参数。这个压缩文件包含了 ICM-42670-P 传感器的使用说明、接口定义、寄存器设置及示例代码。 ICM-42670-P 示例代码可以帮助开发者快速理解和使用该芯片。示例代码中提供了一些常见的功能示例,如初始化传感器、获取传感器数据、配置传感器的采样率和滤波器等。开发者可以根据自己的需求进行修改和扩展,以满足特定的应用场景。 除了示例代码,压缩文件中还包含了 ICM-42670-P 芯片的详细技术文档,比如数据手册和寄存器映射表。这些文档可以帮助开发者深入了解芯片的功能、性能和使用方法。通过阅读这些文档,开发者可以更好地理解芯片的工作原理,优化代码的实现,并解决可能出现的问题。 总之,emd-icm42670-p_examples-2.1.2.pdf.rar 包含了 ICM-42670-P 芯片的示例代码和技术文档,为开发者提供了使用该芯片的相关信息和参考实现。开发者可以通过阅读文档和使用示例代码,快速上手并应用该芯片于各种应用场景中。 ### 回答2: emd-icm42670-p_examples-2.1.2.pdf.rar是一个压缩文件,其中包含了ICM42670传感器的示例代码。ICM42670是一款高性能的惯性测量单元(IMU),可用于测量和监测物体的加速度和角速度。 该压缩文件中的示例代码可以帮助开发人员更好地理解和使用ICM42670传感器。代码中包含了各种功能的示例,比如初始化传感器、读取加速度和角速度数据、设置传感器的工作模式等。 这些示例代码使用了特定的编程语言和开发环境,通常会包含详细的说明和注释,以便开发人员能够轻松地理解和修改代码。同时,开发人员还可以根据自己的需求,将这些示例代码作为基础,进行进一步的开发和定制。 通过使用ICM42670传感器示例代码,开发人员可以快速构建和开发基于该传感器的应用程序,如运动跟踪、姿态检测、导航系统等。此外,示例中的代码还可以用于教育和学习目的,帮助初学者更好地理解和掌握传感器的工作原理和使用方法。 总之,emd-icm42670-p_examples-2.1.2.pdf.rar提供了ICM42670传感器的示例代码,为开发人员提供了一个方便的资源,帮助他们更好地利用和应用这个高性能的惯性测量单元。 ### 回答3: emd-icm42670-p_examples-2.1.2.pdf.rar 是一个压缩文件,主要用于存储和传输PDF格式的示例文件。该文件名包含以下信息: emd-:表示此文件与电子机械制动系统( Electronic Mechanical Braking System)相关。这可能是一个示例文件,用于展示电子机械制动系统的使用方法或演示其功能。 icm42670-:表示此文件与ICM42670有关。ICM42670是一种集成了三轴陀螺仪和三轴加速度计功能的传感器芯片。该文件可能包含有关如何使用ICM42670芯片的示例代码或应用程序。 p_examples-:表示此文件是一个示例文件集合(Examples)。这些示例文件可能包含不同的代码示例,演示了如何在特定平台上使用ICM42670芯片。 2.1.2:表示此文件的版本号为2.1.2。这可能意味着这是某个软件或平台的特定版本,其中包含了特定版本ICM42670芯片的示例文件。 .pdf:表示该文件是一个PDF格式的文件,这是一种广泛使用的文件格式,可用于显示文本和图像的电子文档。 .rar:表示该文件是一种压缩文件,采用了RAR格式进行压缩。RAR是一种常见的压缩文件格式,可用于减小文件的大小,便于存储和传输。 因此,emd-icm42670-p_examples-2.1.2.pdf.rar 可能是一个包含了ICM42670芯片使用示例的PDF文件集合,并使用RAR格式进行了压缩。要查看其中的内容,需要使用支持RAR格式的解压缩工具将其解压缩,并使用PDF阅读器打开PDF文件。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值