【codeforces #296(div 1)】ABD题解

A. Glass Carving

time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular w mm × h mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understanding of what to carve and how.

In order not to waste time, he decided to practice the technique of carving. To do this, he makes vertical and horizontal cuts through the entire sheet. This process results in making smaller rectangular fragments of glass. Leonid does not move the newly made glass fragments. In particular, a cut divides each fragment of glass that it goes through into smaller fragments.

After each cut Leonid tries to determine what area the largest of the currently available glass fragments has. Since there appear more and more fragments, this question takes him more and more time and distracts him from the fascinating process.

Leonid offers to divide the labor — he will cut glass, and you will calculate the area of the maximum fragment after each cut. Do you agree?

Input The first line contains three integers w,h,n (2≤w,h≤200000, 1≤n≤200000).

Next n lines contain the descriptions of the cuts. Each description has the form H y or V x. In the first case Leonid makes the horizontal cut at the distance y millimeters (1≤y≤h-1) from the lower edge of the original sheet of glass. In the second case Leonid makes a vertical cut at distance x (1≤x≤w-1) millimeters from the left edge of the original sheet of glass. It is guaranteed that Leonid won’t make two identical cuts.

Output After each cut print on a single line the area of the maximum available glass fragment in mm2.

Sample test(s) input 4 3 4 H 2 V 2 V 3 V 1 output 8 4 4 2 input 7 6 5 H 4 V 3 V 5 H 2 V 1 output 28 16 12 6 4

最大那一块一定是选择长与宽都最大的,所以我们对于长和宽s分别用set来存当前有哪些切割点,以及每一段的长度。

;multiset<int> s,h;set<int> s1,s2,h1,h2;char c[5];int n,m,q,k;int main(){scanf(“%d%d%d”,&m,&n,&q);s.insert(m),s1.insert(0),s1.insert(m),s2.insert(0),s2.insert(-m);h.insert(n),h1.insert(0),h1.insert(n),h2.insert(0),h2.insert(-n);while (q–){scanf(“%s%d”,c,&k);int a,b;if (c[0]==’V’){b=*s1.lower_bound(k),a=-*s2.lower_bound(-k);s1.insert(k),s2.insert(-k);s.erase(s.find(b-a));s.insert(k-a),s.insert(b-k);}else{b=*h1.lower_bound(k),a=-*h2.lower_bound(-k);h1.insert(k),h2.insert(-k);h.erase(h.find(b-a));h.insert(k-a),h.insert(b-k);}cout<<(1LL*(*s.rbegin())*(*h.rbegin()))<<endl;}return 0;}B. Clique Problem

time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as follows. Consider an undirected graph G. It is required to find a subset of vertices C of the maximum size such that any two of them are connected by an edge in graph G. Sounds simple, doesn’t it? Nobody yet knows an algorithm that finds a solution to this problem in polynomial time of the size of the graph. However, as with many other NP-complete problems, the clique problem is easier if you consider a specific type of a graph.

Consider n distinct points on a line. Let the i-th point have the coordinate xi and weight wi. Let’s form graph G, whose vertices are these points and edges connect exactly the pairs of points (i,j), such that the distance between them is not less than the sum of their weights, or more formally: |xi-xj|≥wi+wj.

Find the size of the maximum clique in such graph.

Input The first line contains the integer n (1≤n≤200000) — the number of points.

Each of the next n lines contains two numbers xi, wi (0≤xi≤109,1≤wi≤109) — the coordinate and the weight of a point. All xi are different.

Output Print a single number — the number of vertexes in the maximum clique of the given graph.

Sample test(s) input 4 2 3 3 1 6 1 0 2 output 3 Note If you happen to know how to solve this problem without using the specific properties of the graph formulated in the problem statement, then you are able to get a prize of one million dollars!

思路题+贪心

假设。

Tutorial中的的解法很简单:

因为在路上你就已经收获了自由自在的好心情。

【codeforces #296(div 1)】ABD题解

相关文章:

你感兴趣的文章:

标签云: