AtCoder - 2271-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.
Based on these reports, find the number of the possible orders in which they were standing. Since it can be extremely large, print the answer modulo 109+7. Note that the reports may be incorrect and thus there may be no consistent order. In such a case, print 0.
Constraints
1≦N≦105
0≦Ai≦N−1
Input
The input is given from Standard Input in the following format:
N
A1 A2 … AN
Output
Print the number of the possible orders in which they were standing, modulo 109+7.
Sample Input 1
5
2 4 4 0 2
Sample Output 1
4
There are four possible orders, as follows:
2,1,4,5,3
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.
Sample Input 3
8
7 5 1 1 7 3 5 3
Sample Output 3
16
 
题意:
有n个人,他们只记得昨天站在他们右边的人和站在左边的人的人数差值。根据差值,问有多少种可能的站法。
 
解题思路:
首先分奇数和偶数讨论。
1.奇数:站在中间的人,左右相差的人数肯定一样多,所以为0.且0只会有一个。
       从中间往俩边延伸,可以知道每移动一位,那么差的人数增加2;
       那么奇数情况下,只会有0,2,4,6,8.且0只有一个。其它2个。

2.偶数情况,可以知道没有为0的人。从1开始。1,3,5,7,。个数都为2.
因为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的更多相关文章

  1. Lining.js - 为CSS提供 ::nth-Line 选择器功能

    在CSS中,我们使用 ::first-line 选择器来给元素第一行内容应用样式.但目前还没有像 ::nth-line.::nth-last-line 甚至 ::last-line 这样的选择器.实际 ...

  2. Lining Up(在一条直线上的最大点数目,暴力)

    Lining Up Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  3. UVA 270 Lining Up 共线点 暴力

    题意:给出几个点的位置,问一条直线最多能连过几个点. 只要枚举每两个点组成的直线,然后找直线上的点数,更新最大值即可. 我这样做过于暴力,2.7s让人心惊肉跳...应该还能继续剪枝的,同一直线找过之后 ...

  4. UVA 270 Lining Up (几何 判断共线点)

     Lining Up  ``How am I ever going to solve this problem?" said the pilot. Indeed, the pilot was ...

  5. 深入解读Linux与Android的相互关系(转-lining)

    大家都知道Android是基于Linux内核的操作系统,也曾经和Linux基金会因为内核问题产生过分歧,本文将开始对Android的内核进行剖析,主要介绍Android和Linux之间的关系,后续还会 ...

  6. POJ1118 Lining Up

    快弄死我了 最后的原因是abs和fabs的区别... 说点收获:1.cmp函数返回的是int,所以不要直接返回double相减的结果2.define inf 1e9和eps 1e-93.在整数相除得到 ...

  7. poj 1118 Lining Up(水题)

    再思考一下好的方法,水过,数据太弱! 本来不想传的! #include <iostream> using namespace std; #define MAX 702 /*284K 422 ...

  8. HDU 1432 Lining Up (POJ 1118)

    枚举,枚举点 复杂度为n^3. 还能够枚举边的,n*n*log(n). POJ 1118 要推断0退出. #include<cstdio> #include<cstring> ...

  9. POJ 1118 Lining Up

    枚举,排序. 先将所有点按双关键字排序,然后枚举线的顶点$P$,剩余的点以$P$为中心进行极角排序,可以取个$gcd$,这样一样的点就排在一起了,然后统计一下更新答案. #pragma comment ...

  10. UVa 270 & POJ 1118 - Lining Up

    题目大意:给一些点,找出一条直线使尽可能多的点在这条直线上,求这条直线上点的个数. 以每一个点为原点进行枚举,求其它点的斜率,斜率相同则说明在一条直线上.对斜率排序,找出斜率连续相等的最大长度. #i ...

随机推荐

  1. C# Enumerable

    使用Enumerable.Range 打印数字0到9 static void Main(string[] args) { , ); //Range方法获取两个int参数:一个起始数,一个是要生成的结果 ...

  2. [P4450] 双亲数 - 莫比乌斯反演,整除分块

    模板题-- \[\sum\limits_{i=1}^a\sum\limits_{j=1}^b[(i,j)=k] = \sum\limits_{i=1}^a\sum\limits_{j=1}^b[k|i ...

  3. nginx配置长连接(ajax60秒请求超时)

    个人博客 地址:http://www.wenhaofan.com/article/20180911150337 1.在使用ajax做轮训的时候前台发出的ajax请求总是会在60秒之后返回405超时响应 ...

  4. es6 新增变量声明方式

    let 与 var var var声明的变量拥有全局作用域或者局部作用域 在全局中声明变量即为全局变量 在函数中声明变量即为局部变量 而var在使用过程中也逐渐暴露出许多问题 var的几大问题 变量提 ...

  5. Vs2013以管理员身份运行

    VS快捷方式目录下的devenv.exe 右键->兼容性疑难解答->疑难解答程序->勾选该程序需要附加权限即可,以后每次打开VS时都会以管理员身份运行了!

  6. JS高级---案例:验证用户输入的是不是邮箱

    案例:验证用户输入的是不是邮箱 <!DOCTYPE html> <html lang="en"> <head> <meta charset ...

  7. python 处理protobuf协议

    背景:需要用django基于python3模拟一个http接口,请求是post方式,body是protobuf string,返回也是protobuf string 设计:django获取pb str ...

  8. 出现“无法在发送 HTTP 标头之后进行重定向”问题

    如题,在Response.Redirect之后会偶尔出现“无法在发送HTTP标头之后进行重定向”问题. 是因为,已经在出现错误的代码之前进行过一次重定向了.仔细检查代码即可. 解决方法:按照逻辑移除多 ...

  9. 2019牛客多校第五场 G subsequence 1 dp+组合数学

    subsequence 1 题意 给出两个数字串s,t,求s的子序列中在数值上大于t串的数量 分析 数字大于另一个数字,要么位数多,要么位数相同,字典序大,位数多可以很方便地用组合数学来解决,所以只剩 ...

  10. 大二组队(NABCD)

    (Need)需求 很多时候,外人都不了解我们的校园.为了宣传铁大.让更多人了解校园.走进铁大. (Approach)做法 我们有最基本的展示.对校园风貌有基本的讲解.有论坛供应大家讨论. (Benef ...