hdu-1050(贪心+模拟)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050

思路:由图可知,1对应2,3对应4,以此类推,如果x,y是偶数则变为奇数;

每次输入两个区间,找区间重合几次,重合的部分最多的就是最终移动几次。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int vc[1200];
int main(void)
{
    int x,y,n,t,i,mx;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        memset(vc,0,sizeof(vc));
        mx=0;
        while(n--)
        {
            scanf("%d %d",&x,&y);
            if(x%2==0) x--;
            if(y%2==0) y--;
            if(x>y) swap(x,y);
            for(i=x;i<=y;i++) vc[i]++,mx=vc[i]>mx?vc[i]:mx;
        }
        printf("%d\n",mx*10);
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/2018zxy/p/9748315.html