【POJ 2572 Advertisement】
Time Limit: 1000MS
Memory Limit: 10000K
Total Submissions: 947
Accepted: 345
Special Judge
Description
The Department of Recreation has decided that it must be more profitable, and it wants to sell advertising space along a popular jogging path at a local park. They have built a number of billboards (special signs for advertisements) along the path and have decided to sell advertising space on these billboards. Billboards are situated evenly along the jogging path, and they are given consecutive integer numbers corresponding to their order along the path. At most one advertisement can be placed on each billboard.
A particular client wishes to purchase advertising space on these billboards but needs guarantees that every jogger will see it's advertisement at least K times while running along the path. However, different joggers run along different parts of the path.
Interviews with joggers revealed that each of them has chosen a section of the path which he/she likes to run along every day. Since advertisers care only about billboards seen by joggers, each jogger's personal path can be identified by the sequence of billboards viewed during a run. Taking into account that billboards are numbered consecutively, it is sufficient to record the first and the last billboard numbers seen by each jogger.
Unfortunately, interviews with joggers also showed that some joggers don't run far enough to see K billboards. Some of them are in such bad shape that they get to see only one billboard (here, the first and last billboard numbers for their path will be identical). Since out-of-shape joggers won't get to see K billboards, the client requires that they see an advertisement on every billboard along their section of the path. Although this is not as good as them seeing K advertisements, this is the best that can be done and it's enough to satisfy the client.
In order to reduce advertising costs, the client hires you to figure out how to minimize the number of billboards they need to pay for and, at the same time, satisfy stated requirements.
Input
The first line of the input contains two integers K and N (1 <= K, N <= 1000) separated by a space. K is the minimal number of advertisements that every jogger must see, and N is the total number of joggers.
The following N lines describe the path of each jogger. Each line contains two integers Ai and Bi (both numbers are not greater than 10000 by absolute value). Ai represents the first billboard number seen by jogger number i and Bi gives the last billboard number seen by that jogger. During a run, jogger i will see billboards Ai, Bi and all billboards between them.
Output
On the fist line of the output file, write a single integer M. This number gives the minimal number of advertisements that should be placed on billboards in order to fulfill the client's requirements. Then write M lines with one number on each line. These numbers give (in ascending order) the billboard numbers on which the client's advertisements should be placed.
Sample Input
- 5 10
- 1 10
- 20 27
- 0 -3
- 15 15
- 8 2
- 7 30
- -1 -10
- 27 20
- 2 9
- 14 21
Sample Output
- 19
- -5
- -4
- -3
- -2
- -1
- 0
- 4
- 5
- 6
- 7
- 8
- 15
- 18
- 19
- 20
- 21
- 25
- 26
- 27
Source
【题解】
①典型的区间前缀和约束的差分约束问题
②处理负数坐标可以加上一个很大的整数
- #include<queue>
- #define _ 10010
- #include<stdio.h>
- #include<algorithm>
- #define inf 1000000007
- #define go(i,a,b) for(int i=a;i<=b;i++)
- #define fo(i,a,x) for(int i=a[x],v=e[i].v;i;i=e[i].next,v=e[i].v)
- using namespace std;
- const int N=30003;
- queue<int>q;bool inq[N];
- struct E{int v,next,w;}e[N<<1];
- int n,K,k=1,a[N],b[N],head[N],S=1e9,T,d[N];
- void ADD(int u,int v,int w){e[k]=(E){v,head[u],w};head[u]=k++;}
- void Build()
- {
- go(i,1,n)scanf("%d%d",a+i,b+i),a[i]+=_,b[i]+=_;
- go(i,1,n)if(a[i]>b[i])a[i]^=b[i]^=a[i]^=b[i];
- go(i,1,n)ADD(a[i]-1,b[i],min(b[i]-a[i]+1,K));
- go(i,1,n)S=min(S,a[i]-1),T=max(T,b[i]);
- go(i,S,T)ADD(i,i-1,-1);
- go(i,S,T)ADD(i,i+1,0);
- }
- void SPFA()
- {
- go(i,S,T)d[i]=-inf;d[S]=0;q.push(S);int u;
- while(!q.empty())
- {
- inq[u=q.front()]=0;q.pop();
- fo(i,head,u)if(d[u]+e[i].w>d[v])
- {
- d[v]=d[u]+e[i].w;
- !inq[v]?q.push(v),inq[v]=1:1;
- }
- }
- printf("%d\n",d[T]);
- go(i,S,T)if(d[i]>d[i-1])printf("%d\n",i-_);
- }
- int main()
- {
- scanf("%d%d",&K,&n);
- Build(); SPFA();
- return 0;
- }//Paul_Guderian
.
【POJ 2572 Advertisement】的更多相关文章
- 【POJ 3169 Layout】
Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 12565Accepted: 6043 Description Like every ...
- 【POJ 1201 Intervals】
Time Limit: 2000MSMeamory Limit: 65536K Total Submissions: 27949Accepted: 10764 Description You are ...
- 【POJ 3279 Fliptile】开关问题,模拟
题目链接:http://poj.org/problem?id=3279 题意:给定一个n*m的坐标方格,每个位置为黑色或白色.现有如下翻转规则:每翻转一个位置的颜色,与其四连通的位置都会被翻转,但注意 ...
- 【POJ 3614 Sunscreen】贪心 优先级队列
题目链接:http://poj.org/problem?id=3614 题意:C头牛去晒太阳,每头牛有自己所限定的spf安全范围[min, max]:有L瓶防晒液,每瓶有自己的spf值和容量(能供几头 ...
- 【POJ 1182 食物链】并查集
此题按照<挑战程序设计竞赛(第2版)>P89的解法,不容易想到,但想清楚了代码还是比较直观的. 并查集模板(包含了记录高度的rank数组和查询时状态压缩) *; int par[MAX_N ...
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【POJ】【2096】Collecting Bugs
概率DP/数学期望 kuangbin总结中的第二题 大概题意:有n个子系统,s种bug,每次找出一个bug,这个bug属于第 i 个子系统的概率为1/n,是第 j 种bug的概率是1/s,问在每个子系 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
随机推荐
- WinForm webbrowser控件的使用
webbrowser是一个比较实用的工具,主要用于在winform窗体中嵌入浏览器,达到winform与webform互操作的目的. 先上一个demo,看一下能实现什么效果. private void ...
- python三大神器之生成器
生成器Generator: 本质:迭代器(所以自带了__iter__方法和__next__方法,不需要我们去实现) 特点:惰性运算,开发者自定义 在python中有三种方法来获取生成器: 1.通过生成 ...
- DedeCMS V5.7sp2最新版本parse_str函数SQL注入漏洞
织梦dedecms,在整个互联网中许多企业网站,个人网站,优化网站都在使用dede作为整个网站的开发架构,dedecms采用php+mysql数据库的架构来承载整个网站的运行与用户的访问,首页以及栏目 ...
- SAP ABAP Development Tools in Eclipseのセットアップ
手順 1. Eclipse IDE インストール 以下からダウンロード.https://tools.hana.ondemand.com/#abap※2018/1月現在 Oxygen(4.7)詳細は割愛 ...
- Lucene如何实现多条件搜索?
有两种方式可以实现, 一是:Lucene搜索API中提供了一个布尔查询器(BooleanQuery),它可以包含多个查询器,每个查询器Occur枚举控制是“and” 还是“or” BooleanQue ...
- 初步学习pg_control文件之五
接前文 初步学习pg_control文件之四,继续看何时出现 DB_IN_CRASH_RECOVERY: 看下面代码就比较清楚了:如果对 InArchiveRecovery 判断值为假,而且 读取出 ...
- Hibernate-ORM:04.Hibernate中的get()和load()
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 本篇博客会讲如何用get()或load()查询单个对象和对缓存的简单操作,以及他俩的区别和相同(前面有的那些配 ...
- 「暑期训练」「Brute Force」 Restoring Painting (CFR353D2B)
题意 给定一定条件,问符合的矩阵有几种. 分析 见了鬼了,这破题谁加的brute force的标签,素质极差.因为范围是1e5,那你平方(枚举算法)的复杂度必然爆. 然后你就会思考其中奥妙无穷的数学规 ...
- python学习总结------邮件与短信
邮件发送 - 简介: - 邮件服务器.用户名.密码 - 相关协议: - SMTP:简单邮件传输协议 - POP3:邮局通讯协议 - IMAP:交互式邮件存取协议 - SMTP协议默认端口是25 - 用 ...
- LAXCUS对数据存储的优化
LAXCUS兼容行存储(NSM)和列存储(DSM)两种数据模型,实现了混合存储.同时在分布环境里,做到将数据的分发和备份自动处理,这样就不再需要人工干预了. 行存储,为了兼容广大用户对 ...