杭电1050(贪心)

题目:

The famous ACM (Advanced Computer Maker) Company has
rented a floor of a building whose shape is in the following figure.



The floor
has 200 rooms each on the north side and south side along the corridor.
Recently the Company made a plan to reform its system. The reform includes
moving a lot of tables between rooms. Because the corridor is narrow and all
the tables are big, only one table can pass through the corridor. Some plan is
needed to make the moving efficient. The manager figured out the following
plan: Moving a table from a room to another room can be done within 10 minutes.
When moving a table from room i to room j, the part of the corridor between the
front of room i and the front of room j is used. So, during each 10 minutes,
several moving between two rooms not sharing the same part of the corridor will
be done simultaneously. To make it clear the manager illustrated the possible
cases and impossible cases of simultaneous moving.



For
each room, at most one table will be either moved in or moved out. Now, the
manager seeks out a method to minimize the time to move all the tables. Your
job is to write a program to solve the manager’s problem.

Input

The input consists of T test cases. The number of
test cases ) (T is given in the first line of the input. Each test case begins
with a line containing an integer N , 1<=N<=200 , that represents the
number of tables to move. Each of the following N lines contains two positive
integers s and t, representing that a table is to move from room number s to
room number t (each room number appears at most once in the N lines). From the
N+3-rd line, the remaining test cases are listed in the same manner as
above.

Output

The output should contain the minimum time in minutes
to complete the moving, one per line.

Sample Input

3

4

10 20

30 40

50 60

70 80

2

1 3

2 200

3

10 100

20 80

30 50

Sample Output

10

20

30

思路:

  一开始的思路是第一组依次循环,如果遇到可以一起的将visit[j] = 1;

然而忽略了如:10 20;30 40; 35 45;30 40,和35,45都可以满足10 20,

可是35 45无法满足30 40,所以实际答案应该是2自己原先的代码得结果是1.

为了解决这个问题,可以将每组经过的过道都加1,这样过道经过数最多的就是组数

要最多的。

代码;

 1 #include<stdio.h>
2 #include<iostream>
3 #include<algorithm>
4 #include<string.h>
5 using namespace std;
6
7 typedef struct{
8 int start;
9 int end;
10 }Table;
11 Table table[205];
12
13 int getmax(int x, int y){
14 return x > y ? x : y;
15 }
16 int getmin(int x, int y){
17 return x > y ? y : x;
18 }
19
20 int main(){
21 int t, n, i, j, visit[205], flag, num, max;
22 scanf("%d", &t);
23 while(t --){
24 scanf("%d", &n);
25 memset(visit, 0, sizeof(visit));
26 for(i = 0; i < n; i ++){
27 scanf("%d %d", &table[i].start, &table[i].end);
28 table[i].start = (table[i].start + 1) / 2;
29 table[i].end = (table[i].end + 1) / 2;
30 for(j = getmin(table[i].start, table[i].end); j <= getmax(table[i].start, table[i].end); j ++){
31 visit[j] ++;
32 }
33 }
34 sort(visit, visit + 205);
35 printf("%d\n", visit[204] * 10);
36 }
37 return 0;
38 }

奋进

杭电1050(贪心),布布扣,bubuko.com

时间: 2024-10-17 00:03:43

杭电1050(贪心)的相关文章

HDU 5742 It&#39;s All In The Mind (贪心) 2016杭电多校联合第二场

题目:传送门. 题意:求题目中的公式的最大值,且满足题目中的三个条件. 题解:前两个数越大越好. #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; int gcd(int a,int b) { if(!b) return a; return gcd(b,a%b); } int main() { int t; ci

HDU 4864 Task (贪心+STL多集(二分)+邻接表存储)(杭电多校训练赛第一场1004)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 解题报告:有n台机器用来完成m个任务,每个任务有一个难度值和一个需要完成的时间,每台机器有一个可以工作的最长时间和一个可以完成的任务的难度的最大值, 一台机器能完成一个任务的条件是这台机器的最长工作时间和能完成任务的难度值必须都大于等于这个任务,而且一台机器最多完成一个任务,假设一个任务的时间为t,难度值为x,那么完成这个任务可以赚到的钱 money = 500 * t + 2 * x; 现在

杭电 1009(贪心算法)

<span style="font-size:18px;"></span><h1 style="text-align: center; color: rgb(26, 92, 200);">FatMouse' Trade</h1><span size="+0"></span><div style="text-align: center;"><

杭电 1052 Tian Ji -- The Horse Racing(贪心)

http://acm.hdu.edu.cn/showproblem.php?pid=1052 Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 18058    Accepted Submission(s): 5239 Problem Description Here is a fa

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY

杭电ACM题目分类

杭电ACM题目分类 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028. 1029.1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092. 1093.1094.1095.1096.1097.1098.1106.1108.1157.1163.1164.1170.1194.1196. 1197.1201.1202.1205.1219.1234.123

【转】对于杭电OJ题目的分类

[好像博客园不能直接转载,所以我复制过来了..] 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDI

杭电 1203 I NEED A OFFER!(01背包)

http://acm.hdu.edu.cn/showproblem.php?pid=1203 I NEED A OFFER! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 15759    Accepted Submission(s): 6259 Problem Description Speakless很早就想出国,现在他已经考完了

杭电oj 1009 FatMouse&#39; Trade

Tips:本题采用贪心算法,类似于背包问题,关键在于读入数据之后,将数据按 J[i]/F[i] 从大到小排列即可. 1 /**本程序主要采用贪心算法思想,类似于背包问题*/ 2 #include<stdio.h> 3 #include<string.h> 4 int main() 5 { 6 int M,N; 7 while(scanf("%d %d",&M,&N)) 8 { 9 if(M == -1 && N == -1) 10