POJ 1083 Moving Tables

题意:一个建筑物里有400个房间,房间都在一层里,在一个走廊的两侧,如图,现在要搬n张桌子,告诉你每张桌子是从哪个屋搬到哪个屋,搬桌子的线路之间不可以有重叠,问最少搬几次。

解法:贪心。一开始觉得只要排个序,然后按顺序一次一次的分配就可以了……但是wa了……百度之后知道只要看哪块地的使用次数最多就是答案……于是A了之后出随机数据对拍,发现确实一开始的贪心是错的……嘤嘤嘤

代码:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long

using namespace std;

bool cmp(int a, int b)
{
    return a > b;
}
int main()
{
    int T;
    while(~scanf("%d", &T))
    {
        while(T--)
        {
            int n;
            int ans[200] = {0};
            scanf("%d", &n);
            for(int i = 0; i < n; i++)
            {
                int l, r;
                scanf("%d%d", &l, &r);
                if(l > r) swap(l, r);
                if(l & 1) l++;
                if(r & 1) r++;
                for(int i = l; i <= r; i += 2)
                    ans[i / 2]++;
            }
            sort(ans, ans + 200, cmp);
            printf("%d\n", ans[0] * 10);
        }
    }
    return 0;
}

  

时间: 2024-10-06 06:02:23

POJ 1083 Moving Tables的相关文章

POJ 1083 Moving Tables 思路 难度:0

http://poj.org/problem?id=1083 这道题题意是有若干段线段,每次要求线段不重叠地取,问最少取多少次. 因为这些线段都是必须取的,所以需要让空隙最小 思路: 循环直到线段全部取完,对于某个刚取得线段ij,下一个线段km取起点k尽量靠近j且满足k>j的.记录循环次数cnt,答案是cnt*10 注意: 房间是相对的,也就是说对于奇数房间号,利用的走廊相当于对应的偶数房间号开始的那一段路程, 一段路程的开头不能是另外一段路程的结尾. #include <cstdio>

poj 1579 Moving Tables(水)

Description The Recaman's sequence is defined by a0 = 0 ; for m > 0, a m = a m−1 − m if the rsulting a m is positive and not already in the sequence, otherwise a m = am−1 + m. The first few numbers in the Recaman's Sequence is 0, 1, 3, 6, 2, 7, 13, 2

poj 杂题 - 1083 Moving Tables

这道题最主要的是看懂题目即可.我们需要算出搬动桌子的最短时间,根据这个图可以知道不同房间占用同一走廊. 这道题里1-4,2 -3显然占用同一走廊,但是2-3 和 4-5也占用了房间4和房间3的那个走廊,所以注意这个数据的最短时间是20,不是10.搞清楚这个就好做了,我们可以将房间偶数/2,奇数/2+1,这样2-3变成了1-2,4-5变成了2-3,自然占用了走廊. #include<stdio.h> #include<string.h> #define max(x,y)(x>y

poj1083 Moving Tables

Moving Tables Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26782   Accepted: 8962 Description 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

hdu1050&amp;&amp;nyoj220 Moving Tables(贪心)

Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 24372    Accepted Submission(s): 8071 Problem Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a

hdoj 1050 Moving Tables【贪心区间覆盖】

Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 24316    Accepted Submission(s): 8053 Problem Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a b

POJ 1083

Moving Tables Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26773   Accepted: 8958 Description 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

HDU1050(Moving Tables:贪心算法)

解题思路: 这种做法是基于hdu2037的做法上考虑的,找出所有可以同时搬运的桌子,然后就很方便求出最短总时间. 还有一种更简单的做法是直接遍历一遍找出与别的重复次数最多的那片区域,重复次数*10就可以得到结果. Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 28033    Accepted Submis

HDU 1050 Moving Tables

Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 23044    Accepted Submission(s): 7749 Problem Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a