题意:第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的位置,加起来便是排名了

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <fstream>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <deque>
  7. #include <vector>
  8. #include <queue>
  9. #include <string>
  10. #include <cstring>
  11. #include <map>
  12. #include <stack>
  13. #include <set>
  14. #define LL long long
  15. #define eps 1e-8
  16. #define INF 0x3f3f3f3f
  17. #define MAXN 10005
  18. using namespace std;
  19. int G[][MAXN];
  20. int s[MAXN], t[MAXN];
  21. vector<int> f[];
  22. int main()
  23. {
  24. #ifndef ONLINE_JUDGE
  25. freopen("in.txt", "r", stdin);
  26. //freopen("out.txt", "w", stdout);
  27. #endif // OPEN_FILE
  28. int n, k, m;
  29. scanf("%d%d", &n, &k);
  30. int x, y, p;
  31. for(int i = ; i < ; i++){
  32. G[i][] = ;
  33. }
  34. for(int i = ; i <= n; i++){
  35. scanf("%d%d", &s[i], &y);
  36. p = ;
  37. for(int j = ; j <= y; j++){
  38. scanf("%d", &x);
  39. p |= << (x - );
  40. }
  41. f[p].push_back(s[i]);
  42. t[i] = p;
  43. G[p][]++;
  44. G[p][G[p][]] = s[i];
  45. }
  46. for(int i = ; i <= ; i++){
  47. sort(G[p], G[p] + G[p][]);
  48. sort(f[i].begin(), f[i].end());
  49. }
  50. scanf("%d", &m);
  51. int q;
  52. int ans;
  53. for(int i = ; i <= m; i++){
  54. scanf("%d%d", &x, &y);
  55. p = ;
  56. for(int j = ; j <= y; j++){
  57. scanf("%d", &q);
  58. p |= << (q - );
  59. }
  60. ans = ;
  61. for(int i = ; i <= ; i++){
  62. if((i & p) != (t[x] & p))continue;
  63. ans += f[i].size() - (upper_bound(f[i].begin(), f[i].end(), s[x]) - f[i].begin());
  64. continue;
  65. int left = , right = G[i][];
  66. while(left < right){
  67. int mid = (left + right) >> ;
  68. if(G[i][mid] > s[x]){
  69. right = mid;
  70. }
  71. else{
  72. left = mid + ;
  73. }
  74. }
  75. if(G[i][left] == s[x]) continue;
  76. //ans += left - 1;
  77. //continue;
  78. if(G[i][left] > s[x]){
  79. ans += left;
  80. }
  81. else if(G[i][left] < s[x]){
  82. ans += left - ;
  83. }
  84. //ans += left;
  85. //if(G[i][left] == s[x])
  86. //ans += left -1;
  87. }
  88. printf("%d\n", ans);
  89. }
  90. }

Gym - 100203A Ariel 暴力+位运算的更多相关文章

  1. UVA 11464 暴力+位运算 ***

    题意:给你一个 n * n 的 01 矩阵,现在你的任务是将这个矩阵中尽量少的 0 转化为 1 ,使得每个数的上下左右四个相邻的数加起来是偶数.求最少的转化个数. 新风格代码 lrj书上说的很清楚了, ...

  2. Gym 100818I Olympic Parade(位运算)

    Olympic Parade http://acm.hust.edu.cn/vjudge/contest/view.action?cid=101594#problem/I [题意]: 给出N个数,找出 ...

  3. UVa 818Cutting Chains (暴力dfs+位运算+二进制法)

    题意:有 n 个圆环,其中有一些已经扣在一起了,现在要打开尽量少的环,使所有的环可以组成一条链. 析:刚开始看的时候,确实是不会啊....现在有点思路,但是还是差一点,方法也不够好,最后还是参考了网上 ...

  4. 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- ...

  5. Codeforces 868D Huge Strings - 位运算 - 暴力

    You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed ...

  6. SRM331-CarolsSinging(暴力,位运算)

    Problem Statement When the Christmas dinner is over, it's time to sing carols. Unfortunately, not al ...

  7. 【UVA】658 - It&#39;s not a Bug, it&#39;s a Feature!(隐式图 + 位运算)

    这题直接隐式图 + 位运算暴力搜出来的,2.5s险过,不是正法,做完这题做的最大收获就是学会了一些位运算的处理方式. 1.将s中二进制第k位变成0的处理方式: s = s & (~(1 < ...

  8. UVA 565 565 Pizza Anyone? (深搜 +位运算)

      Pizza Anyone?  You are responsible for ordering a large pizza for you and your friends. Each of th ...

  9. POJ 1753 位运算+枚举

    题意: 给出4*4的棋盘,只有黑棋和白棋,问你最少几步可以使棋子的颜色一样. 游戏规则是:如果翻动一个棋子,则该棋子上下左右的棋子也会翻一面,棋子正反面颜色相反. 思路: 都是暴搜枚举. 第一种方法: ...

随机推荐

  1. USACO 玛丽卡(最短路+枚举)

    USACO 玛丽卡 麦克找了个新女朋友,玛丽卡对他非常恼火并伺机报复. 因为她和他们不住在同一个城市,因此她开始准备她的长途旅行. 在这个国家中每两个城市之间最多只有一条路相通,并且我们知道从一个城市 ...

  2. Tomcat + Mysql高并发配置优化

    1.Tomcat优化配置 (1)更改Tomcat的catalina.bat 将java变成server模式,增大jvm的内存,在文件开始位置增加 setJAVA_OPTS=-server -Xms10 ...

  3. Hellow BeiJing

    DAY1: (#^.^#),今天是9.23日,离出发去北京还有7天,好像一切还是正常的样子. 先发一张图,这就是我们机房的日常: 但是o( ̄ヘ ̄o#)我听着我耳边的cys童鞋的rap就感觉事情仿佛没辣 ...

  4. Qt之字典划词

    简述 相信大家都用过词典吧!因为英语不太好...O(∩_∩)O~,所以经常进行划词翻译! 简述 实现 效果 源码 更多参考 实现 原理:鼠标移至某单词之上,获取鼠标位置,然后在对应位置进行取词,翻译! ...

  5. [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 ...

  6. [Test] Easy automated testing in NodeJS with TestCafe

    Quickly get up and running with sensible automated testing scenarios written in ES6. Installing and ...

  7. Tomcat中server.xml文件的配置

    server.xml文件当中可配置如下信息: 1)配置端口号(如果是正式网站,要把8080改成80)<Connector executor="tomcatThreadPool" ...

  8. Android之输入内容监听回车键【Editor】

    2.输入内容时按下回车键时监听 username.setOnEditorActionListener(new OnEditorActionListener() { @Override public b ...

  9. Android 进程常驻(0)----MarsDaemon使用说明

    版权声明:本文为博主原创文章,未经博主允许不得转载. 这是一个轻量级的库,配置几行代码,就可以实现在Android上实现进程常驻,也就是在系统强杀下,以及360获取root权限下,clean mast ...

  10. 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 ...