【贪心】CodeChef PROTEPOI Protecting The Poison
来源:互联网 发布:年薪百万的职业知乎 编辑:程序博客网 时间:2024/06/14 09:23
题面在这里
其实很显然,
把所有蛇都投影到垂直的两个方向
对两个方向分别进行扫描线就可以了
示例程序:
#include<cstdio>#include<algorithm>using namespace std;const int maxn=100005,INF=0x3f3f3f3f;int tst,n,k,m,L,R,hx[maxn],hy[maxn],tx[maxn],ty[maxn],ans=0;struct data{ int s,t; bool operator<(const data&b)const{ return s<b.s; }}a[maxn];void work(){ int lst=L; for (int i=1;i<=n&&lst<=R;){ if (lst<a[i].s) {ans-=INF;return;} int far=-1; while (i<=n&&a[i].s<=lst) far=max(far,a[i++].t); lst=far+1;ans++; } if (lst<=R) ans-=INF;}int main(){ scanf("%d",&tst); while (tst--){ scanf("%d%d%d",&n,&k,&m); L=(n-k)/2+1;R=L+k-1; for (int i=1;i<=m;i++){ scanf("%d%d%d%d",&hx[i],&hy[i],&tx[i],&ty[i]); if (hx[i]==tx[i]){ if (hy[i]>ty[i]) swap(hy[i],ty[i]); a[i].s=hy[i];a[i].t=ty[i]; }else a[i].s=a[i].t=hy[i]; } sort(a+1,a+1+m); ans=0;work(); for (int i=1;i<=m;i++) if (hy[i]==ty[i]){ if (hx[i]>tx[i]) swap(hx[i],tx[i]); a[i].s=hx[i];a[i].t=tx[i]; }else a[i].s=a[i].t=hx[i]; sort(a+1,a+1+m); work(); printf("%d\n",ans<0?-1:ans); } return 0;}
阅读全文
2 0
- 【贪心】CodeChef(PROTEPOI)[Protecting The Poison]题解
- 【贪心】CodeChef PROTEPOI Protecting The Poison
- CodeChef PROTEPOI Protecting The Poison
- CodeChef Protecting The Poison【贪心】
- CodeChef Protecting The Poison(贪心)
- Protecting the Flowers (贪心)
- poj3262 Protecting the Flowers(贪心)
- POJ3262 Protecting the Flowers 【贪心】
- POJ3262 Protecting the Flowers(贪心)
- [贪心] poj3262 Protecting the Flowers
- 【POJ3262】Protecting the Flowers【贪心】
- POJ3262 Protecting the Flowers (贪心)
- POJ 3262 Protecting the Flowers 贪心
- poj 3262 Protecting the Flowers (贪心)
- poj3262 Protecting the Flowers --- 简单贪心
- poj 3262 Protecting the Flowers(贪心)
- poj 3262 Protecting the Flowers 【贪心】
- poj 3262 Protecting the Flowers(贪心)
- codeforces 330A Cakeminator
- 如何实现一个楼中楼的评论系统
- Q142:PBRT-V3,交点处各种微分的求解(三角形,3.6章节)
- git tig教程
- IntelliJ IDEA 2017.2 注册方法(附Mac破解方法)
- 【贪心】CodeChef PROTEPOI Protecting The Poison
- Markdown编辑分段函数
- 18章 认识系统服务(daemons)
- 分布式锁原理及实现方式
- 混合树实现三种动画融合
- 暗黑的字符串---递推公式
- 地理商业智能发展浅析
- 一个基本的工作场景
- 队、栈实现纸牌游戏—C—python