题目链接: Problem - B - Codeforces

题目

Example
input
4
3
1 1 1
5
1 2 3 4 5
5
0 2 0 3 0
4
1 3 5 1
output
6
0
36
4

题意

给一串数,用这n个数排几种序列,使得 i=1~(n-1)

输出有几种序列满足情况

题解

附  : & -- 位运算之一,有0则0

不用怀疑,一堆数&完后,得到的数<=这堆数的任意一个数

因为每一位只要有一个数==0,这一位就=0,否则为1

记最后&完所有数的数为num, 如果这串数中有>=2个等于num的数,那么

把这两个数放在最后和最前面,其他的数,全排就好了

记有cnt个数==num,结果为

代码

#include <iostream>

using namespace std;

typedef long long ll;
const int N = 2e5+10, mod = 1e9+ 7;;
int a[N]; int main()
{
int t;
cin >> t;
while(t --)
{
int n;
cin >> n;
for(int i = 1; i <= n ; i ++) cin >> a[i]; int num = a[1]; for(int i = 2; i <= n; i ++)
num &= a[i]; int cnt = 0;
for(int i = 1; i <= n; i ++)
if(num == a[i])
cnt ++; if(cnt < 2)
cout << 0 << endl;
else
{
cnt = (ll)cnt * (cnt-1)% mod;
for(int i = 2; i <= n-2; i ++)
cnt = (ll)cnt * i % mod; cout << cnt << endl;
}
}
return 0;
}

Divide by Zero 2021 and Codeforces Round #714 (Div. 2) B. AND Sequences思维,位运算 难度1400的更多相关文章

  1. Vus the Cossack and Strings(Codeforces Round #571 (Div. 2))(大佬的位运算实在是太强了!)

    C. Vus the Cossack and Strings Vus the Cossack has two binary strings, that is, strings that consist ...

  2. Codeforces Round #672 (Div. 2 B. Rock and Lever (位运算)

    题意:给你一组数,求有多少对\((i,j)\),使得\(a_{i}\)&\(a_{j}\ge a_{i}\ xor\ a_{j}\). 题解:对于任意两个数的二进制来说,他们的最高位要么相同要 ...

  3. 数学 Codeforces Round #219 (Div. 2) B. Making Sequences is Fun

    题目传送门 /* 数学:这题一直WA在13组上,看了数据才知道是计算cost时超long long了 另外不足一个区间的直接计算个数就可以了 */ #include <cstdio> #i ...

  4. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) D. Jon and Orbs

    地址:http://codeforces.com/contest/768/problem/D 题目: D. Jon and Orbs time limit per test 2 seconds mem ...

  5. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C - Jon Snow and his Favourite Number

    地址:http://codeforces.com/contest/768/problem/C 题目: C. Jon Snow and his Favourite Number time limit p ...

  6. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1

    地址:http://codeforces.com/contest/768/problem/B 题目: B. Code For 1 time limit per test 2 seconds memor ...

  7. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A. Oath of the Night's Watch

    地址:http://codeforces.com/problemset/problem/768/A 题目: A. Oath of the Night's Watch time limit per te ...

  8. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined)

    C题卡了好久,A掉C题之后看到自己已经排在好后面说实话有点绝望,最后又过了两题,总算稳住了. AC:ABCDE Rank:191 Rating:2156+37->2193 A.Oath of t ...

  9. Divide by Zero 2018 and Codeforces Round #474 (Div. 1 + Div. 2, combined)

    思路:把边看成点,然后每条边只能从下面的边转移过来,我们将边按照u为第一关键字,w为第二关键字排序,这样就能用线段树维护啦. #include<bits/stdc++.h> #define ...

随机推荐

  1. 【Jenkins】基于Windows系统安装Jenkins

    镜像下载.域名解析.时间同步请点击阿里云开源镜像站 一.Jenkins简介 Jenkins是一款开源 CI&CD 软件,用于自动化各种任务,包括构建.测试和部署软件. Jenkins 支持各种 ...

  2. Apache+PHP+Mysql安装手册(Linux)

    一. 检查系统环境 1.确认centos版本 [root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Co ...

  3. bzoj5315/luoguP4517 [SDOI2018]战略游戏(圆方树,虚树)

    bzoj5315/luoguP4517 [SDOI2018]战略游戏(圆方树,虚树) bzoj Luogu 题目描述略(太长了) 题解时间 切掉一个点,连通性变化. 上圆方树. $ \sum |S| ...

  4. python -sorted 学习

    跟C++ STL中的sort的用法类似,sorted用来对列表进行排序 比如: list = [3,4,82,66,22,11] 用sorted(list),就会对对list这个表进行排序 如果,so ...

  5. seqlist template

    1 #include <iostream.h> 2 typedef int ElemType; 3 typedef struct{ 4 ElemType *elem; 5 int leng ...

  6. 解释WEB 模块?

    Spring的WEB模块是构建在application context 模块基础之上,提供一个适合web应用的上下文.这个模块也包括支持多种面向web的任务,如透明地处理多个文件上传请求和程序级请求参 ...

  7. Mybatis Plus使用租户过滤无效解决方案

    异常内容: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.Pe ...

  8. 我们能自己写一个容器类,然后使用 for-each 循环码?

    可以,你可以写一个自己的容器类.如果你想使用 Java 中增强的循环来遍历, 你只需要实现 Iterable 接口.如果你实现 Collection 接口,默认就具有该属性.

  9. Mybatis入门程序(一)

    1.入门程序实现需求 根据用户id查询一个用户信息 根据用户名称模糊查询用户信息列表 添加用户(二) 更新用户(二) 删除用户(二) 2.引入Mybatis所需 jar 包(Maven工程) < ...

  10. spring重点知识分享

    前言: spring是一个轻量级的开源的控制反转(Inversion of Control,IOC)和面向切面(AOP)的容器框架,它的主要目的是简化企业开发.这两个模块使得java开发更加简单.IO ...