1800: [Ahoi2009]fly 飞行棋
来源:互联网 发布:免费域名注册永久 编辑:程序博客网 时间:2024/05/29 12:24
1800: [Ahoi2009]fly 飞行棋
Description
给出圆周上的若干个点,已知点与点之间的弧长,其值均为正整数,并依圆周顺序排列。 请找出这些点中有没有可以围成矩形的,并希望在最短时间内找出所有不重复矩形。
Input
第一行为正整数N,表示点的个数,接下来N行分别为这N个点所分割的各个圆弧长度
Output
所构成不重复矩形的个数
Sample Input
8
1
2
2
3
1
1
3
3
1
2
2
3
1
1
3
3
Sample Output
3
HINT
N<= 20
题解:
确实是一道水题(n<=20),但是此题枚举的细节确实很多,这里介绍一种比较好理解的方法(速度也超快)首先,设tot为a数组的总和,若tot是奇数那么肯定无解。
然后我们再在数组中找一段连续的数和为tot/2的数量,由于和为tot/2,所以相邻两端数会有连续(为了避免差为0,所以只在1~n-1中找),而且刚好构成一个矩形(画画图就知道了)
#include<stdio.h>#include<iostream>#include<algorithm>#include<string.h>using namespace std;int i,j,n,s,x,ans,a[25];int b,c,d,e;int main(){ scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",&a[i]); s=0; for(i=1;i<=n;i++) s+=a[i]; if(s&1) { printf("0"); return 0; } s/=2; x=0;j=1; ans=0; for(i=1;i<n;i++) { x+=a[i]; while(x>s) { x-=a[j]; j++; } if(x==s) ans++; } cout<<ans*(ans-1)/2; return 0;}
0 0
- 1800: [Ahoi2009]fly 飞行棋
- 1800: [Ahoi2009]fly 飞行棋
- 1800: [Ahoi2009]fly 飞行棋
- 1800: [Ahoi2009]fly 飞行棋
- 1800: [Ahoi2009]fly 飞行棋
- bzoj 1800 [Ahoi2009] fly 飞行棋
- BZOJ 1800 AHOI2009 fly 飞行棋 暴力
- BZOJ 1800 [Ahoi2009]fly 飞行棋
- 【BZOJ 1800】[Ahoi2009]fly 飞行棋
- bzoj 1800: [Ahoi2009]fly 飞行棋
- BZOJ 1800: [Ahoi2009]fly 飞行棋
- [Ahoi2009]fly 飞行棋
- 【BZOJ1800】【Ahoi2009】fly 飞行棋
- [BZOJ1800][Ahoi2009]fly飞行棋
- 【AHOI2009】【BZOJ1800】fly 飞行棋
- [BZOJ1800] [Ahoi2009]fly 飞行棋
- BZOJ1800: [Ahoi2009]fly 飞行棋
- bzoj1800: [Ahoi2009]fly 飞行棋
- linux中Makefile详细介绍
- Iterator
- 裁减网格纸(贪心)
- iOS基础:NSDictionary常用方法
- HDU-1950(LCS)(Bridging signals)
- 1800: [Ahoi2009]fly 飞行棋
- HDOJ(HDU) 1862 EXCEL排序(类对象的快排)
- 装饰大楼 NOIP2015模拟11.3
- 如何查看端口被占用
- 一个Sqrt函数引发的血案
- LeetCode[Design]----Peeking Iterator
- 开发中常用的BaseActivity基类
- poj 2084 Game of Connections (卡特兰数,大数乘除)
- 浅谈Web安全-SQL注入