hdu-----2491Priest John's Busiest Day(2008 北京现场赛G)
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
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.
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)
4
#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)的更多相关文章
- HDUOJ-------2493Timer(数学 2008北京现场赛H题)
Timer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- HDUOJ--------A simple stone game(尼姆博弈扩展)(2008北京现场赛A题)
A simple stone game ...
- HDUOJ----2485 Destroying the bus stations(2008北京现场赛A题)
Destroying the bus stations ...
- HDU 5122 K.Bro Sorting(2014北京区域赛现场赛K题 模拟)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5122 解题报告:定义一种排序算法,每一轮可以随机找一个数,把这个数与后面的比这个数小的交换,一直往后判 ...
- HDU 5119 Happy Matt Friends(2014北京区域赛现场赛H题 裸背包DP)
虽然是一道还是算简单的DP,甚至不用滚动数组也能AC,数据量不算很大. 对于N个数,每个数只存在两个状态,取 和 不取. 容易得出状态转移方程: dp[i][j] = dp[i - 1][j ^ a[ ...
- hdu 5038 (2014北京网络赛G 排序水题)
题意:有n个数字,带入10000 - (100 - ai) ^ 2公式得到n个数,输出n个数中频率最大的数,如果有并列就按值从小到大都输出输出,如果频率相同的数字是全部的n个数,就输出Bad....题 ...
- hdu 5120(求两个圆环相交的面积 2014北京现场赛 I题)
两个圆环的内外径相同 给出内外径 和 两个圆心 求两个圆环相交的面积 画下图可以知道 就是两个大圆交-2*小圆与大圆交+2小圆交 Sample Input22 30 00 02 30 05 0 Sam ...
- hdu 5122 (2014北京现场赛 K题)
把一个序列按从小到大排序 要执行多少次操作 只需要从右往左统计,并且不断更新最小值,若当前数为最小值,则将最小值更新为当前数,否则sum+1 Sample Input255 4 3 2 155 1 2 ...
- hdu 5112 (2014北京现场赛 A题)
给出某个时刻对应的速度 求出相邻时刻的平均速度 输出最大值 Sample Input23 // n2 2 //t v1 13 430 31 52 0 Sample OutputCase #1: 2.0 ...
随机推荐
- [POJ1753]Flip Game(异或方程组,高斯消元,枚举自由变量)
题目链接:http://poj.org/problem?id=1753 题意:同上. 这回翻来翻去要考虑自由变元了,假设返回了自由变元数量,则需要枚举自由变元. /* ━━━━━┒ギリギリ♂ eye! ...
- 【Protle99SE】PCB中各层的含义【小汇】
忽然发现,对solder和paste,layer和plane这两对有些糊涂了,摘录网络中的文章如下: [http://www.360doc.com/content/10/0608/15/514342_ ...
- 安全漏洞API接口
这个是avfisherapi写的API,经常用,每次找他的博客都搜到AV,尴尬..在这里记下来. 0x01 查询最新安全事件和漏洞的接口 接口URL: 乌云网: http://avfisherapi. ...
- firefox 安装flash插件
第一步下载并解压flash解压出一个文件:libflashplayer.so 和文件夹usr 第二步查找plugins其他程序或许也有这个文件夹所以先查找firefox在查找mozilla看在哪个文件 ...
- 函数(def)
一.为什么要使用函数: 面向过程的编程在代码里有很多代码是可以重复利用的,如果使用面向过程编程会使代码显得纷繁复杂,不利于他人和自己日后的阅读.而在函数式编程里,则可以把每个可重复利用的功能封装在一个 ...
- 异步上传图片,光用jquery不行,得用jquery.form.js插件
异步上传图片,光用jquery不行,得用jquery.form.js插件,百度一下下载这个插件,加jquery,引入就可以了 <form id="postbackground" ...
- WdatePicker.js 日历点击时,触发自定义方法 ,可以调用自己的函数。
问题: 在选择日期后,没有提交按钮,得到日期后,就可以把日期传到后台,然后就可以得到数据. 方法: 在input 标签中加入onfocus ,就可以了. wdatePicker();可以自定义事件函数 ...
- js 监听监键盘动作(转)
主要分四个部分 第一部分:浏览器的按键事件 第二部分:兼容浏览器 第三部分:代码实现和优化 第四部分:总结 第一部分:浏览器的按键事件 用js实现键盘记录,要关注浏览器的三种按键事件类型,即keydo ...
- iOS - OC NSKeyedArchiver 数据归档
前言 @interface NSKeyedArchiver : NSCoder @interface NSKeyedUnarchiver : NSCoder 在 OC 语言中,归档是一个过程,即用某种 ...
- 常用的 文件 MIME类型
估计很多朋友对不同后缀的文件对应的MIME类型不熟悉(实际上这么多我也记不住), 所以将平常常见的一些文件后缀对应的MIME类型写了一个对照表,现在奉献给大家: .asx,video/x-ms-asf ...