POJ 1230 Pass-Muraille
2016-04-28 21:54
429 查看
Pass-Muraille
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 10223 Accepted: 3176
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
代码:
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 10223 Accepted: 3176
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
代码:
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> using namespace std; struct root { int x; int y; } s[1005]; int main() { int n,m; int t; scanf("%d",&t); while(t--) { scanf("%d %d",&n,&m); int k=-1; int ans=0; int o; for(int i=0; i<n; i++) { int x1,y1,x2,y2; scanf("%d %d %d %d",&x1,&y1,&x2,&y2); if(x1>x2) { int f=x1; x1=x2; x2=f; } s[i].x=x1; s[i].y=x2; if(s[i].y>k) k=s[i].y; } for(int i=0; i<=k; i++) { int c=0; for(int j=0; j<n; j++) { if(i<=s[j].y&&i>=s[j].x) c++; } c=c-m; while(c>0) { c--; int b=-1; for(int j=0; j<n; j++) { if(i<=s[j].y&&i>=s[j].x&&s[j].y>b) { b=s[j].y; o=j; } } s[o].y=-1; ans++; } } printf("%d\n",ans); } return 0; }
相关文章推荐
- ElasticSearch学习17_Failed to deserialize response of type [*.SearchResponse]错误原因
- 使用有限状态机(FSM)编写的敌人AI
- HashSet contain出错
- LeetCode------Contains Duplicate
- LightOJ - 1282 Leading and Trailing 对数转换
- LA 4725 Airport
- 30-Container With Most Water-Leetcode
- 密码学---PlayFair
- lightoj1282 - Leading and Trailing
- INSTALL_FAILED_SHARED_USER_INCOMPATIBLE的问题解决
- 1106. Lowest Price in Supply Chain
- UVALive6900 Road Repair(树的点分治)
- 机器学习算法之朴素贝叶斯(Naive Bayes)--第二篇
- 关于错误INSTALL_FAILED_NO_MATCHING_ABIS
- rails模块学习之Controller
- 安装exitmail的日志系统,并自动发送邮件过来
- 相同坐标信息的统计----AIS信息统计
- RAID0 RAID1 RAID10 RAID5 各需几块盘才可组建
- 'release' is unavailable 解决办法
- 线程中sleep和wait的区别