这类题一个操作增加多少,一个操作减少多少,求最少刚开始为多少,在中途不会出现负值,模拟一遍,用一个数记下最大的即可

  1. #include<cstdio>
  2. #include<cstring>
  3.  
  4. const int HASH=;
  5.  
  6. int n,num[],head[HASH],next[];
  7.  
  8. void insert(int s)
  9. {
  10. int h=num[s]%HASH;
  11. int u=head[h];
  12. while(u) u=next[u];
  13. next[s]=head[h];//原来的链表头成为s的next
  14. head[h]=s;//s成为head[h]的链表头
  15. }
  16.  
  17. int erase(int s)
  18. {
  19. int h=num[s]%HASH;
  20. int u=head[h];
  21. while(u)
  22. {
  23. if(num[u]==num[s])
  24. {
  25. num[u]=;
  26. return ;
  27. }
  28. u=next[u];
  29. }
  30. return ;
  31. }
  32.  
  33. int main()
  34. {
  35. while(scanf("%d",&n)==)
  36. {
  37. int x,cap=,j=,maxcap=;
  38. char op[];
  39. memset(head,,sizeof(head));
  40. for(int i=;i<=n;i++)
  41. {
  42. scanf("%s%d",op,&num[j]);
  43. if(op[]=='+')
  44. {
  45. insert(j);
  46. j++;
  47. cap++;
  48. //printf("cap=%d\n",cap);
  49. if(cap>maxcap) maxcap=cap;
  50. }
  51. else
  52. {
  53. if(erase(j)) cap--;
  54. else maxcap++;//在记下maxcap之前已经在里面
  55. //printf("cap=%d\n",cap);
  56. if(cap>maxcap) maxcap=cap;
  57. }
  58. }
  59. printf("%d\n",maxcap);
  60. }
  61. return ;
  62. }
  1. #include<cstdio>
  2. #include<cstring>
  3.  
  4. int T,n,a,b,L,cas=;
  5.  
  6. int main()
  7. {
  8. scanf("%d",&T);
  9. while(T--)
  10. {
  11. scanf("%d%d%d%d",&n,&a,&b,&L);
  12. int l,r,strength=,min=,last=;
  13. for(int i=;i<n;i++)
  14. {
  15. scanf("%d%d",&l,&r);
  16. strength+=b*(l-last)-a*(r-l);
  17. if(strength<min) min=strength;
  18. last=r;
  19. }
  20. printf("Case #%d: %d\n",cas++,-min);
  21. }
  22. return ;
  23. }

CodeForces 567B Berland National Library hdu-5477 A Sweet Journey的更多相关文章

  1. CodeForces 567B Berland National Library

    Description Berland National Library has recently been built in the capital of Berland. In addition, ...

  2. Codeforces B - Berland National Library

    B. Berland National Library time limit per test 1 second memory limit per test 256 megabytes input s ...

  3. HDU 5477 A Sweet Journey 水题

    A Sweet Journey Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...

  4. HDU 5477: A Sweet Journey

    A Sweet Journey Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  5. Codeforces 567B:Berland National Library(模拟)

    time limit per test : 1 second memory limit per test : 256 megabytes input : standard input output : ...

  6. Codeforces Round #Pi (Div. 2) B. Berland National Library set

    B. Berland National LibraryTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...

  7. Codeforces Round #Pi (Div. 2) B. Berland National Library 模拟

    B. Berland National LibraryTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

  8. 构造 Codeforces Round #Pi (Div. 2) B. Berland National Library

    题目传送门 /* 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况 ...

  9. Codeforces Round #Pi (Div. 2) B Berland National Library

    B. Berland National Library time limit per test1 second memory limit per test256 megabytes inputstan ...

随机推荐

  1. PerformSelector 和 NSInvocation

  2. TimeJob权限问题 拒绝访问

    internal void RenameWithoutValidation(string value) {     if (value == null) throw new ArgumentNullE ...

  3. 在CentOS linux上通过yum安装JDK<转>

    卸载centos自带的jdk 1.查看当前的jdk版本,并卸载 [root@localhost opt]#  rpm -qa|grep java  java-1.6.0-openjdk-1.6.0.3 ...

  4. 移动前端不得不了解的HTML5 head 头标签(中上篇)

    Meta 标签 meta标签是HTML中head头部的一个辅助性标签,它位于HTML文档头部的 <head> 和 <title> 标记之间,它提供用户不可见的信息.虽然这部分信 ...

  5. H5加载优化

  6. Redis简介一

    Redis是一个开源的,使用C语言编写,面向“键/值”对类型数据的分布式NoSQL数据库系统,特点是高性能,持久存储,适应高并发的应用场景.Redis纯粹为应用而产生,它是一个高性能的key-valu ...

  7. OC-之AFNetworking与ASIHTTPRequest对比

    一.底层实现 1.AFN的底层实现基于OC的NSURLConnection和NSURLSession 2.ASI的底层实现基于纯C语言的CFNetwork框架 3.因为NSURLConnection和 ...

  8. Activity LauchMode启动模式(转载)

    转载于:http://www.cnblogs.com/plokmju/p/android_ActivityLauncherMode.html 在一个Android应用中,不可避免的会包含多个Activ ...

  9. HDU 5755 Gambler Bo

    可以设n*m个未知量,建立n*m个方程.位置i,j可以建立方程 (2*x[i*m+j]+x[(i-1)*m+j]+x[(i+1)*m+j]+x[i*m+j-1]+x[i*m+j+1])%3=3-b[i ...

  10. c语言_头文件

    传统 C++ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #include <assert.h> //设定插入点 #include <ctyp ...