Problem 1: Cow Calisthenics [Michael Cohen, 2010] Farmer John continues his never-ending quest to keep the cows fit by having them exercise on various cow paths that run through the pastures. These cow paths can be represented as a set of vertices co…
传送门:http://www.usaco.org/index.php?page=viewproblem2&cpid=93 很容易发现,这是一个二分图的模型.竖直线是X集,水平线是Y集,若某条竖直线与水平线相交,则连边.由于目的是要没有任何两条线相交,所以二分图的边的两端不能同时取,就是要求一个二分图的最大独立集,which equals to N - 最大匹配. 然而啊然而,仍然没有一A!此题只是说给出线段两端点的坐标,并没有说x1一定<x2,y1一定<y2... 可以说这是本次月赛金…
Link: USACO 2018 Jan Gold 传送门 A: 对于不同的$k$,发现限制就是小于$k$的边不能走 那么此时的答案就是由大于等于$k$的边形成的图中$v$所在的连通块除去$v$的大小 为了优化建图过程,考虑离线,将询问和边都按权值从大到小排序,依次加边即可 维护连通性和连通块大小用并查集 #include <bits/stdc++.h> using namespace std; #define X first #define Y second typedef long lon…
题目描述 奶牛们建立了电话网络,这个网络可看作为是一棵无根树连接n(1 n 100,000)个节点,节点编号为1 .. n.每个节点可能是(电话交换机,或者电话机).每条电话线连接两个节点.第i条电话线连接两个节点Ai和Bi(1 Ai,Bi n; Ai Bi). 叶子节点只连接一条电话线,这些叶子节点是位于电话网中的一个电话亭.两头奶牛需要通话,信号是沿着电话网络中连接两个顶点之间最短的路径传递.每部交换机最多可容纳K (1 K 10)对牛同时通话,对于输入的无根树,求出在任何一个时间最多可同时…
Link: 传送门 A: 按值大小插入后用树状数组统计两边个数 #include <bits/stdc++.h> using namespace std; #define X first #define Y second #define pb push_back typedef double db; typedef long long ll; typedef pair<int,int> P; ; P dat[MAXN]; int n,bit[MAXN],dsp[MAXN],l[MA…
Problem 3: Threatening Letter [J. Kuipers, 2002] FJ has had a terrible fight with his neighbor and wants to send him a nasty letter, but wants to remain anonymous. As so many before him have done, he plans to cut out printed letters and paste them on…
N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we all know, some cows code better than others. Each cow has a certain constant skill rating that is unique among the competitors. The contest is conduct…
题目: Invert Binary Tree Total Accepted: 20346 Total Submissions: 57084My Submissions Question Solution Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia:This problem was inspired by this original tweet by Max Howell:…
题目: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1. 代码: /** * Definition for a bina…
Problem E. Split The Tree Problem Description You are given a tree with n vertices, numbered from 1 to n. ith vertex has a value wi We define the weight of a tree as the number of different vertex value in the tree. If we delete one edge in the tree,…