题目链接:https://abc091.contest.atcoder.jp/tasks/arc092_a

题意

On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (ai,bi), and the coordinates of the i-th blue point are (ci,di).

A red point and a blue point can form a friendly pair when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.

At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.

思路

简单模拟

注意顺序,考虑下面的数据

2

1 2

3 1

2 4

4 3

代码

    #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=200;
struct Point{
int x, y;
Point(int x=0, int y=0):x(x), y(y) {}
bool operator < (const Point &a) const{
return y<a.y;
}
}point[maxn+5];
int n;
bool map[maxn+5][maxn+5]; int main(void){
scanf("%d", &n);
for (int i=0, a, b; i<n; i++){
scanf("%d%d", &a, &b);
map[b][a]=true;
} int cnt=0;
for (int i=0, a, b; i<n; i++){
scanf("%d%d", &a, &b);
point[i]=Point(a, b);
}sort(point, point+n);
for (int i=0; i<n; i++){
int a=point[i].x, b=point[i].y;
bool ifbreak=false;
for (int x=a-1; x>=0; x--){
for (int y=b-1; y>=0; y--)
if (map[y][x]) {cnt++; map[y][x]=false; ifbreak=true; break;}
if (ifbreak) break;
}
}printf("%d\n", cnt); return 0;
}
Time Memory Length Lang Submitted
1 ms 256KB 937 Byte C++14 (GCC 5.4.1) 2018/03/17 21:21:32

AtCoderBeginner091-C 2D Plane 2N Points 模拟问题的更多相关文章

  1. 【AtCoder Regular Contest 092】C.2D Plane 2N Points【匈牙利算法】

    C.2D Plane 2N Points 题意:给定N个红点二维坐标N个蓝点二维坐标,如果红点横纵坐标都比蓝点小,那么它们能够构成一组.问最多能构成多少组. 题解:把满足要求的红蓝点连线,然后就是匈牙 ...

  2. AtCoder Regular Contest 092 C - 2D Plane 2N Points(二分图匹配)

    Problem Statement On a two-dimensional plane, there are N red points and N blue points. The coordina ...

  3. AtCoder Regular Contest 092 2D Plane 2N Points AtCoder - 3942 (匈牙利算法)

    Problem Statement On a two-dimensional plane, there are N red points and N blue points. The coordina ...

  4. arc 092C 2D Plane 2N Points

    题意: 有n个红色的点和n个蓝色的点,如果红色的点的横坐标和纵坐标分别比蓝色的点的横坐标和纵坐标小,那么这两个点就可以成为一对友好的点. 问最多可以形成多少对友好的点. 思路: 裸的二分图匹配,对于满 ...

  5. Microsoft - Find the K closest points to the origin in a 2D plane

    Find the K closest points to the origin in a 2D plane, given an array containing N points. 用 max hea ...

  6. [LeetCode OJ] Max Points on a Line—Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.

    //定义二维平面上的点struct Point { int x; int y; Point(, ):x(a),y(b){} }; bool operator==(const Point& le ...

  7. 2D图形如何运动模拟出3D效果

    一.先看看实现效果图 (左边的2d图片如何运动出右边3d的效果)                                      引言: 对于这个题目,真的很尴尬,不知道取啥,就想了这个题目 ...

  8. Codeforces 909 D. Colorful Points (模拟)

    题目链接: Colorful Points 题意: 给出一段字符串(长度最大为1e6),每次操作可以删除字符串中所有相邻字符与其不同的字符.例如:aabcaa 删除一次就变成了aa,就无法再删除了.题 ...

  9. 【AtCoder】ARC092

    C - 2D Plane 2N Points 把能连边的点找到然后跑二分图匹配即可 #include <bits/stdc++.h> #define fi first #define se ...

随机推荐

  1. [JZOJ 5893] [NOIP2018模拟10.4] 括号序列 解题报告 (Hash+栈+map)

    题目链接: https://jzoj.net/senior/#main/show/5893 题目: 题解: 考虑暴力怎么做,我们枚举左端点,维护一个栈,依次加入元素,与栈顶元素和栈内第二个元素相同时弹 ...

  2. [JZOJ NOIP2018模拟10.19]

    T1写炸了今天,期望70却落了个20...连链上的都没有写对 T3什么什么线段树分治套AC自动机,表示我完全自闭了,幸好考场上没有杠T3 总体比赛还是比较舒服,暴力分给的蛮足的,不像昨天那样 T1:林 ...

  3. validform

    一.validform是什么?            validform是一款智能的表单验证js插件,它是基于jQuery库与css,我们只需要把表单对象放入,             就可以对整个表 ...

  4. Android setImageResource与setImageBitmap的区别

    同样的布局文件,小分辨率手机: 1.使用setImageBitmap设置时,出现如下现象: 2.使用setImageResource时,图片显示正常 原因:setImageResource(id)会根 ...

  5. Epplus做Excel的数据透视

    //表格的范围需要自己定义 var epplus = new ExcelPackage(); var sheet = epplus.Workbook.Worksheets.Add("Shee ...

  6. git pull 失败 ,提示:fatal: refusing to merge unrelated histories

    首次 git pull 时失败,并提示:fatal: refusing to merge unrelated histories 在使用git pull 命令时,添加一个可选项 git pull or ...

  7. 关于目标检测 Object detection

    NO1.目标检测 (分类+定位) 目标检测(Object Detection)是图像分类的延伸,除了分类任务,还要给定多个检测目标的坐标位置.      NO2.目标检测的发展 R-CNN是最早基于C ...

  8. n行m列矩阵顺时针填写1~n*m

    程序效果图如下: 程序参考代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 ...

  9. CF939F Cutlet (单调队列优化DP)

    题目大意:要煎一块有两个面的肉,只能在一段k不相交的时间段$[l_{i},r_{i}]$内翻转,求$2*n$秒后,保证两个面煎的时间一样长时,需要最少的翻转次数,$n<=100000$,$k&l ...

  10. 使用vue实现简单键盘,支持移动端和pc端

    常看到各种app应用中使用自定义的键盘,本例子中使用vue2实现个简单的键盘,支持在移动端和PC端使用,欢迎点赞,h5 ios输入框与键盘 兼容性优化 实现效果: Keyboard.vue <t ...