[Ahoi2009]fly 飞行棋

Time Limit: 10 Sec    Memory Limit: 64 MB

Description

给出圆周上的若干个点,已知点与点之间的弧长,其值均为正整数,并依圆周顺序排列。请找出这些点中有没有可以围成矩形的,并希望在最短时间内找出所有不重复矩形。

Input

第一行为正整数N,表示点的个数,接下来N行分别为这N个点所分割的各个圆弧长度

Output

所构成不重复矩形的个数

Sample Input

8
1
2
2
3
1
1
3
3


Sample Output

3

HINT

N<= 20
[Ahoi2009]fly <wbr>飞行棋

 

看完题目我震惊了。。省选竟然会出暴力瞬秒题。。。

一开始,我想到的是枚举两个点,是的它们的连线是圆的一条直径。然后递推两个顶点找到另外的直径,就能构成矩形。O(N*N)

然后,看到范围。。。我震惊了。。。直接暴力枚举四个点盼矩形。。。

最后,想到只要找到直径的总数m,然后直接算就可以了。。。m*(m-1)/2。

 

AC CODE

 

program hy_1800;
var a: array [ 1..40 ] of longint ;
     n,i,now,c,h,s,t,en,ans: longint ;
begin
   readln(n);
   for i:= 1 to n do
   begin
     readln(a[i]);
     a[n+ 1 ]:=a[i]; c:=c+a[i];
   end ;
   h:=c div 2 ;
   if c* 2 <h then
   begin
     writeln ( '0' ); halt;
   end ;
   s:= 1 ; t:= 0 ;
   while now+a[t+ 1 ]<=h do
   begin
     now:=a[t+ 1 ]+now; inc(t);
   end ;
   if s>t then
   begin
     writeln ( '0' );
     halt;
   end ;
   if now=h then inc(ans);
   if now=h then en:=t else en:=t+ 1
   while s<en do
   begin
     now:=now-a[s]; inc(s);
     while now+a[t+ 1 ]<=h do
     begin
       now:=a[t+ 1 ]+now; inc(t);
     end ;
     if now=h then inc(ans);
     if t<s then
     begin
       writeln ( '0' );
       halt;
     end ;
   end ;
   writeln ((ans*(ans- 1 )) shr 1 );
end .
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值