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]中任何时候举行,但是必须超过总时间的一半以上。
          小镇只有一位牧师,所有的祝福仪式都必须要他在场吗。同时,牧师必须在整数时刻开始或者结束祝福仪式,不过他可以在结束之后立刻开始另一场。
现在给你所有的婚礼的信息请问是否能够安排好一个祝福仪式的顺序,使得牧师能够给所有的新人带去幸福......
          现在给你所有婚礼的信息,请问是否能够安排好一个祝福仪式的顺序,使得牧师能够给所有新人带去幸福...
 
 
自己写了个搓代码:
先展示一下大神的代码把!...
然后再看弱屌的代码....
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. using namespace std;
  6. const int maxn = ;
  7. struct tnode
  8. {
  9. int s,e;
  10. int ms,me;
  11. int keyinterval;
  12. int id;
  13. }c[maxn];
  14.  
  15. bool operator < (const tnode &a , const tnode &b)
  16. {
  17. return (a.ms <b.ms ||(a.ms==b.ms&&a.me<b.me));
  18. }
  19. int n , i;
  20. void init()
  21. {
  22. for(i= ; i<n ;i++ ){
  23. scanf("%d%d",&c[i].s,&c[i].e);
  24. c[i].id=i;
  25. c[i].keyinterval = (c[i].e - c[i].s +)/ ;
  26. c[i].ms=c[i].s+(c[i].e - c[i].s -)/;
  27. c[i].me=c[i].s+;
  28. if((c[i].e-c[i].s)%==)
  29. ++c[i].me;
  30. }
  31. sort(c,c+n);
  32. }
  33. bool work()
  34. {
  35. int now_s , now_e ,last_e;
  36. last_e=;
  37. for(int i= ; i<n ;i++)
  38. {
  39. now_s =c[i].s;
  40. if(now_s<last_e) now_s=last_e;
  41. now_e=now_s+c[i].keyinterval;
  42. if(now_e>c[i].e) return false;
  43. last_e = now_e;
  44. }
  45. return true ;
  46. }
  47.  
  48. int main()
  49. {
  50. while(scanf("%d",&n),n!=)
  51. {
  52. init();
  53. if(work())
  54. printf("YES\n");
  55. else
  56. printf("NO\n");
  57. }
  58. return ;
  59. }

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

代码:

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<vector>
  5. #include<algorithm>
  6. using namespace std;
  7. const int maxn = ;
  8. struct tnode
  9. {
  10. int s,e;
  11. int ms,me;
  12. int keyinterval;
  13. int id;
  14. bool operator < (const tnode &b) const
  15. {
  16. return (ms <b.ms ||(ms==b.ms&&me<b.me));
  17. }
  18. };
  19.  
  20. int n , i;
  21. tnode cc;
  22. vector<tnode>c;
  23. void init()
  24. {
  25. c.clear();
  26. for(i= ; i<n ;i++ ){
  27. scanf("%d%d",&cc.s,&cc.e);
  28. cc.id=i;
  29. cc.keyinterval = (cc.e - cc.s +)/ ;
  30. cc.ms=cc.s+(cc.e - cc.s -)/;
  31. cc.me=cc.s+;
  32. if((cc.e-cc.s)%==)
  33. ++cc.me;
  34. c.push_back(cc);
  35. }
  36. sort(c.begin(),c.end());
  37. }
  38. bool work()
  39. {
  40. int now_s , now_e ,last_e;
  41. last_e=;
  42. for(int i= ; i<n ;i++)
  43. {
  44. now_s =c[i].s;
  45. if(now_s<last_e) now_s=last_e;
  46. now_e=now_s+c[i].keyinterval;
  47. if(now_e>c[i].e) return false;
  48. last_e = now_e;
  49. }
  50. return true ;
  51. }
  52.  
  53. int main()
  54. {
  55. while(scanf("%d",&n),n!=)
  56. {
  57. init();
  58. if(work())
  59. printf("YES\n");
  60. else
  61. printf("NO\n");
  62. }
  63. return ;
  64. }

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

代码:

手动的扩栈....

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

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<cstdlib>
  4. #include<iostream>
  5. #include<algorithm>
  6. #pragma comment(linker, "/STACK:102400000,102400000") //由于用内分装之后会出现溢栈的情况,所以手动扩栈
  7. using namespace std;
  8.  
  9. const int maxn = ;
  10.  
  11. struct tnode
  12. {
  13. int s,e;
  14. int ms,me;
  15. int mid;
  16. bool operator < (const tnode b) const
  17. {
  18. return (ms<b.ms||(ms==b.ms)&&me<b.me);
  19. }
  20. };
  21. class node
  22. {
  23. private:
  24. tnode str[maxn];
  25. int i;
  26. public :
  27. int n;
  28. void init();
  29. bool work();
  30. };
  31.  
  32. void node::init()
  33. {
  34. for(i=;i<n;i++)
  35. {
  36. scanf("%d%d",&str[i].s,&str[i].e) ;
  37. str[i].mid=(str[i].e-str[i].s)/ + ;
  38. str[i].ms= str[i].s+(str[i].e-str[i].s-)/ ;
  39. str[i].me=str[i].s+ ;
  40. if((str[i].e-str[i].s)%==) str[i].me++;
  41. }
  42. sort(str,str+n);
  43. }
  44. bool node::work()
  45. {
  46. int temp_s,temp_e,last_e=;
  47. for( i= ; i<n ; i++ )
  48. {
  49. temp_s=str[i].s;
  50. if(temp_s<last_e) temp_s=last_e;
  51. temp_e = temp_s+str[i].mid;
  52. if(temp_e>str[i].e) return false;
  53. last_e=temp_e;
  54. }
  55. return true ;
  56. }
  57. int main()
  58. {
  59. node a;
  60. while(scanf("%d",&a.n)!=EOF&&a.n)
  61. {
  62. a.init();
  63. if(a.work())printf("YES\n");
  64. else printf("NO\n");
  65. }
  66. return ;
  67. }
 
 

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. Java_GC详解

    Java -- GC 标签(空格分隔): Java 要想深入了解Java的GC(Garbage Collection),我们应该先探寻如下三个问题: What? -- 哪些内存需要回收? When? ...

  2. Java代码规范性

    ---------------------------------------------------------------------------------------------------- ...

  3. Servlet技术

    Java Applet和Java Servlet都有一个共同特点: 它们都不是独立的应用程序,都没有main( )方法: 它们都不是由用户或者程序员直接调用,而是生存在容器中,由容器管理,Applet ...

  4. servlet&jsp高级:第三部分

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  5. Servlet&jsp基础:第四部分

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  6. 使用escape编码地址栏中的中文字符

    在通过地址栏传递参数的时候,有时候会遇到中文参数,在获取这种中文参数值得时候, 往往会出现乱码, 解决办法如下: 在传递参数的使用 escape 函数进行编码,获取的时候再进行解码即可. 例如: va ...

  7. iOS - UIRefreshControl 刷新数据

    前言 NS_CLASS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED @interface UIRefreshControl : UIControl 1.UIRefresh ...

  8. Linux_常用命令_04_挂载

    1. mount [-t vfstype] [-o options] device dir ZC: -o 后面跟多个option的话,用逗号隔开.(例如:"mount -o rw,remou ...

  9. Android listview和ListAdapter搭配使用

    ListView时Android中自带的数据显示控件,要使用ListView填充数据,必须要通过适配器来填充,这里给大家介绍一下ListAdapter适配器,效果图如下: java源码: packag ...

  10. OpenGL的glPushMatrix和glPopMatrix矩阵栈顶操作函数详解

    OpenGL中图形绘制后,往往需要一系列的变换来达到用户的目的,而这种变换实现的原理是又通过矩阵进行操作的.opengl中的变换一般包括视图变换.模型变换.投影变换等,在每次变换后,opengl将会呈 ...