https://vjudge.net/problem/ZOJ-1375

In modern day magic shows, passing through walls is very popular in which a magician performer passes through several walls in a predesigned stage show. The wall-passer (Pass-Muraille) has a limited wall-passing energy to pass through at most k walls in each wall-passing show. The walls are placed on a grid-like area. An example is shown in Figure 1, where the land is viewed from above. All the walls have unit widths, but different lengths. You may assume that no grid cell belongs to two or more walls. A spectator chooses a column of the grid. Our wall-passer starts from the upper side of the grid and walks along the entire column, passing through every wall in his way to get to the lower side of the grid. If he faces more than k walls when he tries to walk along a column, he would fail presenting a good show. For example, in the wall configuration shown in Figure 1, a wall-passer with k = 3 can pass from the upper side to the lower side choosing any column except column 6.


Figure 1. Shaded cells represent the walls.

Given a wall-passer with a given energy and a show stage, we
want to remove the minimum number of walls from the stage so that our
performer can pass through all the walls at any column chosen by
spectators.

Input

The first line of the input file
contains a single integer t (1 <= t <= 10), the number of test
cases, followed by the input data for each test case. The first line of
each test case contains two integers n (1 <= n <= 100), the number
of walls, and k (0 <= k <= 100), the maximum number of walls that
the wall-passer can pass through, respectively. After the first line,
there are n lines each containing two (x, y) pairs representing
coordinates of the two endpoints of a wall. Coordinates are non-negative
integers less than or equal to 100. The upper-left of the grid is
assumed to have coordinates (0, 0). The second sample test case below
corresponds to the land given in Figure 1.

Output

There should be one line per test
case containing an integer number which is the minimum number of walls
to be removed such that the wall-passer can pass through walls starting
from any column on the upper side.

Sample Input

2
3 1
2 0 4 0
0 1 1 1
1 2 2 2
7 3
0 0 3 0
6 1 8 1
2 3 6 3
4 4 6 4
0 5 1 5
5 6 7 6
1 7 3 7

Sample Output

1
1

一开始我贪心是优先选择覆盖目标列最多的墙进行拆除然后统计总个数,然后一直WA意识到贪心方案不对,正解是从0-最后一列遍历发现不满足的列之后优先选择一个之前未选择过得且包含这一列且往右延伸的距离尽可能大的那个进行拆除就AC。

 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define LL long long
int num[];
struct node{int l,r;}P[];
bool vis[];
int main()
{
int T,N,M,K,i,j,k;
cin>>T;
while(T--){
int a,b,c,d;
cin>>N>>K;
memset(num,,sizeof(num));
memset(vis,,sizeof(vis));
for(i=;i<=N;++i)
{
scanf("%d%d%d%d",&a,&b,&c,&d);
if(a>c) swap(a,c);
P[i].l=a;
P[i].r=c;
for(j=a;j<=c;++j)
num[j]++;
}
int ans=;
for(i=;i<=;++i)
{ while(num[i]>K){
int u=-,w=-;
for(j=;j<=N;++j)
{
if(!vis[j]&&i>=P[j].l&&i<=P[j].r&&w<P[j].r){
w=P[j].r;
u=j;
}
}
vis[u]=;
for(j=P[u].l;j<=P[u].r;++j)
num[j]--;
ans++;
}
}
printf("%d\n",ans);
}
return ;
}

zoj 1375 贪心的更多相关文章

  1. Heap Partition ZOJ - 3963(贪心)

    ZOJ - 3963 贪心做一下就好了 反正别用memset #include <iostream> #include <cstdio> #include <sstrea ...

  2. zoj 1375||poj 1230(贪心)

    Pass-Muraille Time Limit: 2 Seconds      Memory Limit: 65536 KB In modern day magic shows, passing t ...

  3. ZOJ - 3715贪心

    ZOJ - 3715KindergartenElection 题目大意:幼儿园里正在举办班长选举,除1号小朋友外每个人都会投他最好的朋友,但1号小朋友可以贿赂别人(小伙子有丶想法),被贿赂的小朋友就会 ...

  4. ZOJ 38727(贪心)

    这道题真心坑.越想越远  想的飞起来了. 最后纠结起后缀表达式的定义来了. 题意: 就是给你一个串 ,  让你用最少改动次数来实它变成一个合法的后缀表达式,  改动方式有两种, 一种是直接加入数字或者 ...

  5. ZOJ 3607贪心算法

    http://blog.csdn.net/ffq5050139/article/details/7832991 http://blog.watashi.ws/1944/the-8th-zjpcpc/ ...

  6. ZOJ 3829 贪心 思维题

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...

  7. ZOJ Problem Set - 3829Known Notation(贪心)

    ZOJ Problem Set - 3829Known Notation(贪心) 题目链接 题目大意:给你一个后缀表达式(仅仅有数字和符号),可是这个后缀表达式的空格不幸丢失,如今给你一个这种后缀表达 ...

  8. 贪心+模拟 ZOJ 3829 Known Notation

    题目传送门 /* 题意:一串字符串,问要最少操作数使得成为合法的后缀表达式 贪心+模拟:数字个数 >= *个数+1 所以若数字少了先补上在前面,然后把不合法的*和最后的数字交换,记录次数 岛娘的 ...

  9. 【贪心+一点小思路】Zoj - 3829 Known Notation

    借用别人一句话,还以为是个高贵的dp... ... 一打眼一看是波兰式的题,有点懵还以为要用后缀表达式或者dp以下什么什么的,比赛后半阶段才开始仔细研究这题发现贪心就能搞,奈何读错题了!!交换的时候可 ...

随机推荐

  1. MySQL中lock与latch的区分

    这里要区分锁中容易令人混淆的概念lock与latch.在数据库中,lock与latch都可以成为锁,但两者有截然不同的含义 latch 一般称为闩锁(轻量级的锁) 因为其要求锁定的时间非常短,若迟勋时 ...

  2. 我的Android进阶之旅------>RGB颜色查询对照表

    因为兼容性问题,色阶板功能只能在IE浏览器中运行 RGB颜色对照表   #FFFFFF   #FFFFF0   #FFFFE0   #FFFF00   #FFFAFA   #FFFAF0   #FFF ...

  3. DOM 属性操作

    1 属性节点 2 attribute操作 3 value获取值操作 4 class的操作 5 指定CSS操作 1.属性节点 //获取文本节点的值 var divEle = document.getEl ...

  4. 爬虫,如何防止被ban之策略大集合

    话说在尝试设置download_delay小于1,并且无任何其他防止被ban的策略之后,我终于成功的被ban了. 关于scrapy的使用可参见之前文章: http://blog.csdn.net/u0 ...

  5. F110 参数保存和重新运行录屏

    **初始界面回车 PERFORM frm_dynpro USING ' 'X'. PERFORM frm_dynpro USING '' 'BDC_CURSOR' 'F110V-LAUFD'. PER ...

  6. 002 MIRO发票校验采购订单项目科目分配类别检查增强-20150819

    BADI SE19:ZINVOICE_UPDATE   MIRO发票检验过账好模拟时,检查采购订单line 是否有固定资产的行项目,如果有固定资产项目,则弹出提示框,提示消息:存在规定资产采购项目! ...

  7. [转] CentOS---网络配置详解

    原文地址: http://blog.chinaunix.net/uid-26495963-id-3230810.html 一.配置文件详解在RHEL或者CentOS等Redhat系的Linux系统里, ...

  8. 分布式计算开源框架Hadoop入门实践(一)

    在SIP项目设计的过程中,对于它庞大的日志在开始时就考虑使用任务分解的多线程处理模式来分析统计,在我从前写的文章<Tiger Concurrent Practice --日志分析并行分解设计与实 ...

  9. springboot-FilterRegistrationBean

    主要用来对servlet filter进行自定义,比如设置order. 先写一个普通的filter: public class FilterDemo implements Filter { priva ...

  10. C语言math.h库函数中atan与atan2的区别

    源: C语言math.h库函数中atan与atan2的区别 C语言中的atan和atan2