Lining Up
原创 fadedsun
最后发布于2017-08-07 10:10:15
阅读数 656
收藏
展开
Problem Statement
There are N people, conveniently numbered 1 through N. They were standing in a row yesterday, but now they are unsure of the order in which they were standing. However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person. According to their reports, the difference above for person i is Ai.
1≦N≦105
0≦Ai≦N−1
Input
The input is given from Standard Input in the following format:
A1 A2 … AN
Output
Print the number of the possible orders in which they were standing, modulo 109+7.
5
2 4 4 0 2
Sample Output 1
4
There are four possible orders, as follows:
2,5,4,1,3
3,1,4,5,2
3,5,4,1,2
Sample Input 2
7
6 4 0 2 4 0 2
Sample Output 2
0
Any order would be inconsistent with the reports, thus the answer is 0.
8
7 5 1 1 7 3 5 3
Sample Output 3
16
从中间往俩边延伸,可以知道每移动一位,那么差的人数增加2;
那么奇数情况下,只会有0,2,4,6,8.且0只有一个。其它2个。
如果可以,因为,位置有俩个,一个站的位置确定,另一个人就确定了,
那么根据组合排列中的乘法原理,就可得知。
判断出现次数是否符合规则
小心数据太大溢出
取模要根据乘法取模规则
# include <cstdio>
# include <map>
# include <cmath> using namespace std; const int mod = 1e9+; int main()
{
int n;
int a[];
map<int,int> m;
scanf("%d",&n); for(int i = ;i < n;i++)
{
scanf("%d",&a[i]);
m[a[i]]++;
} int flag = ;
if(n%) //奇数
{
if(m[] != )
{
flag = ;
}
for(int i = ;i < n;i+=)
{
if(m[i] != )
{
flag = ;
}
}
}else{
for(int i = ;i < n;i+=)
{
if(m[i] != )
{
flag = ;
}
}
}
long long sum = ; for(int i =;i < floor(n/);i++)
{
sum = ((sum % mod) * )% mod;
} if(n%)
{
if(flag)
printf("0\n");
else
printf("%lld\n",sum);
}
else
{
if(flag)
printf("0\n");
else
printf("%lld\n",sum);
} return ;
}
Lining Up的更多相关文章
- Lining.js - 为CSS提供 ::nth-Line 选择器功能
在CSS中,我们使用 ::first-line 选择器来给元素第一行内容应用样式.但目前还没有像 ::nth-line.::nth-last-line 甚至 ::last-line 这样的选择器.实际 ...
- Lining Up(在一条直线上的最大点数目,暴力)
Lining Up Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- UVA 270 Lining Up 共线点 暴力
题意:给出几个点的位置,问一条直线最多能连过几个点. 只要枚举每两个点组成的直线,然后找直线上的点数,更新最大值即可. 我这样做过于暴力,2.7s让人心惊肉跳...应该还能继续剪枝的,同一直线找过之后 ...
- UVA 270 Lining Up (几何 判断共线点)
Lining Up ``How am I ever going to solve this problem?" said the pilot. Indeed, the pilot was ...
- 深入解读Linux与Android的相互关系(转-lining)
大家都知道Android是基于Linux内核的操作系统,也曾经和Linux基金会因为内核问题产生过分歧,本文将开始对Android的内核进行剖析,主要介绍Android和Linux之间的关系,后续还会 ...
- POJ1118 Lining Up
快弄死我了 最后的原因是abs和fabs的区别... 说点收获:1.cmp函数返回的是int,所以不要直接返回double相减的结果2.define inf 1e9和eps 1e-93.在整数相除得到 ...
- poj 1118 Lining Up(水题)
再思考一下好的方法,水过,数据太弱! 本来不想传的! #include <iostream> using namespace std; #define MAX 702 /*284K 422 ...
- HDU 1432 Lining Up (POJ 1118)
枚举,枚举点 复杂度为n^3. 还能够枚举边的,n*n*log(n). POJ 1118 要推断0退出. #include<cstdio> #include<cstring> ...
- POJ 1118 Lining Up
枚举,排序. 先将所有点按双关键字排序,然后枚举线的顶点$P$,剩余的点以$P$为中心进行极角排序,可以取个$gcd$,这样一样的点就排在一起了,然后统计一下更新答案. #pragma comment ...
- UVa 270 & POJ 1118 - Lining Up
题目大意:给一些点,找出一条直线使尽可能多的点在这条直线上,求这条直线上点的个数. 以每一个点为原点进行枚举,求其它点的斜率,斜率相同则说明在一条直线上.对斜率排序,找出斜率连续相等的最大长度. #i ...
随机推荐
- Spark Streaming:updateStateByKey报错 is not applicable for the arguments...
ones.updateStateByKey(new Function2<List<Integer>, Optional<Integer>, Optional<Int ...
- 6.Dockerfile 指令
概述 我们已经介绍了 FROM,RUN,还提及了 COPY, ADD,其实 Dockerfile 功能很强大,它提供了十多个指令.下面我们继续讲解其他的指令. COPY 格式: COPY <源路 ...
- navicat异常 - 1130-host ... is not allowed to connect to this MySql server
错误描述 用navicat连接数据库报错:1130-host ... is not allowed to connect to this MySql server如何处理 解决方案 1.连接服务器: ...
- idea的插件库连不上网络
如果你试遍了网上的方法都没有解决网络问题,建议换个网络,比如切换到电信网络.
- Java 并发核心机制
目录 一.J.U.C 简介 二.synchronized 三.volatile 四.CAS 五.ThreadLocal 参考资料
- 意外发现--http-server使用
http-server 在很多情况下,需要在本地开启http服务器来测试.所以就需要一个简单的省事好用的http服务器.以前的时候,都是使用php的本地环境,但是,自从学了nodejs,发现了http ...
- c++中vector函数
std::vector <cv::Point> VectorPoints 说明:首先定义一个Point(即Point2i---二维整型的点)类型的变量VectorPoints,这就是我们创 ...
- go语言 实现对称加密解密算法
package main import ( "bytes" "crypto/aes" "crypto/cipher" "crypt ...
- samba搭建共享目录
centos 中使用docker 运行samba docker pull dperson/samba 运行一下命令 docker run -it -p 139:139 -p 445:445 --nam ...
- Python之路Day02
一.While while -- 循环 while 条件: 循环体 break -- 终止当前循环 while True: print("爱情买卖") break ...