题目链接: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. sicily 1146 采药 (动规)

    打代码不走心会掉坑里的.. 下边是代码: //1146.采药 //t表示总时间 //m表示草药数 //w表示采药时间 //v表示草药价值 #include <iostream> using ...

  2. ApacheFlink简介

    对无界数据集的连续处理 在我们详细介绍Flink之前,让我们从更高的层面上回顾处理数据时可能遇到的数据集的类型以及您可以选择处理的执行模型的类型.这两个想法经常被混淆,清楚地区分它们是有用的. 首先, ...

  3. APP信息获取接口

    https://itunes.apple.com/lookup?id=APPID&callback=2 http://myapp.com/cgi-bin/mapp/mapp_info?type ...

  4. 洛谷 P1983 车站分级 拓扑排序

    Code: #include<cstdio> #include<queue> #include<algorithm> #include<cstring> ...

  5. 原生的ajax请求----(播放托管到爱奇艺上的视频)

    播放视频 $(function(){ //视频播放 $('.play-icon').click(function () { $.ajax({ type:"get", url: &q ...

  6. continue和break

    <script type="text/javascript"> var i=1; computer: while(true){ i++; switch(i){ case ...

  7. Centos 7 修改 ssh 端口

    1.修改 ssh 配置 vi /etc/ssh/ssh_config vi /etc/ssh/sshd_config ///以上这2个文件,都去掉#port22前"#",将22改为 ...

  8. NodeJS学习笔记 (5)网络服务-http-req(ok)

    原文:https://github.com/chyingp/nodejs-learning-guide 自己敲代码: 概览 本文的重点会放在req这个对象上.前面已经提到,它其实是http.Incom ...

  9. 紫书 例题11-11 UVa 12661 (dihkstra变形)

    这道题主要比较权值的时候要改变一下,其他地方基本一样. 比较权值的时候要考虑边的时间与a, b 可以设相对于当前边的时间now, 则now = d[u] % (a+b), 也就是当前这个边进行到整个a ...

  10. 2019年北航OO第二单元(多线程电梯任务)总结

    一.三次作业总结 1. 说在前面 对于这次的这三次电梯作业,我采用了和几乎所有人都不同的架构:将每个人当作一个线程.这样做有一定的好处:它使得整个问题的建模更加自然,并且在后期人员调度变得复杂时,可以 ...