河南理工

河南理工大学新生挑战赛 C.Xor Path

若如初见. 提交于 2020-01-21 14:24:17
河南理工大学新生挑战赛 C.Xor Path 题目描述 In graph theory, if an undirected gragh G(V, E) without cycle has n vertices, n − 1 edges and the graph is connected, then G(V, E) is called a tree. You are given a tree has n vertices, each vertice has a weight. Vertice i’s weight is w i w_i w i ​ . Henry has q queries, each query has two vertices u, v. He wants to know the xor sum of the weights of all vertices on the shortest path from u to v (contains u,v). 输入描述: The first line is an integer n ( 1 ≤ n ≤ 1 0 5 ) n (1 ≤ n ≤ 10^5 ) n ( 1 ≤ n ≤ 1 0 5 ) , the number of the vertices. Line 2 has n integers , the ith

河南理工大学新生挑战赛

左心房为你撑大大i 提交于 2020-01-20 10:09:55
点击这里可以查看题目哦! A.水题~签到 B.The flower 题意:意思就是给一个字符串,然后从字符串中得到子串,并且子串满足情况 1.出现次数大于2,; 2.子串的长度等于k; 找到有多少个这样的串然后按照字典序打印出来 思路:用map存子串用来计算数目,然后用set来去重并排序,在截取字符串的时候要注意不能直接遍历长度截取子串,因为截取长度不知。所以要从i = k-1开始。然后就是遍历子串,看map里面哪一个>2,然后把这个子串插入到一个新的set容器里面,目的是排序,然后输出大小,遍历输出子串即可! # include <bits/stdc++.h> using namespace std ; int main ( ) { string s ; int k ; cin >> s >> k ; unordered_map < string , int > mmp ; set < string > st ; int n = ( int ) s . length ( ) ; for ( int i = k - 1 ; i < n ; i ++ ) { string now = s . substr ( i - ( k - 1 ) , k ) ; mmp [ now ] ++ ; st . insert ( now ) ; } set < string > ans ; for