Priest John's Busiest Day

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1420    Accepted Submission(s): 415

Problem Description
John is the only priest in his town. October 26th is the John's busiest day in a year because there is an old legend in the town that the couple who get married on that day will be forever blessed by the God of Love. This year N couples plan to get married on the blessed day. The i-th couple plan to hold their wedding from time Si to time Ti. According to the traditions in the town, there must be a special ceremony on which the couple stand before the priest and accept blessings. Moreover, this ceremony must be longer than half of the wedding time and can’t be interrupted. Could you tell John how to arrange his schedule so that he can hold all special ceremonies of all weddings?
Please note that:
John can not hold two ceremonies at the same time. John can only join or leave the weddings at integral time. John can show up at another ceremony immediately after he finishes the previous one.
 
Input
The input consists of several test cases and ends with a line containing a zero.
In each test case, the first line contains a integer N ( 1 ≤ N ≤ 100,000) indicating the total number of the weddings.
In the next N lines, each line contains two integers Si and Ti. (0 <= Si < Ti <= 2147483647)
 
Output
For each test, if John can hold all special ceremonies, print "YES"; otherwise, print “NO”.
 
Sample Input
3
1 5
2 4
3 6
2
1
4
5 6
0
 
Sample Output
NO
YES
 
Source
 
 题意:
           小镇有n场婚礼在一天之内进行,第i场婚礼的开始时间为s,结束时间为t,在每一场婚礼中,有一个重要的仪式。即牧师给与两位新人传达主的祝福,对于第i场婚礼,祝福仪式可以在[s  , t]中任何时候举行,但是必须超过总时间的一半以上。
          小镇只有一位牧师,所有的祝福仪式都必须要他在场吗。同时,牧师必须在整数时刻开始或者结束祝福仪式,不过他可以在结束之后立刻开始另一场。
现在给你所有的婚礼的信息请问是否能够安排好一个祝福仪式的顺序,使得牧师能够给所有的新人带去幸福......
          现在给你所有婚礼的信息,请问是否能够安排好一个祝福仪式的顺序,使得牧师能够给所有新人带去幸福...
 
 
自己写了个搓代码:
先展示一下大神的代码把!...
然后再看弱屌的代码....
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = ;
struct tnode
{
int s,e;
int ms,me;
int keyinterval;
int id;
}c[maxn]; bool operator < (const tnode &a , const tnode &b)
{
return (a.ms <b.ms ||(a.ms==b.ms&&a.me<b.me));
}
int n , i;
void init()
{
for(i= ; i<n ;i++ ){
scanf("%d%d",&c[i].s,&c[i].e);
c[i].id=i;
c[i].keyinterval = (c[i].e - c[i].s +)/ ;
c[i].ms=c[i].s+(c[i].e - c[i].s -)/;
c[i].me=c[i].s+;
if((c[i].e-c[i].s)%==)
++c[i].me;
}
sort(c,c+n);
}
bool work()
{
int now_s , now_e ,last_e;
last_e=;
for(int i= ; i<n ;i++)
{
now_s =c[i].s;
if(now_s<last_e) now_s=last_e;
now_e=now_s+c[i].keyinterval;
if(now_e>c[i].e) return false;
last_e = now_e;
}
return true ;
} int main()
{
while(scanf("%d",&n),n!=)
{
init();
if(work())
printf("YES\n");
else
printf("NO\n");
}
return ;
}

运用STL之后,速度更搓,空间开销也增大了不少....

代码:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn = ;
struct tnode
{
int s,e;
int ms,me;
int keyinterval;
int id;
bool operator < (const tnode &b) const
{
return (ms <b.ms ||(ms==b.ms&&me<b.me));
}
}; int n , i;
tnode cc;
vector<tnode>c;
void init()
{
c.clear();
for(i= ; i<n ;i++ ){
scanf("%d%d",&cc.s,&cc.e);
cc.id=i;
cc.keyinterval = (cc.e - cc.s +)/ ;
cc.ms=cc.s+(cc.e - cc.s -)/;
cc.me=cc.s+;
if((cc.e-cc.s)%==)
++cc.me;
c.push_back(cc);
}
sort(c.begin(),c.end());
}
bool work()
{
int now_s , now_e ,last_e;
last_e=;
for(int i= ; i<n ;i++)
{
now_s =c[i].s;
if(now_s<last_e) now_s=last_e;
now_e=now_s+c[i].keyinterval;
if(now_e>c[i].e) return false;
last_e = now_e;
}
return true ;
} int main()
{
while(scanf("%d",&n),n!=)
{
init();
if(work())
printf("YES\n");
else
printf("NO\n");
}
return ;
}

然后自己有写了一次..........!

代码:

手动的扩栈....

#program comment (linker ,"/STACK :102400000  102400000")

 #include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000") //由于用内分装之后会出现溢栈的情况,所以手动扩栈
using namespace std; const int maxn = ; struct tnode
{
int s,e;
int ms,me;
int mid;
bool operator < (const tnode b) const
{
return (ms<b.ms||(ms==b.ms)&&me<b.me);
}
};
class node
{
private:
tnode str[maxn];
int i;
public :
int n;
void init();
bool work();
}; void node::init()
{
for(i=;i<n;i++)
{
scanf("%d%d",&str[i].s,&str[i].e) ;
str[i].mid=(str[i].e-str[i].s)/ + ;
str[i].ms= str[i].s+(str[i].e-str[i].s-)/ ;
str[i].me=str[i].s+ ;
if((str[i].e-str[i].s)%==) str[i].me++;
}
sort(str,str+n);
}
bool node::work()
{
int temp_s,temp_e,last_e=;
for( i= ; i<n ; i++ )
{
temp_s=str[i].s;
if(temp_s<last_e) temp_s=last_e;
temp_e = temp_s+str[i].mid;
if(temp_e>str[i].e) return false;
last_e=temp_e;
}
return true ;
}
int main()
{
node a;
while(scanf("%d",&a.n)!=EOF&&a.n)
{
a.init();
if(a.work())printf("YES\n");
else printf("NO\n");
}
return ;
}
 
 

hdu-----2491Priest John's Busiest Day(2008 北京现场赛G)的更多相关文章

  1. HDUOJ-------2493Timer(数学 2008北京现场赛H题)

    Timer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  2. HDUOJ--------A simple stone game(尼姆博弈扩展)(2008北京现场赛A题)

    A simple stone game                                                                                  ...

  3. HDUOJ----2485 Destroying the bus stations(2008北京现场赛A题)

    Destroying the bus stations                                                                          ...

  4. HDU 5122 K.Bro Sorting(2014北京区域赛现场赛K题 模拟)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5122 解题报告:定义一种排序算法,每一轮可以随机找一个数,把这个数与后面的比这个数小的交换,一直往后判 ...

  5. HDU 5119 Happy Matt Friends(2014北京区域赛现场赛H题 裸背包DP)

    虽然是一道还是算简单的DP,甚至不用滚动数组也能AC,数据量不算很大. 对于N个数,每个数只存在两个状态,取 和 不取. 容易得出状态转移方程: dp[i][j] = dp[i - 1][j ^ a[ ...

  6. hdu 5038 (2014北京网络赛G 排序水题)

    题意:有n个数字,带入10000 - (100 - ai) ^ 2公式得到n个数,输出n个数中频率最大的数,如果有并列就按值从小到大都输出输出,如果频率相同的数字是全部的n个数,就输出Bad....题 ...

  7. hdu 5120(求两个圆环相交的面积 2014北京现场赛 I题)

    两个圆环的内外径相同 给出内外径 和 两个圆心 求两个圆环相交的面积 画下图可以知道 就是两个大圆交-2*小圆与大圆交+2小圆交 Sample Input22 30 00 02 30 05 0 Sam ...

  8. hdu 5122 (2014北京现场赛 K题)

    把一个序列按从小到大排序 要执行多少次操作 只需要从右往左统计,并且不断更新最小值,若当前数为最小值,则将最小值更新为当前数,否则sum+1 Sample Input255 4 3 2 155 1 2 ...

  9. hdu 5112 (2014北京现场赛 A题)

    给出某个时刻对应的速度 求出相邻时刻的平均速度 输出最大值 Sample Input23 // n2 2 //t v1 13 430 31 52 0 Sample OutputCase #1: 2.0 ...

随机推荐

  1. winform继承窗体,无法修改父窗体控件问题处理笔记

    问题描述: 一个窗体集成父窗体,发现无法直接修改父窗体的控件,比如修改大小等,父窗体控件已经设置为public,如果做成一个dll被引用无此问题 特征: 不禁使父窗体控件,就算新加一个控件也会这样:鼠 ...

  2. jquery之event与originalEvent的关系、event事件对象用法浅析

    在jquery中,最终传入事件处理程序的 event 其实已经被 jQuery 做过标准化处理, 其原有的事件对象则被保存于 event 对象的 originalEvent 属性之中, 每个 even ...

  3. [dataTables.js error] Uncaught TypeError: myTable.row is not a function

    使用dataTables.js时遇到的问题. 代码如下: var myTable = $('#dynamic-table') .dataTable({ bAutoWidth : false, &quo ...

  4. Creating HTML table with vertically oriented text as table header 表头文字方向

    AS an old question, this is more like info or reminder about vertical margin or padding in % that ta ...

  5. Java、fileless恶意软件威胁桌面安全

    工作原理:用户访问一个受侵的网站,不小心下载了最新类型的恶意软件.如果你的杀毒软件运行良好的话,就会阻止下载,至少能够检测到并隔离硬盘上的入侵文件.但是如果硬盘上没有文件监测呢?如果恶意软件只入侵内存 ...

  6. IO端口、IO内存、IO空间、内存空间的含义和联系

    1,IO空间:X86一个特有的空间,与内存空间独立的空间,同样利用IO空间可以操作数据,只不过是利用对应的IO端口操作函数,例如inb(), inbw(), inl(); outb(), outw() ...

  7. 简明Vim练级攻略(转载)

    前言 今天看到这篇文章,共鸣点非常多.它把Vim使用分为4个级别,目前我自己是熟练运用前面三级的命令,在培养习惯使用第四级.完全就是我这一年来坚持使用Vim的过程.所以不管怎么我要转载这篇文章.翻译自 ...

  8. JSP连接数据库的两种方式:Jdbc-Odbc桥和Jdbc直连(转)

    学JSP的同学都要知道怎么连数据库,网上的示例各有各的做法,弄得都不知道用谁的好.其实方法千变万化,本质上就两种:Jdbc-Odbc桥和Jdbc直连. 下面先以MySQL为例说说这两种方式各是怎么连的 ...

  9. linux下,一些关于动态库的问题:

    程序运行是加载动态库的几种方法: 第一种,通过ldconfig命令    ldconfig是一个动态链接库管理命令,为了让动态链接库为系统所共享,还需运行动态链接库的管理命令它,ldconfig命令通 ...

  10. PLSQL Developer连接远程Oracle方法(非安装客户端)

    Oracle比较麻烦,通常需要安装oracle的客户端才能实现.通过instantclient可以比较简单的连接远程的Oracle. 1.新建目录D:\Oracle_Cleint用于存放相关文件,新建 ...