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. LED Keychain-A Tool To Drive Specific Market Segments

    LED keychain are an excellent tool to drive specific market segments. They can focus on a small grou ...

  2. 小I的小姐姐

    小 I 的小姐姐 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 小 I 去天津玩啦,一路上,他跟他的同学发生了许多有趣 ...

  3. (转)预估大数据量下UV的方法

    在实际应用中,我们经常碰到这种情况,即要统计某个对象或者事件独立出现的次数.对于较小的数据量,这很容易解决,我们可以首先在内存中对序列进行排序,然后扫描有序序列统计独立元素数目.其中排序时间复杂度为O ...

  4. 小总结:fibonacci数的产生

    我写的一个固定的函数来嘞: ]={,}; void f() { ;i<;i++) { fib[i]=fib[i-]+fib[i-]; } } 1,1,2,3,5,8,13,21,34,55,.. ...

  5. windows redis启动

    1.下载redis 2.启动redis 3.启动redis客户端并设置protected-mode为false

  6. 【Python】浮点数用科学计数法表示

  7. Python之路Day05

    字典 字典 -- dict Python的数据结构之一 字典是可变数据类型,无序的 定义 dic = {'key':'Value'} 键值对 字典的作用 存储数据,大大量的,将数据和数据起到关联作用 ...

  8. 在 linux 中连接 mysql 数据库

    命令格式 mysql -h主机地址 -u用户名 -p用户密码 登录本机 mysql mysql -u用户名 -p用户密码 实例 TD - X1数据库:/opt/lampp/bin/mysql -u r ...

  9. codeforces 1283F. DIY Garland(树+优先队列)

    题目连接:https://codeforces.com/contest/1283/problem/F 题意:一根电线连接着两个点,这两个点分别代表着两个灯,灯有自己的编号i,其亮度是2 ^ i,每根电 ...

  10. lvm磁盘扩容

    LVM实现新挂载磁盘扩容到原有目录 #查看磁盘 fdisk -l #创建pv pvcreate /dev/sdb [root@VM-67-49 ~]# pvcreate /dev/sdb Physic ...