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的棋盘,只有黑棋和白棋,问你最少几步可以使棋子的颜色一样. 游戏规则是:如果翻动一个棋子,则该棋子上下左右的棋子也会翻一面,棋子正反面颜色相反. 思路: 都是暴搜枚举. 第一种方法: ...
随机推荐
- c进程学习日志
#include<unistd.h> #include<sys/types.h> #include<pwd.h> #include<stdio.h> i ...
- 紫书 例题 11-14 UVa 1279 (动点最小生成树)(详细解释)
这道题写了好久-- 在三维空间里面有动的点, 然后求有几次最小生成树. 其实很容易发现, 在最小生成树切换的时候,在这个时候一定有两条边相等, 而且等一下更大的那条边在最小生成树中,等一下更小的边不在 ...
- 【codeforces 128C】Games with Rectangle
[题目链接]:http://codeforces.com/problemset/problem/128/C [题意] 让你一层一层地在n*m的网格上画k个递进关系的长方形;(要求一个矩形是包含在另外一 ...
- HDU 2782 The Worm Turns (DFS)
Winston the Worm just woke up in a fresh rectangular patch of earth. The rectangular patch is divide ...
- github git.exe位置
C:\Users\yourname\AppData\Local\GitHub\PortableGit_69703d1db91577f4c666e767a6ca5ec50a48d243\bin\git. ...
- Android清单文件具体解释(六) ---- <activity>节点的属性
1.android:allowTaskReparenting android:allowTaskReparenting是一个任务调整属性,它表明当这个任务又一次被送到前台时,该应用程序所定义的Acti ...
- hdu5249 Tricks Device(网络流最大匹配)
分析题意可知: 1.最少须要切断多少边使吴不能找到张(题意吴仅仅能走最短路径上面的边),对从起点到终点的最短路径又一次建图,每条边的权值为1.求最大流就可以 2.在吴能够找到张的前提下,最多能够切断边 ...
- Insert Data with C# Driver
https://docs.mongodb.com/getting-started/csharp/insert/ OverView You can use the InsertOneAsync meth ...
- String slices
String slices A segment of a string is called a slice. Selecting a slice is similar selecting a char ...
- 30.algorithm排序小结
如果容器中是类,如果要调用sort则需要重载操作符 "<" 包含头文件 #define _CRT_SECURE_NO_WARNINGS #include <vector ...