【usaco 2012 Nov Bronze】找奶牛Find the Cow!

来源:互联网 发布:爱淘宝怎么注册账号 编辑:程序博客网 时间:2024/06/06 01:11
题目:

     奶牛贝里斯最近逃离了农夫约翰的农场躲在草丛里。于是,农夫约翰试图去找回他的奶牛。不幸的是,这些高高的草丛挡住了约翰的视线。现在,我们把这些草丛描述为一个长度为N的字符串,这个字符串只包含‘(’和‘)’这两种字符。例如,字符串:)((()())()) 。约翰知道贝里斯隐藏的前大腿很像连续的两个左括号((,隐藏的后大腿很像连续的两个右括号))。贝里斯的位置可以描述为:((的位置为X,))的位置为Y,并且X<Y。

问题描述:

     请帮助约翰计算贝里斯隐藏的地方有多少种可能。

题解

  枚举。

代码

var  s,t:ansistring;  a,b:array[1..500000] of longint;  i,l,r,j,sum,ans:longint;begin  assign(input,'cowfind.in');reset(input);  assign(output,'cowfind.out');rewrite(output);  readln(s);t:=s;  for i:=1 to length(s)-1 do    begin      t:=copy(s,i,2);      if t='((' then inc(ans);      if t='))' then sum:=sum+ans;    end;  writeln(sum);  close(input);close(output);end.

3 0