POJ 1230 Pass-Muraille 贪心

来源:互联网 发布:公安大数据应用现状 编辑:程序博客网 时间:2024/06/09 19:20

Pass-Muraille
Time Limit: 1000MS Memory Limit: 65536KB 64bit IO Format: %lld & %llu
Submit

Status

Description
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.

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
Hint
Walls are parallel to X.
Source
Tehran 2002 Preliminary

//逐列检查 在每次需要拆墙的时候都拆右边影响最大的(即从该列开始长度最长的)墙 贪心#include<stdio.h>#include<string>#include<cstring>#include<queue>#include<algorithm>#include<functional>#include<vector>#include<iomanip>#include<math.h>#include<iostream>#include<sstream>#include<stack>#include<set>#include<bitset>using namespace std;int pic[105][105];int T,N,K,righ,down,X1,Y1,X2,Y2;int main(){    cin.sync_with_stdio(false);    cin>>T;    while(T--)    {        righ=0;        down=0;        memset(pic,0,sizeof(pic));        cin>>N>>K;        for (int i=1; i<=N; i++)        {            cin>>X1>>Y1>>X2>>Y2;            righ=max(righ,max(X1,X2));            down=max(down,Y1);            int len=max(X1,X2)-min(X1,X2)+1;            for (int i=min(X1,X2); i<=max(X1,X2); i++)                pic[i][Y1]=max(pic[i][Y1],len--);        }        int Ans=0;        for (int i=0; i<=righ; i++)        {            int temp=0;            for (int j=0; j<=down; j++)                if (pic[i][j])                    temp++;            while (temp>K)            {                int maxl=0,pos=0;                for (int k=0; k<=down; k++)                    if (pic[i][k]>maxl)                    {                        maxl=pic[i][k];                        pos=k;                    }                int p=pic[i][pos];                for (int d=0; d<p; d++)                    pic[i+d][pos]=0;                temp--;                Ans++;            }        }        cout<<Ans<<endl;    }    return 0;}
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 黑衣服洗完发白怎么办 白衣服被黑衣服染色了怎么办 评职称单位领导不推荐怎么办 支付宝被限制收款怎么办 在淘宝上下单想写两个地址怎么办 注销了的支付宝怎么办 狗狗黑色毛发红怎么办 蘑菇街直播间被禁言了怎么办 收了发票不付款怎么办 退款要先收发票怎么办 淘宝退款了又收到货怎么办 商家收货后拒绝退款怎么办 申请退货退款卖家不处理怎么办 淘宝买东西换货卖家不发货怎么办 淘宝自动默认付款没发货怎么办 支付宝支付失败可钱扣了怎么办 苹果nfc感应坏了怎么办 老鼠添过的盘子怎么办 ie浏览器页面显示网页错误怎么办 Ⅵvo手机声音小怎么办 小米手机预约错了怎么办 小米note二手没解锁怎么办 艾灸后脸色越黑怎么办 淘宝软件类目不能上架宝贝怎么办 ae中没有mpg格式怎么办 淘宝小二处理不公怎么办 遇到卖保险的人怎么办 租房合同没理家电清单怎么办 普雪油烟机坏了怎么办 我累了 真的累了怎么办 u盘15g变成4g了怎么办 属兔的买了东户怎么办 玩时时彩输了2万怎么办 胸变的又软又小怎么办 u盘16g变成4g了怎么办 1岁宝宝吃了就吐怎么办 脚崴了肿了很痛怎么办 九格拼图5在9那怎么办 4s锁屏密码忘了怎么办 6p触屏偶尔乱跳怎么办 新办劳务公司的劳务资质怎么办