题目链接: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. ServiceStack.Redis之IRedisClient<第三篇>【转】

    事实上,IRedisClient里面的很多方法,其实就是Redis的命令名.只要对Redis的命令熟悉一点就能够非常快速地理解和掌握这些方法,趁着现在对Redis不是特别了解,我也对着命令来了解一下这 ...

  2. POJ 2114 点分治

    思路: 点分治 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> u ...

  3. Pcap 数据报解析

    最近看了一下网络的书,信息系统也有实验任务,所以就学习了一下pcap包的解析. 主要是对内部以太网帧头,ip头部,tcp头部或者udp头部的解析.我因为用访问google.cn作为的样例,没有udp包 ...

  4. 07:清泉-改(prime+堆)

    时间限制:  10000ms 单个测试点时间限制:  1000ms 内存限制:  512000kB 描述 华北电力大学可以抽象为一张有n个点m条边的无向图. 现在所有的边都断了. 修复每条边都有个不同 ...

  5. (转载)JS与WebView交互存在的一些问题

    JS与WebView交互存在的一些问题 作者 隔壁的李小宝 关注 2015.06.09 19:30 字数 2896 阅读 11117评论 3喜欢 35 一.背景概述 2013年Android平台暴露出 ...

  6. Android学习——LinearLayout布局实现居中、左对齐、右对齐

    android:orientation="vertical"表示该布局下的元素垂直排列: 在整体垂直排列的基础上想要实现内部水平排列,则在整体LinearLayout布局下再创建一 ...

  7. solarwinds之数据库

      1.              Orion配置向导     2.              连接数据库     3.              创建一个新的数据库     4.           ...

  8. uva 11584 - 字符串 dp

    题目链接 一个长度1000的字符串最少划分为几个回文字符串 ---------------------------------------------------------------------- ...

  9. php时间差方法

    /** * 时间差计算 * * @param Timestamp $time * @return String Time Elapsed */ function time2Units ($time,$ ...

  10. for 的相关用法

    forEach() <!DOCTYPE html> <html> <head> <meta charset="utf-8"> < ...