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. centos8 常用软件

    防火墙 GUI版 https://blog.csdn.net/qq_36492368/article/details/80432259 dnf install -y firewall-config d ...

  2. 【C语言】求s(n)=a+aa+aaa+...+aa...a的值

    原理:比如a=2,s(1)=2,s(2)=2+2*10+2,s(3)=2+2*10+2+(2*10+2)*10+2   ..... 规律: item=item*10+a sum=sum+item 代码 ...

  3. C语言合并两个有序链表

    将两个有序链表合并为一个新的有序链表并返回.新链表是通过拼接给定的两个链表的所有节点组成的. 示例: 输入:1->2->4, 1->3->4输出:1->1->2-& ...

  4. Test Blog

    计算机实习报告 姓名:王方正 学号:20174314 一.开发任务 题目源自<程序设计实践教程>教材22题,学生基本信息管理.描述略. 二.需求分析 1.说明自己针对这个任务将完成哪些功能 ...

  5. Mac使用pip命令安装selenium包报错解决方法

    1.使用命令:  pip install selenium 2.换成命令: python -m pip install selenium 即可成功安装

  6. model_Flask

    虚拟环境 新建一个虚拟环境:mkvirtualenv 环境名 删除一个虚拟环境:rmvirtualenv 环境名 退出:deactivate win10下安装 1. 打开cmd 安装虚拟环境包 pip ...

  7. WebRTC笔记(一)

    来源<WebRTC权威指南> 1 WebRTC特点 对等连接(Peer Connection):浏览器与浏览器(万维网上的任意两个通信终端)之间的连接(P2P) 信令服务器:在浏览器和对等 ...

  8. DVWA的安装及报错解决

    PS:我是在wamp5集成环境中搭建的 1.解压下载好的DVWA安装包到www目录下 DVWA安装包: https://pan.baidu.com/s/1ivnwiH53gIV5jWU5IyeD0Q ...

  9. torchvision的理解和学习 加载常用数据集,对主流模型的调用.md

    torchvision的理解和学习 加载常用数据集,对主流模型的调用 https://blog.csdn.net/tsq292978891/article/details/79403617 加载常用数 ...

  10. mongo gridfs 学习

    一.mongo是啥东西? MongoDB 是由C++语言编写的,基于分布式文件存储的开源数据库系统.在高负载的情况下,添加更多的节点,可以保证服务器性能. 二.gridfs是啥东西? 1.MongoD ...