B1800 [Ahoi2009]fly 飞行棋 数学模拟
20分钟一遍AC,大水题,我的算法比较复杂,但是好理解,就是找可以凑出来一半周长的点来暴力枚举就行了。
题干:
Description
给出圆周上的若干个点,已知点与点之间的弧长,其值均为正整数,并依圆周顺序排列。 请找出这些点中有没有可以围成矩形的,并希望在最短时间内找出所有不重复矩形。
Input
第一行为正整数N,表示点的个数,接下来N行分别为这N个点所分割的各个圆弧长度
Output
所构成不重复矩形的个数
Sample Input Sample Output
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
#define duke(i,a,n) for(int i = a;i <= n;i++)
#define lv(i,a,n) for(int i = a;i >= n;i--)
#define clean(a) memset(a,0,sizeof(a))
const int INF = << ;
typedef long long ll;
typedef double db;
template <class T>
void read(T &x)
{
char c;
bool op = ;
while(c = getchar(), c < '' || c > '')
if(c == '-') op = ;
x = c - '';
while(c = getchar(), c >= '' && c <= '')
x = x * + c - '';
if(op) x = -x;
}
template <class T>
void write(T x)
{
if(x < ) putchar('-'), x = -x;
if(x >= ) write(x / );
putchar('' + x % );
}
int len[][];
int a[];
int n,tot = ,ans = ;
queue <int> qu;
void work(int x,int k)
{
duke(i,,k - )
{
int s = len[x][i];
duke(j,k + ,n)
{
if(len[x][j] - len[x][k] == s)
{
ans++;
}
}
}
}
int main()
{
read(n);
duke(i,,n)
{
read(a[i]);
a[i + n] = a[i];
tot += a[i];
}
tot /= ;
duke(i,,n)
{
int ok = ;
duke(j,,n)
{
len[i][j] = len[i][j - ] + a[i + j - ];
if(len[i][j] == tot)
{
ok = ;
}
}
if(ok == )
qu.push(i);
}
while(!qu.empty())
{
int x = qu.front();
int k;
duke(i,,n)
{
if(len[x][i] == tot)
{
k = i;
break;
}
}
work(x,k);
qu.pop();
}
printf("%d\n",ans / );
return ;
}
/*
8
1
2
2
3
1
1
3
3
*/
B1800 [Ahoi2009]fly 飞行棋 数学模拟的更多相关文章
- bzoj 1800: [Ahoi2009]fly 飞行棋 暴力
1800: [Ahoi2009]fly 飞行棋 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline ...
- BZOJ 1800: [Ahoi2009]fly 飞行棋( 枚举 )
O(N2)算出有x条直径然后答案就是x(x-1)/2...这个数据范围是闹哪样! ----------------------------------------------------------- ...
- BZOJ 1800: [Ahoi2009]fly 飞行棋【思维题,n^4大暴力】
1800: [Ahoi2009]fly 飞行棋 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1689 Solved: 1335[Submit][St ...
- BZOJ_1800_[Ahoi2009]fly 飞行棋_乱搞
BZOJ_1800_[Ahoi2009]fly 飞行棋_乱搞 Description 给出圆周上的若干个点,已知点与点之间的弧长,其值均为正整数,并依圆周顺序排列. 请找出这些点中有没有可以围成矩形的 ...
- bzoj千题计划174:bzoj1800: [Ahoi2009]fly 飞行棋
http://www.lydsy.com/JudgeOnline/problem.php?id=1800 圆上两条直径构成矩形的对角线 #include<cstdio> using nam ...
- bzoj1800: [Ahoi2009]fly 飞行棋(乱搞)
1800: [Ahoi2009]fly 飞行棋 题目:传送门 题解: 大水题,早上签个到 没什么好说的...搞个前缀和,算个周长... 周长为奇数肯定误解啊废话QWQ 那么看到n<=20,还不暴 ...
- BZOJ1800 [Ahoi2009]fly 飞行棋
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...
- bzoj1800[Ahoi2009]fly 飞行棋 暴力枚举
找了道bzoj的水题,千年难得一遇. 建议初学者做做,然而我个蒟蒻初学时应该A不了..... < http://www.lydsy.com/JudgeOnline/problem.php?id= ...
- 1800: [Ahoi2009]fly 飞行棋
#include<cstdio> #include<iostream> using namespace std; ],n,ans; int main() { scanf(&qu ...
随机推荐
- oracle for linux服务器磁盘空间不足,通过过期的文件释放磁盘空间
--2013-09-16截取的数据-- 使用df-h命令查看系统磁盘空间 [root@erpdbs PROD]# df -h Filesystem Size Used Avail Use% Mount ...
- java攻城狮之路--复习xml&dom_pull编程
xml&dom_pull编程: 1.去掉欢迎弹窗界面:在window项的preferences选项中输入“configuration center” 找到这一项然后 把复选框勾去即可. ...
- jquery jstree 插件的使用
最近一个项目 需要用到jstree 这个jQuery插件,就研究了下,做目录树 菜单还是很强大的,下面对经常会用到几个用法做下说明. 1. 首先页面 引用 jquery.jstree 2. html ...
- table案例一
实现效果: html <style> #mform{ margin: 10px; } #mtable{ border-collapse: collapse; } #mtable thead ...
- 1.Linux入门介绍
1.1 Linux概述 1.1.1 Linux简要介绍 Linux的由来: Linux的内核最初是由芬兰人李纳斯·托瓦茨在上大学的时候编写的一个内核,它是基于Unix操作系统编写的 大多服务器使用的是 ...
- python 单元测试中处理用例失败的情况
今天有一个需求, 在单元测试失败的时候打印一些日志, 我们管他叫 dosomething 吧 ,反正就是做一些操作 查了下并没有查到相关的方法, 于是研究了一波unittest 的源码 发现了这个东西 ...
- UNIX C 总结
--day01--王建立QQ:2529866769今天的内容:一.计算机的框架什么是操作系统?(汽车)加油系统 油门 用户跟加油子系统交互的窗口.(接口)方向系统 方向盘 用户跟方向系统的交互接口.导 ...
- SSH远程执行命令环境变量问题
SSH命令格式 usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec] [-D [bind_address: ...
- ubuntu18.04安装chrome浏览器
前几天把系统弄崩溃了,弄了好久也没弄好,索性直接装18.04,下面是安装chrom浏览器的步骤,网络上照着16.04安装的,应该是一样的 启动终端. 输入以下命令: sudo wget http:// ...
- pyhon中的内存优化机制
一.变量的内存地址 python中变量的内存地址可以用id()来查看 >>> a = " >>> id(a) 2502558915696 二.pyhon中 ...