HDU ACM 1050 Moving Tables->贪心或者?

分析:该題可以用贪心来做,类似于节目时间安排的问题,桌子的移动房间看作时间处理。

下面是另一种更简便的做法。把奇数房间号和偶数房间号映射为房间在走廊上的位置,从1到200;开一个数组,每次从s移桌子到t就把中间走廊的每个位置都加1,最后扫描整个数组,找出最大值在乘上移动一张桌子所用的时间就是必须花费的时间。

#include<iostream>
using namespace std;

int roompos[202];

int GetRoomPos(int n)
{
    if(n&1) return (n+1)/2;
    else return n/2;
}

int main()
{
    int T,N,s,t,i,j,max,maxpos,minpos;

    cin>>T;
    while(T--)
    {
        cin>>N;
        memset(roompos,0,sizeof(roompos));
        maxpos=-1;
        minpos=10000;
        for(i=0;i<N;i++)
        {
            cin>>s>>t;
            if(s>t)
            {
                int tmp=s;
                s=t;
                t=tmp;
            }
            maxpos=maxpos>GetRoomPos(t)?maxpos:GetRoomPos(t);
            minpos=minpos<GetRoomPos(s)?minpos:GetRoomPos(s);
            for(j=GetRoomPos(s);j<=GetRoomPos(t);j++)
                roompos[j]+=1;
        }
        max=0;
        for(i=minpos;i<=maxpos;i++)
            max=max>roompos[i]?max:roompos[i];
        cout<<max*10<<endl;
    }
    return 0;
}
时间: 2024-10-16 14:03:40

HDU ACM 1050 Moving Tables->贪心或者?的相关文章

--hdu 1050 Moving Tables(贪心)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050 AC code: #include<stdio.h> #include<string.h> int m[210]; int main(void) { int t,n,i,j,st,en,ma; scanf("%d",&t); while(t--) { memset(m,0,sizeof(m)); scanf("%d",&n)

hdoj 1050 moving tables

代码: #include <iostream> #include <algorithm> //#include <fstream> using namespace std; int f[201]; int main() { //ifstream cin("1050_input.txt");   //调试用 int t, n, i, j, s, e; cin >> t; while( t-- ){ memset( f, 0, sizeof(

HDU 1050 Moving Tables (贪心)

Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 20302    Accepted Submission(s): 6889 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): 24553    Accepted Submission(s): 8116 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

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

HDU 1050.Moving Tables【细节与方法选取】【8月26】

Moving Tables Problem 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 rooms each on the north side and south side along the corridor. Recently the

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

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