ZOJ 1029

///
//2351692     2010-11-17 16:53:46     Accepted     1029     C     0     164     VRS
//1029 房间移桌子 贪心法

 

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

typedef struct _MOVING
{
    int roomFrom;
    int roomTo;
    int flags;
}MOVING;
MOVING move[205];

int cmp(const void *x,const void *y)
{
    MOVING *a=(MOVING *)x;
    MOVING *b=(MOVING *)y;
    return a->roomFrom-b->roomFrom;
}

int main()
{
    int testCase,i;
    int tempa,tempb;
    int moveNum,lastLoc,currentLoc;
    int unsoveNum,unsoveCurrent,unsoveCount;
    int count;
    int unsoveMove[205];
    scanf("%d", &testCase);
    while(testCase--)
    {
        count=0;
        memset(move,0,sizeof(move));
        scanf("%d", &moveNum);
        for(i=0;i<moveNum;i++)
        {
            scanf("%d %d", &tempa, &tempb);
            if(tempa<=tempb)
            {
                move[i].roomFrom=tempa;
                move[i].roomTo=tempb;
            }
            else
            {
                move[i].roomFrom=tempb;
                move[i].roomTo=tempa;
            }
            move[i].flags=0;
        }
        qsort(move,moveNum,sizeof(move[0]),cmp);

 

        count=0;
        lastLoc=0;currentLoc=1;
        while(1)
        {
            while(move[lastLoc].flags==1 && lastLoc<moveNum) lastLoc++;
            if(lastLoc<moveNum)
            {
                move[lastLoc].flags=1;
                count+=10;
            }
            else
                break;
            currentLoc=lastLoc+1;
            while(currentLoc<moveNum)
            {
                while(move[currentLoc].flags==1 && currentLoc<moveNum) currentLoc++;
                if(currentLoc<moveNum
                    && move[lastLoc].roomTo<move[currentLoc].roomFrom
                    && !(move[lastLoc].roomTo%2==1 && move[lastLoc].roomTo==move[currentLoc].roomFrom-1)
                    )
                {
                    move[currentLoc].flags=1;
                    lastLoc=currentLoc;
                }
                currentLoc++;
            }
            lastLoc=1;
        }
       
        printf("%d\n",count);
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/VRS_technology/archive/2010/11/23/1885405.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值