房间安排 (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;
for(int i=; i<n; i++){
scanf("%d%d%d", &num, &start, &length);
for(int i=; i<length; i++){
day[i+start] += num;
}
}
int ans = ;
for(int i=; i<N; i++){
ans = max(ans, day[i]);
}
printf("%d\n", ans);
} return ;
}
看别人题解后才明白的,同时记录下自己的模拟算法(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;
for(int i=; 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);
int ans = c[].v;
for(int i=; i<n; i++){
int cur = c[i].v;
ans += cur;
for(int j=; 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);
}
return ;
}
房间安排 (nyoj 168)的更多相关文章
- nyoj 168 房间安排(区间覆盖)
房间安排 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 2010年上海世界博览会(Expo2010),是第41届世界博览会.于2010年5月1日至10月31日期间, ...
- ACM 房间安排
房间安排 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 2010年上海世界博览会(Expo2010),是第41届世界博览会.于2010年5月1日至10月31日期间, ...
- ny168 房间安排
房间安排 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 2010年上海世界博览会(Expo2010),是第41届世界博览会.于2010年5月1日至10月31日期间,在中 ...
- [河南省ACM省赛-第三届] 房间安排 (nyoj 168)
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=168 分析:找到一天中需要最多的房间即可 #include<iostream> ...
- NYOJ题目168房间安排
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAssAAAOTCAIAAADGwNmiAAAgAElEQVR4nOy9PY7cyLPufTchXwsZu9
- 房间安排-nyoj168
描述 2010年上海世界博览会(Expo2010),是第41届世界博览会.于2010年5月1日至10月31日期间,在中国上海市举行.本次世博会也是由中国举办的首届世界博览会.上海世博会以“城市,让生活 ...
- [原]NYOJ-房间安排168
大学生程序代写 /*房间安排 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 2010年上海世界博览会(Expo2010),是第41届世界博览会.于2010年5月1日至1 ...
- The Accomodation of Students HDU - 2444 二分图判定 + 二分图最大匹配 即二分图-安排房间
/*655.二分图-安排房间 (10分)C时间限制:3000 毫秒 | C内存限制:3000 Kb题目内容: 有一群学生,他们之间有的认识有的不认识.现在要求把学生分成2组,其中同一个组的人相互不认 ...
- 【南阳OJ分类之语言入门】80题题目+AC代码汇总
小技巧:本文之前由csdn自动生成了一个目录,不必下拉一个一个去找,可通过目录标题直接定位. 本文转载自本人的csdn博客,复制过来的,排版就不弄了,欢迎转载. 声明: 题目部分皆为南阳OJ题目. 代 ...
随机推荐
- laravel配置路由除了 / 都是404解决办法
1.php.ini开启phpopenssl 2.conf (nginx为例) location / { index index.html index.htm index.php l.php; #tr ...
- linux常用命令及系统常见符号
常用命令 1.start x 进入界面 2.shutdown -h now 立刻关机 shutdown -r now 立刻重新启动 reboot 立刻重新启动 3.su root 切换成超级管理员 4 ...
- English trip V1 - B 15. Giving Personal Information 提供个人信息 Teacher:Solo Key: Do/Does
In this lesson you will learn to answer simple questions about yourself. 本节课讲学到回答关于自己的一些简单问题 课上内容(L ...
- 20170907wdVBA_ImportPicturesBaseOnExcel
Public Sub ImportPicturesBaseOnExcel() Dim shp As Object Dim xlApp As Object Dim Wb As Object Dim Rn ...
- yarn基础解释
https://yarnpkg.com/zh-Hans/docs Yarn 对你的代码来说是一个包管理器, 你可以通过它使用全世界开发者的代码,或者分享自己的代码. 代码通过包(package)(或者 ...
- mat 使用 分析 oom 使用 Eclipse Memory Analyzer 进行堆转储文件分析
概述 对于大型 JAVA 应用程序来说,再精细的测试也难以堵住所有的漏洞,即便我们在测试阶段进行了大量卓有成效的工作,很多问题还是会在生产环境下暴露出来,并且很难在测试环境中进行重现.JVM 能够记录 ...
- Roman To Integer leetcode java
问题描述: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range fr ...
- python记录_day17 类与类之间的关系
一.依赖关系 a类的对象是b类方法的参数 这种关系是我用着你,但你不属于我,比如公司和临时工的关系,是很弱的一种关系 class Zhiwu: def __init__(self,name,atk): ...
- hdu-4738-tarjin/割边
http://acm.hdu.edu.cn/showproblem.php?pid=4738 求得是边权最小的割边,和求割点类似用tarjin,但要注意的是不能走从父亲过来的那一条边,在割点里那样理解 ...
- mybatis的update使用选择
更新后台设置时,会分多个页面更新同一个表中的数据,愿想是尽量减少sql请求数据量并且减少重复代码. 比如博客园的: 假如只有一个用户信息表,这样的话每个页面只更新部分字段. 这种情况下的更新推荐在xm ...