CodeForces 567B Berland National Library hdu-5477 A Sweet Journey
这类题一个操作增加多少,一个操作减少多少,求最少刚开始为多少,在中途不会出现负值,模拟一遍,用一个数记下最大的即可
- #include<cstdio>
- #include<cstring>
- const int HASH=;
- int n,num[],head[HASH],next[];
- void insert(int s)
- {
- int h=num[s]%HASH;
- int u=head[h];
- while(u) u=next[u];
- next[s]=head[h];//原来的链表头成为s的next
- head[h]=s;//s成为head[h]的链表头
- }
- int erase(int s)
- {
- int h=num[s]%HASH;
- int u=head[h];
- while(u)
- {
- if(num[u]==num[s])
- {
- num[u]=;
- return ;
- }
- u=next[u];
- }
- return ;
- }
- int main()
- {
- while(scanf("%d",&n)==)
- {
- int x,cap=,j=,maxcap=;
- char op[];
- memset(head,,sizeof(head));
- for(int i=;i<=n;i++)
- {
- scanf("%s%d",op,&num[j]);
- if(op[]=='+')
- {
- insert(j);
- j++;
- cap++;
- //printf("cap=%d\n",cap);
- if(cap>maxcap) maxcap=cap;
- }
- else
- {
- if(erase(j)) cap--;
- else maxcap++;//在记下maxcap之前已经在里面
- //printf("cap=%d\n",cap);
- if(cap>maxcap) maxcap=cap;
- }
- }
- printf("%d\n",maxcap);
- }
- return ;
- }
- #include<cstdio>
- #include<cstring>
- int T,n,a,b,L,cas=;
- int main()
- {
- scanf("%d",&T);
- while(T--)
- {
- scanf("%d%d%d%d",&n,&a,&b,&L);
- int l,r,strength=,min=,last=;
- for(int i=;i<n;i++)
- {
- scanf("%d%d",&l,&r);
- strength+=b*(l-last)-a*(r-l);
- if(strength<min) min=strength;
- last=r;
- }
- printf("Case #%d: %d\n",cas++,-min);
- }
- return ;
- }
CodeForces 567B Berland National Library hdu-5477 A Sweet Journey的更多相关文章
- CodeForces 567B Berland National Library
Description Berland National Library has recently been built in the capital of Berland. In addition, ...
- Codeforces B - Berland National Library
B. Berland National Library time limit per test 1 second memory limit per test 256 megabytes input s ...
- HDU 5477 A Sweet Journey 水题
A Sweet Journey Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 5477: A Sweet Journey
A Sweet Journey Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- Codeforces 567B:Berland National Library(模拟)
time limit per test : 1 second memory limit per test : 256 megabytes input : standard input output : ...
- 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 ...
- Codeforces Round #Pi (Div. 2) B. Berland National Library 模拟
B. Berland National LibraryTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...
- 构造 Codeforces Round #Pi (Div. 2) B. Berland National Library
题目传送门 /* 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况 ...
- Codeforces Round #Pi (Div. 2) B Berland National Library
B. Berland National Library time limit per test1 second memory limit per test256 megabytes inputstan ...
随机推荐
- PerformSelector 和 NSInvocation
- TimeJob权限问题 拒绝访问
internal void RenameWithoutValidation(string value) { if (value == null) throw new ArgumentNullE ...
- 在CentOS linux上通过yum安装JDK<转>
卸载centos自带的jdk 1.查看当前的jdk版本,并卸载 [root@localhost opt]# rpm -qa|grep java java-1.6.0-openjdk-1.6.0.3 ...
- 移动前端不得不了解的HTML5 head 头标签(中上篇)
Meta 标签 meta标签是HTML中head头部的一个辅助性标签,它位于HTML文档头部的 <head> 和 <title> 标记之间,它提供用户不可见的信息.虽然这部分信 ...
- H5加载优化
- Redis简介一
Redis是一个开源的,使用C语言编写,面向“键/值”对类型数据的分布式NoSQL数据库系统,特点是高性能,持久存储,适应高并发的应用场景.Redis纯粹为应用而产生,它是一个高性能的key-valu ...
- OC-之AFNetworking与ASIHTTPRequest对比
一.底层实现 1.AFN的底层实现基于OC的NSURLConnection和NSURLSession 2.ASI的底层实现基于纯C语言的CFNetwork框架 3.因为NSURLConnection和 ...
- Activity LauchMode启动模式(转载)
转载于:http://www.cnblogs.com/plokmju/p/android_ActivityLauncherMode.html 在一个Android应用中,不可避免的会包含多个Activ ...
- 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 ...
- c语言_头文件
传统 C++ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #include <assert.h> //设定插入点 #include <ctyp ...