题意: 给你n个点的坐标,让你给出两个点,这两个点的连线可以平分这些点. 思路: 先按y的大小排序,在按x的小排序,再搞一下就行了.如下图: #include <bits/stdc++.h> using namespace std; struct poi{ int x; int y; }p[]; bool cmp(struct poi a,struct poi b) { if(a.y==b.y) return a.x<b.x; else return a.y>b.y; } int…
链接:https://www.nowcoder.com/acm/contest/141/E来源:牛客网 Eddy likes to play with string which is a sequence of characters. One day, Eddy has played with a string S for a long time and wonders how could make it more enjoyable. Eddy comes up with following…
链接:https://www.nowcoder.com/acm/contest/141/H来源:牛客网 Eddy has solved lots of problem involving calculating the number of coprime pairs within some range. This problem can be solved with inclusion-exclusion method. Eddy has implemented it lots of times…
G.coloring tree BFS计数 题目:给你n(<=5000)个节点的一颗树 你有K(<=5000)种颜色 你可以给每一个节点染一种颜色 总共有Kn种染色方法 在一种染色方法中 定义colorness为每一对相同颜色节点距离中的最短距离 问colorness为D时 有多少种染色方案 结果%mod 解:我们先求出>=D的方案数再减去>=D+1的方案数就是==D的方案数 现在问题变为>=X的方案数 可以看成对于任意一个节点,所有和它距离小于d的节点,不能和它有相同的颜色…
题目: 题意:将1~n的数进行m次操作,每次操作将第pi位到pi+si-1位的数字移到第一位,求最后的排列. 思路:现在还没不会写splay,在知道这是splay模板题后找了一波别人的模板,虽然过了,但是感觉自己没学到什么,过几天去学一波splay,再回来把这题重写一次~ 代码实现如下: #include <map> #include <set> #include <cmath> #include <ctime> #include <stack>…
题目链接(貌似未报名的不能进去):https://www.nowcoder.com/acm/contest/141/A 题目: 题意:背包题意,并打印路径. 思路:正常背包思路,不过五维的dp很容易爆内存,比赛时无限爆,后面队友提醒用short就过了.不过也可以用滚动减少内存消耗,两种代码实现都贴一下吧~ 五维代码实现如下: #include <set> #include <map> #include <queue> #include <stack> #in…
起初看到这道题的时候,草草就放过去了,开了另一道题,结果开题不顺利,总是感觉差一点就可以做出来,以至于一直到最后都没能看这道题qaq 题意:类似于操作系统上讲的LRU算法,有两个操作,0操作代表访问其中的块,如果命中,将该块去除放到数组的末尾,未命中则在数组末尾加入当前块,1操作是询问数组中是否存在一个块,存在输出该块的数据,否则输出无效. 分析:考虑到只是对于数组的最后一个元素进行操作,所以可以使用链表进行模拟相关操作,主要的坑点就是时间卡的很紧所以需要加入快读,使用简单的hash将字符串映射…
题意: 如题. 或者用我的数组分治也可以,就是有点愚蠢. //#include <bits/stdc++.h> #include <map> #include <iostream> #include <algorithm> /* 在O(n)中找连续的子串 -> 统计前缀和 map记录下标 */ using namespace std; ]; int n; , one = ; ]; map<int, int> mp1, mp2; int ma…
链接:https://www.nowcoder.com/acm/contest/143/J来源:牛客网 There are n students going to travel. And hotel has two types room:double room and triple room. The price of a double room is p2 and the price of a triple room is p3 Now you need to calulate the min…
链接:https://www.nowcoder.com/acm/contest/143/G来源:牛客网 Give two positive integer c, n. You need to find a pair of integer (a,b) satisfy 1<=a,b<=n and the greatest common division of a and b is c.And you need to maximize the product of a and b 输入描述: The…