码迷,mamicode.com
首页 > 其他好文 > 详细

hdu-1050(贪心+模拟)

时间:2018-10-06 21:38:11      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:scanf   ems   size   stream   namespace   swap   ++   pac   wap   

题目链接: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;
}

hdu-1050(贪心+模拟)

标签:scanf   ems   size   stream   namespace   swap   ++   pac   wap   

原文地址:https://www.cnblogs.com/2018zxy/p/9748315.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!