[河南省ACM省赛-第三届] 房间安排 (nyoj 168)
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=168
分析:找到一天中需要最多的房间即可
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define N 200
int day[N];//day[i] 第i天的最多房间数
int main()
{
freopen("d:\\in.txt", "r", stdin);
int t, n;
scanf("%d", &t);
while(t--){
memset(day, , sizeof(day));
scanf("%d", &n);
int num, start, length;
; i<n; i++){
scanf("%d%d%d", &num, &start, &length);
; i<length; i++){
day[i+start] += num;
}
}
;
; i<N; i++){
ans = max(ans, day[i]);
}
printf("%d\n", ans);
}
;
}
看别人题解后才明白的,同时记录下自己的模拟算法(TimeLimitExceeded)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
#define INPUT freopen("d:\\in.txt", "r", stdin);
#define N 10002
struct Node {
int a, b, v;
}c[N];
bool cmp(Node n1, Node n2)
{
return n1.a != n2.a ? n1.a < n2.a : n1.b < n2.b;
}
int main()
{
INPUT;
int t, n;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
int day;
; i<n; i++){
scanf("%d%d%d", &c[i].v, &c[i].a, &day);
c[i].b = c[i].a+day;
}
sort(c, c+n, cmp);
].v;
; i<n; i++){
int cur = c[i].v;
ans += cur;
; j<i; j++){
if(c[j].v && cur && c[j].b <= c[i].a){//如果 j团有剩余房间 且 当前订单还需要房间 且j团已离开
int reuse = min(c[j].v, cur);
ans -= reuse;
c[j].v -= reuse;
cur -= reuse;
}
}
}
printf("%d\n", ans);
}
;
}
[河南省ACM省赛-第三届] 房间安排 (nyoj 168)的更多相关文章
- [河南省ACM省赛-第三届] 素数 (nyoj 169)
#include <iostream> #include <cstdio> #include <queue> #include <cstring> #i ...
- [河南省ACM省赛-第三届] AMAZING AUCTION (nyoj 251)
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=251 规则: 1.若某竞标价唯一,则胜出 2.若不存在唯一竞标价,则投标次数最少竞标价中标 ...
- [河南省ACM省赛-第三届] 网络的可靠性 (nyoj 170)
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=170 根据题意,需要找到度数为1的结点个数,如下图: #include<iostre ...
- [河南省ACM省赛-第三届] 聪明的kk (nyoj 171)
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=171 动态规划: d(i,j) = max{d(i-1, j), d(i, j-1)}+m ...
- [河南省ACM省赛-第三届] BUYING FEED (nyoj 248)
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> us ...
- [河南省ACM省赛-第四届] 序号互换 (nyoj 303)
相似与27进制的转换 #include<iostream> #include<cstdio> #include<cstring> #include<strin ...
- [河南省ACM省赛-第四届] 表达式求值(nyoj 305)
栈的模拟应用: #include<iostream> #include<cstdio> #include<cstring> #include<string&g ...
- Mine Number(搜索,暴力) ACM省赛第三届 G
Mine Number Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Every one once played the gam ...
- ACM 房间安排
房间安排 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 2010年上海世界博览会(Expo2010),是第41届世界博览会.于2010年5月1日至10月31日期间, ...
随机推荐
- start running 开始跑步减肥
begin 两个月前,逛超市的时候站在体重秤上称了称,一直以为自己体重很正常(BMI<25,虽然也不轻~~~),结果直接迈过超重,奔着肥胖跑去了(BMI>30,BMI计算器 http:// ...
- 业务类接口在TCP,HTTP,BLL模式下的实例 设计模式混搭 附源码一份
业务类接口在TCP,HTTP,BLL模式下的实例 设计模式混搭 附源码一份 WinForm酒店管理软件--框架这篇随笔可以说是我写的最被大家争议的随笔,一度是支持和反对是一样的多.大家对我做的这个行业 ...
- PL/SQL配置大小写转换等快捷键
Tools(工具) --> Preferences(首选项) --> Key Configuration(键配置) 然后修改自己需要的快捷键方式 作者:itmyhome
- C#实战Microsoft Messaging Queue(MSMQ)
C#实战Microsoft Messaging Queue(MSMQ)消息队列(干货) 前言 在使用MSMQ之前,我们需要自行安装消息队列组件!(具体安装方法大家自己搜一下吧) 采用MSMQ带来的好处 ...
- CSS3 3D笨蛋教程
英文原文An Introduction to CSS 3-D Transforms 爱因斯坦说所有概念都必须介绍给儿童们,若他们无法了解,这些理论就毫无价值. 透视 一个元素需要一个透视点才能激活3D ...
- C#代码搜索器
WEBUS2.0 In Action - [源代码] - C#代码搜索器 最近由于工作的需要, 要分析大量C#代码, 在数万个cs文件中搜索特定关键词. 这是一项非常耗时的工作, 用Notepad++ ...
- lua脚本中字符串分割split
function split( s, c ) for item in string.gmatch( s, "(.-)"..c) do print(item); end end s ...
- Kattis - Aaah!
Aaah! Photo by Unknown Jon Marius shouted too much at the recent Justin Bieber concert, and now need ...
- Selenium WebDriver多层表单切换
[Java] 首先 测试网站frame结构为 -topframe: -centerframe: -leftframe: -mainframe: -bottomframe: 我当时遇到的问题是,首先在c ...
- python——爬虫
网络爬虫(又被称为网页蜘蛛,网络机器人,在FOAF社区中间,更经常的称为网页追逐者),是一种按照一定的规则,自动地抓取万维网信息的程序或者脚本.另外一些不常使用的名字还有蚂蚁.自动索引.模拟程序或者蠕 ...