Gym - 100203A Ariel 暴力+位运算
题意:第i种生物有k[i]个特征,分数是score[i],现在要参加竞赛,报出一种生物a,和一些特征h[i],参加竞赛的所有生物在这些h[i]上面的特征是一样的,a生物有h[i],则所有竞赛的生物都必须有h[i],a生物没有,竞赛的生物也没有,没有提到的则不用管。问你在竞赛中a的排名
思路:特征最多只有10中,所有可以用二进制的每一位表示特征的状态,并记录下每种状态下的生物的类型。现在给你生物的状态,首先要求出能参加竞赛的生物的种类。当 (i&p == t[a]&p) 时,所有拥有i状态的生物就是可以参加竞赛的。再用二分找到在这些类型中a的位置,加起来便是排名了
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#define LL long long
#define eps 1e-8
#define INF 0x3f3f3f3f
#define MAXN 10005
using namespace std;
int G[][MAXN];
int s[MAXN], t[MAXN];
vector<int> f[];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // OPEN_FILE
int n, k, m;
scanf("%d%d", &n, &k);
int x, y, p;
for(int i = ; i < ; i++){
G[i][] = ;
}
for(int i = ; i <= n; i++){
scanf("%d%d", &s[i], &y);
p = ;
for(int j = ; j <= y; j++){
scanf("%d", &x);
p |= << (x - );
}
f[p].push_back(s[i]);
t[i] = p;
G[p][]++;
G[p][G[p][]] = s[i];
}
for(int i = ; i <= ; i++){
sort(G[p], G[p] + G[p][]);
sort(f[i].begin(), f[i].end());
}
scanf("%d", &m);
int q;
int ans;
for(int i = ; i <= m; i++){
scanf("%d%d", &x, &y);
p = ;
for(int j = ; j <= y; j++){
scanf("%d", &q);
p |= << (q - );
}
ans = ;
for(int i = ; i <= ; i++){
if((i & p) != (t[x] & p))continue;
ans += f[i].size() - (upper_bound(f[i].begin(), f[i].end(), s[x]) - f[i].begin());
continue;
int left = , right = G[i][];
while(left < right){
int mid = (left + right) >> ;
if(G[i][mid] > s[x]){
right = mid;
}
else{
left = mid + ;
}
}
if(G[i][left] == s[x]) continue;
//ans += left - 1;
//continue;
if(G[i][left] > s[x]){
ans += left;
}
else if(G[i][left] < s[x]){
ans += left - ;
}
//ans += left;
//if(G[i][left] == s[x])
//ans += left -1;
}
printf("%d\n", ans);
}
}
Gym - 100203A Ariel 暴力+位运算的更多相关文章
- UVA 11464 暴力+位运算 ***
题意:给你一个 n * n 的 01 矩阵,现在你的任务是将这个矩阵中尽量少的 0 转化为 1 ,使得每个数的上下左右四个相邻的数加起来是偶数.求最少的转化个数. 新风格代码 lrj书上说的很清楚了, ...
- Gym 100818I Olympic Parade(位运算)
Olympic Parade http://acm.hust.edu.cn/vjudge/contest/view.action?cid=101594#problem/I [题意]: 给出N个数,找出 ...
- UVa 818Cutting Chains (暴力dfs+位运算+二进制法)
题意:有 n 个圆环,其中有一些已经扣在一起了,现在要打开尽量少的环,使所有的环可以组成一条链. 析:刚开始看的时候,确实是不会啊....现在有点思路,但是还是差一点,方法也不够好,最后还是参考了网上 ...
- A - Subarrays Beauty gym 位运算 &
You are given an array a consisting of n integers. A subarray (l, r) from array a is defined as non- ...
- Codeforces 868D Huge Strings - 位运算 - 暴力
You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed ...
- SRM331-CarolsSinging(暴力,位运算)
Problem Statement When the Christmas dinner is over, it's time to sing carols. Unfortunately, not al ...
- 【UVA】658 - It's not a Bug, it's a Feature!(隐式图 + 位运算)
这题直接隐式图 + 位运算暴力搜出来的,2.5s险过,不是正法,做完这题做的最大收获就是学会了一些位运算的处理方式. 1.将s中二进制第k位变成0的处理方式: s = s & (~(1 < ...
- UVA 565 565 Pizza Anyone? (深搜 +位运算)
Pizza Anyone? You are responsible for ordering a large pizza for you and your friends. Each of th ...
- POJ 1753 位运算+枚举
题意: 给出4*4的棋盘,只有黑棋和白棋,问你最少几步可以使棋子的颜色一样. 游戏规则是:如果翻动一个棋子,则该棋子上下左右的棋子也会翻一面,棋子正反面颜色相反. 思路: 都是暴搜枚举. 第一种方法: ...
随机推荐
- 【转载】spring boot 链接 虚拟机(Linux) redis
原文:https://www.imooc.com/article/43279?block_id=tuijian_wz 前提是你已经安装redis且支持远程连接,redis的安装这里不再赘述,有需要的可 ...
- vue-cli#2.0项目结构分析
项目结构 build 构建工具相关的目录 config 配置目录 dist 通过工具打包生成的最终需要上线的目录 node_modules 存放本地开发所有的依赖包的目录 src 源码目录 stati ...
- 【BZOJ 1212】[HNOI2004]L语言
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 因为查询的字典里面.单词的最大长度为10 所以. 如果建立一棵字典树的话. 深度最多为10: 那么可以写一个DP; 设f[i]表示1 ...
- Maven学习总结(22)——Maven常用插件介绍
我们都知道Maven本质上是一个插件框架,它的核心并不执行任何具体的构建任务,所有这些任务都交给插件来完成,例如编译源代码是由maven- compiler-plugin完成的.进一步说,每个任务对应 ...
- HDU——T 1507 Uncle Tom's Inherited Land*
http://acm.hdu.edu.cn/showproblem.php?pid=1507 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- hdu 1518 Square 深搜,,,,花样剪枝啊!!!
Square Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- 可靠的Windows版Redis
副标题: 评论更精彩,教你怎么解决64位Windows版Redis狂占C盘的问题. MS Open Tech 技术团队近期花了非常多时间来測试最新构建的Windows版Redis(可在 MS Open ...
- Android jni 二维数组 传递
学习Android Jni时,一个二维 整数 数组的传递花了我好长时间,在网上查的资料都不全,当然最后是成功了,写在这里是为了自己记住,当然有人搜索到并利用了我会很高兴. in Android J ...
- mysql创建新用户时 连接报错 (解决方案把匿名用户删除)
ERROR (): Access denied for user 'ljcc'@'localhost' (using password: YES) 步骤 创建了mysql的用户 insert mysq ...
- 增强for循环的使用详解及代码
首先说一下他的语法结构: for(数据类型 变量 :集合){ //这里写要遍历的元素,或者所需要的代码即可//如果集合中存放的是对象,可以获取到每个对象(数据类型=对象类型 变量(遍历出来的每个对象) ...