AtCoderBeginner091-C 2D Plane 2N Points 模拟问题
题目链接: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 模拟问题的更多相关文章
- 【AtCoder Regular Contest 092】C.2D Plane 2N Points【匈牙利算法】
C.2D Plane 2N Points 题意:给定N个红点二维坐标N个蓝点二维坐标,如果红点横纵坐标都比蓝点小,那么它们能够构成一组.问最多能构成多少组. 题解:把满足要求的红蓝点连线,然后就是匈牙 ...
- 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 ...
- 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 ...
- arc 092C 2D Plane 2N Points
题意: 有n个红色的点和n个蓝色的点,如果红色的点的横坐标和纵坐标分别比蓝色的点的横坐标和纵坐标小,那么这两个点就可以成为一对友好的点. 问最多可以形成多少对友好的点. 思路: 裸的二分图匹配,对于满 ...
- 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 ...
- [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 ...
- 2D图形如何运动模拟出3D效果
一.先看看实现效果图 (左边的2d图片如何运动出右边3d的效果) 引言: 对于这个题目,真的很尴尬,不知道取啥,就想了这个题目 ...
- Codeforces 909 D. Colorful Points (模拟)
题目链接: Colorful Points 题意: 给出一段字符串(长度最大为1e6),每次操作可以删除字符串中所有相邻字符与其不同的字符.例如:aabcaa 删除一次就变成了aa,就无法再删除了.题 ...
- 【AtCoder】ARC092
C - 2D Plane 2N Points 把能连边的点找到然后跑二分图匹配即可 #include <bits/stdc++.h> #define fi first #define se ...
随机推荐
- Excel中将字符串中从右起第n个指定字符替换的方法
比如你想把www.baidu.com.cn中的倒数第二个”.”替换成@,则可以用: =SUBSTITUTE(A1,".","@",LEN(A1)-LEN(SUB ...
- VisualStudio UnitTest FrameWork
当创建单元测试时,Microsoft.VisualStudio.TestTools.UnitTesting的名字控件会添加到测试项目中,该名字控件中包含很多有用的类: 断言类:在单元测试中验证条件 初 ...
- FPGA初学之前后仿真分析
最近在学习FPGA,感觉语言的学习到时很容易,但是由于缺乏电路图的硬件知识,所以看起来比较难懂,下面是对FPGA中仿真的一点理解,以后需要学习的地方还有很多啊. 一.使用ISE环境进行FPGA系统设计 ...
- APICloud关闭Key Building Resolve
顶部菜单 --> 扩展 --> keybinding resolver --> toggle
- hiho1116 - 数据结构 线段树(区间合并)
题目链接 现在有一个有n个元素的数组a1, a2, ..., an. 记f(i, j) = ai * ai+1 * ... * aj. 初始时,a1 = a2 = ... = an = 0,每次我会修 ...
- Activiti BPMN 2.0 designer eclipse插件安装
官方网是这样说的: https://www.activiti.org/userguide/index.html#springSpringBoot The following installation ...
- SpringBoot学习笔记(1)----环境搭建与Hello World
简介: Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配 ...
- FCC高级编程篇之Make a Person
Make a Person Fill in the object constructor with the following methods below: getfirstname() getLas ...
- SKU和SPU表的设计
1.什么是SKU,SPU SKU:Stock Keeping Unit (库存量单位)SKU即库存进出计量的单位,可以是以件.盒.托盘等为单位,是物理上不可分割的最小存货单元.在使用时要根据不同业态, ...
- [SHOI2012]魔法树
题目:洛谷P3833. 题目大意:给你一棵树,有两种操作:1.给两个点和它们之间的最短路上的所有点加上一个值:2.询问以某个点为根的子树的子树和.你需要实现这个功能. 解题思路:如果只有最后才询问的话 ...