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

 #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的更多相关文章

  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. grunt学习随笔

    1 grunt 安装  全局安装 npm install -g grunt-cli 2 配置好package.json 和 Gruntfile 文件,这两个文件必须位于项目根目录下. 2.1packa ...

  2. hdu_5963_朋友(找规律)

    题目链接:hdu_5963_朋友 题意: 中文,不解释 题解: 把样例拿出来看看,你会发现以x为节点是否能赢,就是与x相连的边权值的和或者异或是否为奇数. #include<bits/stdc+ ...

  3. 对一个表中所有列数据模糊查询adoquery

    如何用adoquery对一个表中所有列进行模糊查询: procedure TForm3.Button4Click(Sender: TObject); var ASql,AKey: string; I: ...

  4. NOIP2014-普及组复赛-第二题-比例简化

    题目描述 Description 在社交媒体上,经常会看到针对某一个观点同意与否的民意调查以及结果.例如,对某一观点表示支持的有1498 人,反对的有 902人,那么赞同与反对的比例可以简单的记为14 ...

  5. ios 将彩色照片转化成黑白等几种类型

    -(UIImage *)changeColoursImageTograyScaleImage:(UIImage *)anImage type:(int)type { CGImageRef imageR ...

  6. js自定义的简易滚动条

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  7. Python in minute

    Python 性能优化相关专题:    https://www.ibm.com/developerworks/cn/linux/l-cn-python-optim/   Python wikipedi ...

  8. linux命令英文缩写的含义(方便记忆)

    命令缩写: ls:list(列出目录内容) cd:Change Directory(改变目录) su:switch user 切换用户 rpm:redhat package manager 红帽子打包 ...

  9. iOS学习笔记(01) - 泛型

    决定新开一坑,在不断学习的同时分享自己的学习历程给大家,既是对自己学习的记录,又希望能对大家提供些微的帮助. 这一篇文章主要来介绍泛型的意义.使用与声明方法等. 1.泛型:限制类型 1.1.泛型使用场 ...

  10. php 创建文件

    $myfile = fopen("newfile.txt", "w") or die("Unable to open file!"); $t ...