Divide by Zero 2021 and Codeforces Round #714 (Div. 2) B. AND Sequences思维,位运算 难度1400
题目链接: Problem - B - Codeforces
题目
4
3
1 1 1
5
1 2 3 4 5
5
0 2 0 3 0
4
1 3 5 1
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的更多相关文章
- 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 ...
- Codeforces Round #672 (Div. 2 B. Rock and Lever (位运算)
题意:给你一组数,求有多少对\((i,j)\),使得\(a_{i}\)&\(a_{j}\ge a_{i}\ xor\ a_{j}\). 题解:对于任意两个数的二进制来说,他们的最高位要么相同要 ...
- 数学 Codeforces Round #219 (Div. 2) B. Making Sequences is Fun
题目传送门 /* 数学:这题一直WA在13组上,看了数据才知道是计算cost时超long long了 另外不足一个区间的直接计算个数就可以了 */ #include <cstdio> #i ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Divide by Zero 2018 and Codeforces Round #474 (Div. 1 + Div. 2, combined)
思路:把边看成点,然后每条边只能从下面的边转移过来,我们将边按照u为第一关键字,w为第二关键字排序,这样就能用线段树维护啦. #include<bits/stdc++.h> #define ...
随机推荐
- 昇腾CANN论文上榜CVPR,全景图像生成算法交互性再增强!
摘要:近日,CVPR 2022放榜,基于CANN的AI论文<Interactive Image Synthesis with Panoptic Layout Generation>强势上榜 ...
- Java案例——统计字符串中各种字符出现的次数
/*案例:统计各种字符在字符串中出现的次数 分析:只考虑三种字符类型的情况下(大写字母,小写字母,数字) 1.使用Scanner 类获取字符串数据 2.遍历字符串得到每一个字符 3.判断每一个字符是那 ...
- exit函数和return语句
exit函数是c语言的库函数,有一个整型的参数,代表进程终止,这个函数需<stdlib.h>头文件 在函数中写return只是代表函数终止了,不管在程序的任何位置调用exit那么进程就立即 ...
- nginx配置只允许某个IP或某些IP进行访问
server{ listen 80; listen 443 ssl; server_name ehall.jerry.plus; ssl_certificate "****.crt" ...
- 装饰器property的简单运用
property函数:在类中使用,将类中的方法伪装成一个属性 使用方法:在函数,方法,类的上面一行直接@装饰器的名字 装饰器的分类: 装饰器函数 装饰器方法:property 装饰类 class St ...
- 图解CompletableFuture源码
前言 关于CompletableFuture源码解析部分,整体上感觉还是写比较难的,不过为了推广到团队还是要好好搞一下的,我还是希望大家看到这边文章能学到点什么,废话不多说开始吧. 属性部分 首先看属 ...
- webapi_3 今天真真真全是大经典案例
这个项目一多起来了,还是分个序号比价好一点,你好我好大家好,然后关于这个标点符号的问题,我打字真的很不喜欢打标点符号,不是不好按,按个逗号其实也是顺便的事情,可能就是养成习惯了,就喜欢按个空格来分开, ...
- java 8 一个list过滤另外一个list
- 什么是 AOP?
在软件开发过程中,跨越应用程序多个点的功能称为交叉问题.这些交叉问题与 应用程序的主要业务逻辑不同.因此,将这些横切关注与业务逻辑分开是面向方 面编程(AOP)的地方.
- Spring-boot-菜鸟-快速创建应用
file-new-project 选择Spring boot ,然后选择自己的配置类型,maven jdk版本等 结果: 目录解析: resources文件夹中目录结构 static:保存所有的静态 ...