2021“MINIEYE杯”中国大学生算法设计超级联赛

1006

  • Given a sequence of integers of length n, find the shortest consecutive subsequence witch XOR sum not less than k.

    If there are multiple consecutive subsequences of the same length, print the consecutive subsequence with the smallest left end point.

    If there are no consecutive subsequence witch XOR sum not less than k, just print “-1”.

【这道题可以说是完全给了自己一道警钟,早早的就写过trie的01树的题目,写这题的时候不仅没想到,百度知道要01trie做之后都没有思路,明明写过求最大异或的题目,害。】

​ 首先这题使用了异或前缀和的01字典树,我们可以边遍历边补充建树,遍历右端点,那么现在已有的树便是所有有可能存在左端点的一颗前缀树,每次从最高位开始找,找是否可能异或为1的点,然后维护一个到当前位置的异或值,如果大于k,则我们维护一个返回的值,而v[p]越大则区间长度越小。

解释

else{p = son[p][x];//if (res >= k)//  ans = max(ans, v[p]);}

因为如果p = son[p] [x],值是不会变大的,而不会变的点其实都是之前的点,是肯定会长度更长的。(每次建树每个点都是存的最后一个位置)

int n, k;
int son[30 * maxn][2], idx;
int v[30 * maxn],a[maxn];void creat(int u,int pos)
{int p = 0;pre(i, 29, 0){int x = u >> i & 1;if (son[p][x] == 0) son[p][x] = ++idx;p = son[p][x];v[p] = pos;}return;
}int ser(int u)
{int ans = -1;int res = 0;int p = 0;pre(i, 29, 0){int x = u >> i & 1;if (son[p][!x]){p = son[p][!x];res = res + (1 << i);if (res >= k)ans = max(ans, v[p]);}else{p = son[p][x];//if (res >= k)//  ans = max(ans, v[p]);}}return ans;
}signed main()
{//ios::sync_with_stdio(0);//cin.tie(0),cout.tie(0);int t = read();while (t--){n = read(), k = read();rep(i, 0, 30 * n) son[i][0] = son[i][1] = 0;idx = 0;rep(i, 1, n) a[i] = read();int sum = 0;int l = -1, r = -1;int res = 0,minn = inf;rep(i, 1, n){sum = sum ^ a[i];if ((res = ser(sum)) != -1){if (minn > (i - res)){//see1(i);minn = i - res;l = res + 1;r = i;}}creat(sum, i);}if (~l){printf("%d %d\n", l, r);}else out(-1);}return 0;
}

1009

  • Let’s call a weighted connected undirected graph of n vertices and m edges KD-Graph, if the
    following conditions fulfill:

    * n vertices are strictly divided into K groups, each group contains at least one vertice

    * if vertices p and q ( p ≠ q ) are in the same group, there must be at least one path between p and q meet the max value in this path is less than or equal to D.

    * if vertices p and q ( p ≠ q ) are in different groups, there can’t be any path between p and q meet the max value in this path is less than or equal to D.

    You are given a weighted connected undirected graph G of n vertices and m edges and an integer K.

    Your task is find the minimum non-negative D which can make there is a way to divide the n vertices into K groups makes G satisfy the definition of KD-Graph.Or −1 if there is no such D exist.

    老毛病了二分之前不想是不是满足单调性不过脑子。

首先最暴力的方法就是从1尝试到inf (X) 从0试到inf(√)但是显然会超时。

那么我们怎么样才能减小找D的次数呢,如果一个d是可行的话,那么d有可能夹在2个权值之间,而如果d可行的话,小于d的那个权值也可行,因为<=d的在一个组里面,所以其实答案就在m个权值中,如果从小到大排序,就只需要遍历1e5次了。

而每次比较都需要在某一阶段合并完成后,再去看是否满足k。

int n, m, k;
int fa[maxn];struct nod
{int a, b, c;bool operator < (const nod& b) const&{return c < b.c;}}mp[5*maxn];int find(int x)
{if (fa[x] != x) fa[x] = find(fa[x]);return fa[x];
}void solve()
{rep(i, 1, n) fa[i] = i;sort(mp + 1, mp + 1 + m);int now = n,ans = 0;rep(i, 1, m)  {if (mp[i].c > ans)  // 在将某一阶段合并完成后,再去比较 {if (now == k){out(ans);return;}}if ( find(mp[i].a) == find(mp[i].b) ) continue;now--; // 现在有的集合数减少fa[find(mp[i].a)] = find(mp[i].b);ans = mp[i].c;}printf("%d\n", now == k ? ans : -1); //最后有一次是没有判断的return ;
}signed main()
{//ios::sync_with_stdio(0);//cin.tie(0),cout.tie(0);int t = read();while (t--){n = read(), m = read(), k = read();rep(i, 1, m){int x = read(), y = read(), z = read();mp[i] = { x,y,z };}solve();}return 0;
}

2021“MINIEYE杯”中国大学生算法设计超级联赛相关推荐

  1. 【2021杭电多校赛】2021“MINIEYE杯”中国大学生算法设计超级联赛(3)签到题3题

    2021"MINIEYE杯"中国大学生算法设计超级联赛(3) Start Time : 2021-07-27 12:00:00 End Time : 2021-07-27 17:0 ...

  2. 【2021杭电多校赛】2021“MINIEYE杯”中国大学生算法设计超级联赛(1)签到题15869

    2021"MINIEYE杯"中国大学生算法设计超级联赛(1) Start Time : 2021-07-20 12:10:00 End Time : 2021-07-20 17:1 ...

  3. 2021“MINIEYE杯”中国大学生算法设计超级联赛(2)

    2021"MINIEYE杯"中国大学生算法设计超级联赛(2) 1008 I love exam (类背包DP) 1010 I love permutation (数学构造,剩余系) ...

  4. 7068 Dota2 Pro Circuit 杭电多校(2021“MINIEYE杯”中国大学生算法设计超级联赛9) [贪心+双指针]

    题目 Dota2 Pro Circuit *Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Oth ...

  5. 【2021杭电多校赛】2021“MINIEYE杯”中国大学生算法设计超级联赛(5)签到题4题

    Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 Miserable Faith 33.33%(19/57) 1002 String Mod 2 ...

  6. 【2021杭电多校赛】2021“MINIEYE杯”中国大学生算法设计超级联赛(8)

    1006 GCD Game (博弈论,nim游戏,质因子个数) 题意:有n个数a1,a2....an两个人玩游戏,Alice先动,Bob后动每次可以将一个数变为他的因子,直到不能动就输了. 题解:将问 ...

  7. 2021“MINIEYE杯”中国大学生算法设计超级联赛(1)个人解题报告

    文章目录 HDU6950 Mod, Or and Everything HDU6954 Minimum spanning tree HDU6958 KD-Graph HDU6957 Maximal s ...

  8. 2021“MINIEYE杯”中国大学生算法设计超级联赛(8)(1002,1004,1006,1009)

    前言 依旧是白嫖账号,只打了一些题/kk 正题 1002 Buying Snacks 题目大意 nnn个物品,每个可以买一次也可以不买,如果买需要选择1/21/21/2块钱的,然后也可以相邻两个一起买 ...

  9. 2021“MINIEYE杯”中国大学生算法设计超级联赛(7)部分题解

    前言 找大佬嫖到个号来划水打比赛了,有的题没写或者不是我写的就不放了. 目前只有:1004,1005,1007,1008,1011 正题 题目链接:https://acm.hdu.edu.cn/con ...

最新文章

  1. 新兴AI解决方案将越来越依赖于嵌入式视觉技术
  2. Angular 2 Pipe
  3. 程序员开发利器:源代码管理的十条建议
  4. Hibernate实体JSONObject化时遇到的问题
  5. c语言二维数组中的周边,【C语言】二维数组中的查找,杨氏矩阵
  6. ubuntu 13.04 mysql_Ubuntu 13.04 MySQL Proxy安装与配置
  7. 由递推关系到通项公式
  8. Atitit 学历的类型大总结 目录 1. 学历的分类 2 1.1. 按照组织性质,分类为立法系统 政府系统 司法系统 部落级别 企业级别商业系统 宗教系统 个人级别 2 1.2. 按照地域性质,
  9. Windows程序设计--起步
  10. 时空跳跃者的魔法(codevs3315)
  11. 打造自己备份的系统镜像
  12. coap 返回版本信息_coap组包格式的简单解析
  13. 暗黑破坏神2中的符文系统,一共有多少个符文,可以介绍其中1个符文组合吗?...
  14. Arduino开发板连接XBee模块的方法
  15. 计算机视觉算法——基于Transformer的目标检测(DETR / Deformable DETR / DETR 3D)
  16. AI模型也需要资产管理,星环科技推出AI运营平台MLOps星环科技星环科技
  17. 【Matlab】多元线性回归
  18. hive报错整理之Malformed ORC file 、Invalid postscript.
  19. Java使用EasyExcel下载xls、xlsx 出现文件格式与扩展名不匹配(亲测)
  20. Cesium中文教程-Cesium Workshop(一)

热门文章

  1. 分享5款小软件,让你打造更舒适的办公电脑
  2. js设计模式抽象工厂模式
  3. java多线程读写excel文件
  4. java正则表达式 密码强度_密码验证,密码强度正则表达式
  5. 小作坊开发与正规团队开发
  6. 【100%通过率】华为OD机试真题 Java 实现【货币单位换算】【2022.11 Q4 新题】
  7. MOngodb备份(mongodump)和恢复(mongorestore)
  8. projectwbs表_Microsoft Project制作WBS基本使用
  9. 荒野行动系统推荐观战榜_荒野行动攻略_实力围观枪神 《荒野行动》观战系统有学问_游戏手机游戏-中关村在线...
  10. Python开发微信公众平台(一)