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的棋盘,只有黑棋和白棋,问你最少几步可以使棋子的颜色一样. 游戏规则是:如果翻动一个棋子,则该棋子上下左右的棋子也会翻一面,棋子正反面颜色相反. 思路: 都是暴搜枚举. 第一种方法: ...
随机推荐
- USACO 玛丽卡(最短路+枚举)
USACO 玛丽卡 麦克找了个新女朋友,玛丽卡对他非常恼火并伺机报复. 因为她和他们不住在同一个城市,因此她开始准备她的长途旅行. 在这个国家中每两个城市之间最多只有一条路相通,并且我们知道从一个城市 ...
- Tomcat + Mysql高并发配置优化
1.Tomcat优化配置 (1)更改Tomcat的catalina.bat 将java变成server模式,增大jvm的内存,在文件开始位置增加 setJAVA_OPTS=-server -Xms10 ...
- Hellow BeiJing
DAY1: (#^.^#),今天是9.23日,离出发去北京还有7天,好像一切还是正常的样子. 先发一张图,这就是我们机房的日常: 但是o( ̄ヘ ̄o#)我听着我耳边的cys童鞋的rap就感觉事情仿佛没辣 ...
- Qt之字典划词
简述 相信大家都用过词典吧!因为英语不太好...O(∩_∩)O~,所以经常进行划词翻译! 简述 实现 效果 源码 更多参考 实现 原理:鼠标移至某单词之上,获取鼠标位置,然后在对应位置进行取词,翻译! ...
- [React] Refactor a Stateful List Component to a Functional Component with React PowerPlug
In this lesson we'll look at React PowerPlug's <List /> component by refactoring a normal clas ...
- [Test] Easy automated testing in NodeJS with TestCafe
Quickly get up and running with sensible automated testing scenarios written in ES6. Installing and ...
- Tomcat中server.xml文件的配置
server.xml文件当中可配置如下信息: 1)配置端口号(如果是正式网站,要把8080改成80)<Connector executor="tomcatThreadPool" ...
- Android之输入内容监听回车键【Editor】
2.输入内容时按下回车键时监听 username.setOnEditorActionListener(new OnEditorActionListener() { @Override public b ...
- Android 进程常驻(0)----MarsDaemon使用说明
版权声明:本文为博主原创文章,未经博主允许不得转载. 这是一个轻量级的库,配置几行代码,就可以实现在Android上实现进程常驻,也就是在系统强杀下,以及360获取root权限下,clean mast ...
- Find or Query Data with the mongo Shell
https://docs.mongodb.com/getting-started/shell/query/ Overview You can use the find() method to issu ...