题目链接: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)的更多相关文章

  1. nyoj 168 房间安排(区间覆盖)

    房间安排 时间限制:3000 ms  |  内存限制:65535 KB 难度:2   描述 2010年上海世界博览会(Expo2010),是第41届世界博览会.于2010年5月1日至10月31日期间, ...

  2. ACM 房间安排

    房间安排 时间限制:3000 ms  |  内存限制:65535 KB 难度:2   描述 2010年上海世界博览会(Expo2010),是第41届世界博览会.于2010年5月1日至10月31日期间, ...

  3. ny168 房间安排

    房间安排 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述 2010年上海世界博览会(Expo2010),是第41届世界博览会.于2010年5月1日至10月31日期间,在中 ...

  4. [河南省ACM省赛-第三届] 房间安排 (nyoj 168)

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=168 分析:找到一天中需要最多的房间即可 #include<iostream> ...

  5. NYOJ题目168房间安排

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAssAAAOTCAIAAADGwNmiAAAgAElEQVR4nOy9PY7cyLPufTchXwsZu9

  6. 房间安排-nyoj168

    描述 2010年上海世界博览会(Expo2010),是第41届世界博览会.于2010年5月1日至10月31日期间,在中国上海市举行.本次世博会也是由中国举办的首届世界博览会.上海世博会以“城市,让生活 ...

  7. [原]NYOJ-房间安排168

    大学生程序代写 /*房间安排 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述 2010年上海世界博览会(Expo2010),是第41届世界博览会.于2010年5月1日至1 ...

  8. The Accomodation of Students HDU - 2444 二分图判定 + 二分图最大匹配 即二分图-安排房间

    /*655.二分图-安排房间 (10分)C时间限制:3000 毫秒 |  C内存限制:3000 Kb题目内容: 有一群学生,他们之间有的认识有的不认识.现在要求把学生分成2组,其中同一个组的人相互不认 ...

  9. 【南阳OJ分类之语言入门】80题题目+AC代码汇总

    小技巧:本文之前由csdn自动生成了一个目录,不必下拉一个一个去找,可通过目录标题直接定位. 本文转载自本人的csdn博客,复制过来的,排版就不弄了,欢迎转载. 声明: 题目部分皆为南阳OJ题目. 代 ...

随机推荐

  1. python中列表和元组的操作(结尾格式化输出小福利)

    一. 列表 1. 查 names = "YanFeixu WuYifan" names_1 = ["YanFeixu"," WuYifan" ...

  2. 图片路径转base64字节码

    package product; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOE ...

  3. Advances in Single Cell Genomics to Study Brain Cell Types | 会议概览

    单细胞在脑科学方面的应用 Session 1: Deciphering the Cellular Landscape of the Brain Using Single Cell Transcript ...

  4. WPF打印涉及到的关键类

    DocumentViewer--->FixedDocument----> PageContent  ---->FixedPage

  5. 字符串hash

    hash[i]=(hash[i-1]*p+idx(s[i]))%mod p和mod取不同的较大的素数

  6. 1. windows 下redis数据库的安装

    安装 window系统的redis是微软团队根据官方的linux版本高仿的 官方原版: https://redis.io/ 中文官网:http://www.redis.cn 下载地址: https:/ ...

  7. scrapy 爬虫框架(一)

    一 . scrapy 的安装 安装scrapy框架时,需要先安装依赖包. #Linux: pip3 install scrapy #Windows: a. pip3 install wheel b. ...

  8. 【洛谷p1106】删数问题

    (洛谷t2755暂时过不去了) 删数问题[传送门] 洛谷算法标签: emmmm……删数问题又牵扯到了字符串.因为毕竟高精度的数240位呢!要是输入一个整型,要码240行来求出每一位……怕是还没求出来就 ...

  9. Python 2.7.x 使用Requests发起https请求时报Warning的问题

    warning :如下 /usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/connectionpool.py:852: ...

  10. GIL锁,线程池

    内容梗概: 1.线程队列 2.线程池 3.GIL锁 1.线程队列 1.1先进先出队列(FIFO)import queueq = queue.Queue(3)q.put(1)q.put(2)q.put( ...