problem-1000-移動桌子

題意:公司有400個房間,單號對雙號對門,中間有一條走廊,
現在要搬東西,給出要搬的次數,還有每次搬動的房間號,
每次搬動需要10分鐘,搬動過程中的那段走廊不能被使用,

求最大搬動時長。

解析:

按a從大到小排序。.由於奇偶數分列兩邊,所以需要將奇偶數房間號做一下變換: 
    如果值是奇數,則該值除以2再+1;如果是偶數直接除以二,此時號的範圍變成1~200 
ac代碼:
#include<cstdio>
#include<iostream>
#include<fstream>
#include<cmath>
#include<cstring>
using namespace std;

const int N=202;
int main()
{
    int c;
    scanf("%d",&c);
    while(c--){
    int m,n;
    int start,end;
    int i;//拌勻次數
    int ccount[N];
    scanf("%d",&i);
    memset(ccount,0,sizeof(ccount));

    for(m=0;m<i;m++)
    {
        scanf("%d%d",&start,&end);
        start=(start-1)/2;
        end=(end-1)/2;
        if(start>end){
            int temp=start;
            start=end;
            end=temp;
        }
        for(n=start;n<=end;n++)
            ccount[n]++;
    }
    int max=0;
    for(m=0;m<N;m++)
        if(ccount[m]>max) max=ccount[m];
    printf("%d\n",max*10);
    }
    return 0;
}

發佈了33 篇原創文章 · 獲贊 0 · 訪問量 7485
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章