先把能合并的区间都合并起来。

考虑最裸的贪心策略,从左到右一段一段的取。

但是,这样会有错,错在没有考虑每段区间选取最后一个点。

因为N只有10,所以枚举一下哪些区间最后一个点会被选择,然后按照最裸的的贪心策略从左到右选择即可,每次更新最大值。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<algorithm>
using namespace std; const int maxn=;
struct X
{
long long L,R;
} s[maxn],tmp[maxn];
int n;
long long k,m,ans;
int g[maxn]; bool cmp(const X&a,const X&b)
{
if(a.L==b.L) return a.R<b.R;
return a.L<b.L;
} void f()
{
sort(tmp+,tmp++n,cmp);
int cnt=;
s[].L=tmp[].L,s[].R=tmp[].R;
for(int i=; i<=n; i++)
{
if(tmp[i].L<=s[cnt].R+)
s[cnt].R=max(s[cnt].R,tmp[i].R);
else
{
cnt++;
s[cnt].L=tmp[i].L,s[cnt].R=tmp[i].R;
}
}
n=cnt;
} long long check()
{
long long sum=,pos=; long long sy=m; for(int i=;i<=n;i++)
{
if(pos<s[i].L)
{
long long u=min(sy,(s[i].R-s[i].L+)/k);
sum=sum+u*k,pos=s[i].L-+u*k;
sy=sy-u; if(sy==) return sum; if(pos<s[i].R)
{
sum=sum+k,pos=pos+k;
sy=sy-; if(sy==) return sum;
} if(g[i]==)
{
sum=sum+s[i].R+k--pos;
pos=s[i].R+k-;
sy=sy-; if(sy==) return sum;
}
}
else if(pos>=s[i].R)
{
if(g[i]==)
{
sum=sum+s[i].R+k--pos;
pos=s[i].R+k-;
sy=sy-; if(sy==) return sum;
}
}
else
{
long long u=min(sy,(s[i].R-pos)/k);
sum=sum+u*k,pos=pos+u*k;
sy=sy-u; if(sy==) return sum; if(pos<s[i].R)
{
sum=sum+k,pos=pos+k;
sy=sy-; if(sy==) return sum;
} if(g[i]==)
{
sum=sum+s[i].R+k--pos;
pos=s[i].R+k-;
sy=sy-; if(sy==) return sum;
}
}
}
return sum;
} void dfs(int tot)
{
if(tot==n+)
{
ans=max(ans,check());
return;
}
g[tot]=; dfs(tot+);
g[tot]=; dfs(tot+);
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
ans=;
scanf("%d%lld%lld",&n,&k,&m);
for(int i=; i<=n; i++)
scanf("%lld%lld",&tmp[i].L,&tmp[i].R);
f();
dfs();
printf("%lld\n",ans);
}
return ;
}

ZOJ 3941 Kpop Music Party的更多相关文章

  1. ZOJ 3941 Kpop Music Party 贪心

    题目链接: http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=3941 题解: 先吧所给的区间合并,得到若干个独立的区间. 然后从左 ...

  2. ZOJ 3941 Kpop Music Party(省赛, 贪心)

    Kpop Music Party Time Limit: 2 Seconds      Memory Limit: 65536 KB Marjar University often hosts Kpo ...

  3. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  4. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  5. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

  6. ZOJ Problem Set - 1392 The Hardest Problem Ever

    放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...

  7. ZOJ Problem Set - 1049 I Think I Need a Houseboat

    这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...

  8. ZOJ Problem Set - 1006 Do the Untwist

    今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...

  9. ZOJ Problem Set - 1001 A + B Problem

    ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...

随机推荐

  1. NoRouteToHostException

    http://stackoverflow.com/questions/1572215/how-to-avoid-a-noroutetohostexception 端口不够用,注意一定要关闭所有不用的连 ...

  2. Update Case的用法与execute执行字符串

    摘自于网路:http://www.cnblogs.com/joinger/articles/1297160.html update h_crm_SafetyAccessUser set         ...

  3. 【字母全排列】 poj 1256

    深搜   注意与STL模版的去重函数唯一的区别就是有去重. #include <iostream> #include <cstdio> #include <string. ...

  4. 【转载】newInstance()和new()

    newInstance()和new() 在Java开发特别是数据库开发中,经常会用到Class.forName( )这个方法.通过查询Java Documentation我们会发现使用Class.fo ...

  5. Android摄像头:只拍摄SurfaceView预览界面特定区域内容(矩形框)---完整(原理:底层SurfaceView+上层绘制ImageView)

    Android摄像头:只拍摄SurfaceView预览界面特定区域内容(矩形框)---完整实现(原理:底层SurfaceView+上层绘制ImageView) 分类: Android开发 Androi ...

  6. w3chtml页面和css书写规范

    http://www.cnblogs.com/Wenwang/archive/2011/09/07/2169881.html

  7. Windows下MongoDB安装及创建用户名和密码

    下载MongoDB的安装文件https://www.mongodb.com/download-center#community,选择合适的版本(注:本人选择的是3.2.6) 下载完MongoDB.ms ...

  8. opencv ,亮度调整【【OpenCV入门教程之六】 创建Trackbar & 图像对比度、亮度值调整

    http://blog.csdn.net/poem_qianmo/article/details/21479533 [OpenCV入门教程之六] 创建Trackbar & 图像对比度.亮度值调 ...

  9. 为什么有时候必须添加sys.setdefaultencoding('utf-8')

    今天在尝试Python的CGI模块时遇到中文字符不能正确显示的问题,很郁闷.在网上仔细找了找,终于解决了这个问题,现在将解决方法陈述如下,以防下次失误. 页面源代码如下 #-*- coding: ut ...

  10. sphinx set several dates as filter

    http://sphinxsearch.com/forum/view.html?id=3187 > I think I may have found a bug. Yep, it looks w ...