考的其实是同构图的性质: 1.同构图的顶点数,边数相等 2.同构图通过点的映射后邻接矩阵相同 这篇博客讲的很好https://www.jianshu.com/p/c33b5d1b4cd9 本题还需要一步构造的方案,通过最基础的n=4和n=4+1的图的图推广到n=4k和n=4k+1的状态 #include<bits/stdc++.h> using namespace std; #define maxn 2005 int mp[maxn][maxn]; int n,f[maxn]; int mai…
这题的不能用二分做,因为不满足单调性的 可以用multiset做 #include<bits/stdc++.h> #define ll long long #define rep(i,a,b) for(int i=a;i<=b;i++) using namespace std; ; multiset<int>s; multiset<int>::iterator it; int a[maxn],T,N,K,C; bool check(int Mid) { s.cle…
链接:https://www.nowcoder.com/acm/contest/144/C来源:牛客网 Oak is given N empty and non-repeatable sets which are numbered from 1 to N. Now Oak is going to do N operations. In the i-th operation, he will insert an integer x between 1 and M to every set inde…
链接:https://www.nowcoder.com/acm/contest/144/J来源:牛客网 skywalkert, the new legend of Beihang University ACM-ICPC Team, retired this year leaving a group of newbies again. Rumor has it that he left a heritage when he left, and only the one who has at lea…
链接:https://ac.nowcoder.com/acm/contest/887/H来源:牛客网 题目描述 Given three integers A, B, C. Count the number of pairs <x ,y> (with 1≤x≤Aand1≤y≤B) such that at least one of the following is true: - (x and y) > C - (x xor y) < C   ("and", &q…
题意: 给你\(A-J\)的字母组成的日期,形式为\(yyyy/mm/dd\).现给你\(n\)个这样的串\((n<=1e5)\),问你把字母映射成数字,并且使得所有日期合法且为星期五的最小字典序为什么. 思路: 判断星期几可以直接用吉姆拉尔森公式解决. inline int weekday(int y, int m, int d){ \(\qquad\)if(m <= 2){m += 12, y--;} \(\qquad\)return (d + 2 * m + 3 * (m + 1) /…
题意: 给定点数,构造自补图,要求输出邻接矩阵,和原图与补图的同构映射. 题解: 只有点数为4k和4k+1的情况才能构造自补图,因为只有这些情况下边数才为偶数. 一种构造方式是,邻接矩阵和同构映射增量构造,每次加四个边xyzw,x和w连接原来的所有边,yz不连,同构映射是交换xy,zw 参考:www.matrix67.com/blog/archives/6221 #include<bits/stdc++.h> using namespace std; typedef long long LL;…
题意: 给出一棵n个点的树,每条边有边权.对这个树加边变成一个完全图.新加的边的权值为边上两点在树上的距离.求完全图上任意两点的最大流之和. 题解: 一共有C(n,2)个点对.假设当前求s到t之间的最大流,也就是最小割.那么割完之后会是2个连通块,且连通块内部是完全图. 因为是最小割,所以被割掉的边权和最小.即两个连通块内部的边权和最大.那么就会有一个连通块是孤立点,取s和t中到其余所有点距离小的作为孤立点. 问题变成了求每个点到其他所有点的距离. dfs第一次求每个点到他所有儿子节点的距离,d…
题意: 给出n个区间和m个点(点按顺序给出且强制在线).每个区间只会被第一个他包含的点摧毁.问每个点能摧毁多少个区间以及每个区间是被哪个点摧毁的. 题解: 将n个区间按照左端点排序,然后用vector(储存左端点,右端点,id)初始化线段树. 初始化的方法是:对于线段树的n个叶子节点,即为排好序的n个区间.对于其他节点,将左右儿子按照右端点大小归并(归并是线性复杂度). 还要维护每个节点左端点的最小值(用来剪枝)和最大值(用来判断可行性). 每个区间只会被第一个他包含的点摧毁,所以用vis数组标…
一个数很大,并不能预处理,所以要进行公式变换,存前一个的值就好 #include <bits/stdc++.h> using namespace std; typedef long long ll; ,N=1e6+; ll n,m,inv[N]; int main() { inv[]=inv[]=; ; ios::sync_with_stdio(),cout.tie(); cin>>T; ; i<N; ++i) inv[i]=(MD-MD/i)*inv[MD%i]%MD; w…