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

  1. [河南省ACM省赛-第三届] 素数 (nyoj 169)

    #include <iostream> #include <cstdio> #include <queue> #include <cstring> #i ...

  2. [河南省ACM省赛-第三届] AMAZING AUCTION (nyoj 251)

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=251 规则: 1.若某竞标价唯一,则胜出 2.若不存在唯一竞标价,则投标次数最少竞标价中标 ...

  3. [河南省ACM省赛-第三届] 网络的可靠性 (nyoj 170)

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=170 根据题意,需要找到度数为1的结点个数,如下图: #include<iostre ...

  4. [河南省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 ...

  5. [河南省ACM省赛-第三届] BUYING FEED (nyoj 248)

    #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> us ...

  6. [河南省ACM省赛-第四届] 序号互换 (nyoj 303)

    相似与27进制的转换 #include<iostream> #include<cstdio> #include<cstring> #include<strin ...

  7. [河南省ACM省赛-第四届] 表达式求值(nyoj 305)

    栈的模拟应用: #include<iostream> #include<cstdio> #include<cstring> #include<string&g ...

  8. Mine Number(搜索,暴力) ACM省赛第三届 G

    Mine Number Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Every one once played the gam ...

  9. ACM 房间安排

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

随机推荐

  1. linux 安装svn,并设置钩子来同步更新

    linux安装svn下载 http://subversion.tigris.org/downloads/subversion-1.6.6.tar.gz 和 http://subversion.tigr ...

  2. 关于Jquery 序列化表单的注意事项

    在JQuery 的serialize方法序列化表单的过程中,如果表单的name值最后有空格,会出现“+”号,查源码可见原因.这一小问题就浪费了半小时的时间,记录下来,备忘.

  3. ASP.NET MVC3开发 - CodeFisrt数据库篇之M层验证之调用远程方法(Remote)验证

    本文讲述在作者在使用.net mvc3进行开发的时候用到的两种调用远程验证的方法,第一种方法比较傻瓜,第二种方法方便好用,调用远程验证是个比较常见的验证方法,比如注册用户时的用户名唯一性验证. 作者原 ...

  4. jQuery中delegate与on的用法与区别

    在jQuery1.7中 .delegate()已被.on()取代.对于早期版本,它仍然使用事件委托的最有效手段. 在事件绑定和委派,delegate()和on在一般情况下,这两种方法是等效的. .de ...

  5. Android Widget(窗口小部件)

    Android Widget简介 应用程序窗口小部件(Widget)是微型的应用程序视图,它可以被嵌入到其它应用程序中(比如桌面)并接收周期性的更新.你可以通过一个App Widget Provide ...

  6. SQL Server中的高可用性1

    SQL Server中的高可用性(1)----高可用性概览   自从SQL Server 2005以来,微软已经提供了多种高可用性技术来减少宕机时间和增加对业务数据的保护,而随着SQL Server ...

  7. .NET中 类型,对象,线程栈,托管堆在运行时的关系

    .NET中 类型,对象,线程栈,托管堆在运行时的关系 The Relationship at Run Time between Types,Objects,A Thread's Stack,and T ...

  8. 抛掉kendoUI的MultiSelect,自己实现 DropDownList MultiSelect

    我们首先来看下kendoUI官方的下拉框多选: 再来看看telerik RadControls的下拉框多选: 很明显从展现形式上来看,第二种是优于第一种的,至少我是这么认为的 :-) 那我们就对Dro ...

  9. 采用SOLR进行全文索引的完整解决方案,设计图

  10. Python自动化测试 -ConfigParser模块读写配置文件

    C#之所以容易让人感兴趣,是因为安装完Visual Studio, 就可以很简单的直接写程序了,不需要做如何配置. 对新手来说,这是非常好的“初体验”, 会激发初学者的自信和兴趣. 而有些语言的开发环 ...