2020牛客寒假算法基础集训营4-I 匹配星星【贪心】
2024-10-08 09:37:27
链接:https://ac.nowcoder.com/acm/contest/3005/I
来源:牛客网
备注:
思路:
#include <bits/stdc++.h>
#define dbg(x) cout << #x << "=" << x << endl using namespace std;
typedef long long LL; template<class T>inline void read(T &res)
{
char c;T flag=;
while((c=getchar())<''||c>'')if(c=='-')flag=-;res=c-'';
while((c=getchar())>=''&&c<='')res=res*+c-'';res*=flag;
} namespace _buff {
const size_t BUFF = << ;
char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
char getc() {
if (ib == ie) {
ib = ibuf;
ie = ibuf + fread(ibuf, , BUFF, stdin);
}
return ib == ie ? - : *ib++;
}
} int qread() {
using namespace _buff;
int ret = ;
bool pos = true;
char c = getc();
for (; (c < '' || c > '') && c != '-'; c = getc()) {
assert(~c);
}
if (c == '-') {
pos = false;
c = getc();
}
for (; c >= '' && c <= ''; c = getc()) {
ret = (ret << ) + (ret << ) + (c ^ );
}
return pos ? ret : -ret;
} const int maxn = 1e5 + ; set <int> s;
map<int, int> mapp; int n; struct node {
int x,y,z;
}a[maxn]; bool cmp(node a, node b) {
if(a.x == b.x) {
return a.z > b.z;
}
return a.x < b.x;
} int main()
{
read(n);
for(int i = ; i <= n; ++i) {
scanf("%d %d %d",&a[i].x, &a[i].y, &a[i].z);
}
sort(a+, a+n+, cmp);
set<int>::iterator it; LL ans = ;
for(int i = ; i <= n; ++i) {
if(a[i].z == ) {
if(!mapp[a[i].y]) {
s.insert(a[i].y);
}
mapp[a[i].y]++;
}
if(a[i].z == ) {
it = s.lower_bound(a[i].y);
if(it != s.begin()) {
mapp[*it]--;
if(!mapp[*it]) {
s.erase(*it);
}
dbg(*it);
ans++;
}
}
}
cout << ans << endl;
return ;
}
/*
5
1 1 0
2 2 0
3 3 0
4 4 0
5 5 1
*/
最新文章
- ionic cordova 热更新(引用自www.zyyapp.com/post/116.html)
- hihocoder 1066 无间道之并查集
- play app to war
- Android客户端调用Asp.net的WebService
- MFC修改任务栏图标及程序运行exe图标
- twitter 监控登陆活动
- Hibernate 总结一
- 戏说云计算之PaaS,IaaS,SaaS【转载】
- 浅谈Android五大布局
- JAVA课设---五子棋
- python + selenium 自动化测试框架
- Java 与C++的各种优势与弱点--学习更新中
- leaflet渲染mapbox gl的矢量数据
- New UWP Community Toolkit - DropShadowPanel
- return_fun.go 源码阅读
- js获取浏览器窗体最大化事件
- ERROR 1045 (28000): Access denied for user &#39;mysql&#39;@&#39;localhost&#39; (using password: YES
- Python 之 __new__() 方法与实例化(转)
- python日志和异常
- 2-5 re模块练习题
热门文章
- SpringBoot、Spring MVC报错:Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
- 什么是JWT以及具体应用
- 《python可以这样学》第二章
- C语言程序转汇编代码
- win10上使用linux命令
- 通过LD_PRELOAD绕过disable_functions
- SAP MM 一个含有多个账号分配对象的行项目的PO及其收货
- .Net框架的模块代码生成器--其三(dotnet tool指令的参数)
- 返回一个整数数组中最大子数组的和——java程序设计
- pgspider gzip fdw试用(集成gzip+http+graphql-engine)