Codeforces Round #368 (DIV 2) __codeforces

Source: Internet
Author: User

Last night at the 9-point cf,div2, in order to rating change opened the trumpet.

Speaking of the last one is also DIV2 the trumpet to attend, and then the first trumpet on the 1900, last night after playing the second trumpet also on the DIV1. Very happy.

The last time at home is probably not in the 12:30 cf. After all, to replenish sleep.


Partial puzzle:

Codeforces 707A Brain ' s Photos

Topic Link: Http://www.codeforces.com/problemset/problem/707/A

For a matrix, there are no letters except b,w,g in the judgment matrix.

Analysis: Water problem, scan the judge can again.

Cough, just started playing when the DotA people are not sober, the title did not read to knock, did not see G also calculate, only judged B and W, the result is water over the test data. Later, after being hack, I looked over the words and scolded myself silly X.

<span style= "FONT-SIZE:18PX;" >/***********************************************
 | Author:fry
 | Created time:2016/8/20 20:59:40
 | File Name:a.cpp
 | Copyright: 
 |  For personal use, feel free to use
 |  Otherwise call me at Http://blog.csdn.net/fry_guest 
***********************************************/
# Include <bits/stdc++.h>
using namespace std;

int main ()
{
	int n,m;
	char c;
	BOOL F=false;
	while (~SCANF ("%d%d", &n,&m)) {
		f=false;
		for (int i=1;i<=n;i++) {
			for (int j=1;j<=m;j++) {
				scanf ("%c", &c);
				if (c!= ' B ' &&c!= ' W ' &&c!= ' G ') f=true;
			}
		if (f) printf ("#Color \ n");
		else printf ("#Black &white\n");
	}
	return 0;
}

</span>

Codeforces 707B Bakery

Topic Link: Http://www.codeforces.com/problemset/problem/707/B

Give a picture, have a heavy edge. Some of these points have been marked to find an unmarked point that minimizes the distance from the nearest marked point. Output minimum distance, if there is no such point output-1.

Analysis: It can be concluded that the final answer must be adjacent to a marked point.

Then just enumerate all the marked points, and then enumerate all of their adjacent points.

Writing is not very clear, the code is very ugly.

<span style= "FONT-SIZE:18PX;" >/*********************************************** | Author:fry | Created TIME:2016/8/20 21:15:37 | File Name:b.cpp |  Copyright: |  For personal use, feel free to use | Otherwise call me at Http://blog.csdn.net/fry_guest ***********************************************/#include <
Bits/stdc++.h> using namespace std;
const int n=1e5+5;
	struct point {int x,c;
	Point (int _x=0,int _c=0) {x=_x; c=_c;
}
};
vector<point>v[n];
BOOL Check[n];
int ans;
			void DW (int x) {for (int i=0;i<v[x].size (); i++) {if (!check[v[x][i].x)) {if (ans==-1) {ans=v[x][i].c;
		else Ans=min (V[x][i].c,ans);
	int main () {int n,m,k;
	int l,r,c;
		while (~SCANF ("%d%d%d", &n,&m,&k)) {for (int i=1;i<=n;i++) v[i].clear ();
			for (int i=1;i<=m;i++) {scanf ("%d%d%d", &l,&r,&c);
			V[l].push_back (Point (R,c));
		V[r].push_back (Point (L,c));
		} memset (check,0,sizeof (check)); for (int i=1;i<=k;i++) {ScanF ("%d", &c);
		Check[c]=1;
		} ans=-1;
			for (int i=1;i<=n;i++) {if (Check[i]) {DW (i);
	} printf ("%d\n", ans);
return 0; } </span>

Codeforces 707C Pythagorean Triples

Topic Link: Http://www.codeforces.com/problemset/problem/707/C

An edge of a known right-angled triangle, asking for possible additional two edges. Three edges are positive integers, n<1e9, the final result is less than 1e18. No solution output-1

Analysis: It is easy to learn that when the given edge length is less than 3 o'clock, there is no solution.

So next, let's assume that the given edge is a rectangular edge. The other two side lengths are A,b, where B is the hypotenuse

It can be drawn from the Pythagorean theorem: a*a+n*n=b*b

The formula is adjusted slightly: (b-a) (b+a) =n*n

When n is odd, only the b-a=1,b+a=n*n can be made.

When n is an even number, only the B-A=2,B+A=N*N/2 can be made.

After the completion of the calculation of the limit data, even and odd numbers are about 2.5e17 and 5e17, will not exceed the upper limit.


<span style= "FONT-SIZE:18PX;" >/***********************************************
 | Author:fry
 | Created time:2016/8/20 21:26:03
 | File Name:c.cpp
 | Copyright: 
 |  For personal use, feel free to use
 |  Otherwise call me at Http://blog.csdn.net/fry_guest 
***********************************************/
# Include <bits/stdc++.h>
using namespace std;

int main ()
{
	long long n,a,b;
	while (~SCANF ("%i64d", &n)) {
		if (n<3) {
			printf (" -1\n");
			Continue;
		}
		if (n%2) {
			a=n*n/2;
			b=a+1;
			printf ("%i64d%i64d\n", a,b);
		}
		else {
			a=n*n/2/2-1;
			b=a+2;
			printf ("%i64d%i64d\n", a,b);
		}
	return 0;
}

</span>

Codeforces 707D Persistent Bookcase

Topic Link: Http://www.codeforces.com/problemset/problem/707/D

The book: There is a row of n rows m shelves, initially empty, the existing Q operation, require output after each operation of the bookshelf there are several books.

The operation is divided into 4 kinds:

1. Put a book in J of Line I. If there is already a book in line J before the operation, then ignore this operation.

2. Take away the book in paragraph J of line I. If there are no books in line J before the operation, then ignore this operation.

3. Reverse all books in line I. For all columns in line I, if there is a book in this position, take it away, and if there is no book in that position, put a book in that position.

4. The status of the entire bookshelf will now be returned to the end of the first k operation.

1<=n,m<=1e3,1<=q<=1e5


Analysis: In fact, the original topic has mentioned the persistence of data structure, listen to the teammate said she this problem directly wrote a persistent tree on a.

I did not think of the persistent tree (well, it is actually not written), a little way past.

It's easy to build all the operations into a tree and then operate on the tree.

First the root node must be the No. 0 time, that is, the initial value is null, for the next I operation, if this operation is not operation 4, then its Father node is the first i-1 operation, if this operation is Operation 4 and is returned to the first K operation after the appearance, then the node of the father is the K-operation.

Once the tree is finished, the tree is traversed. Backtrack to remove the original operation.

It should be noted that the original operation may not exist, such as the original I line J column already has a book, this operation requires the addition of a book in this position, then will not operate, the same time back can not take the book away.


Regarding memory, the teammate can use the persistence to be able direct, actually n*q memory is no problem. The memory of my method is O (min (q,n*m)).

Time complexity, violent operation, add and delete operations is the complexity of O (1), the inversion of the complexity is O (M), although the Sense O (q*m) can also look like,

But I changed my posture, and when I recorded it, I used a mark to record the reversal of each line. And each row opens a set to record where there is a book, so the final time complexity, add and delete operations is O (LOGM), the reverse complexity is O (1), the final complexity O (Q*LOGM)


<span style= "FONT-SIZE:18PX;" >/*********************************************** | Author:fry | Created TIME:2016/8/20 21:37:29 | File Name:d.cpp |  Copyright: |  For personal use, feel free to use | Otherwise call me at Http://blog.csdn.net/fry_guest ***********************************************/#include <
Bits/stdc++.h> using namespace std;
const int n=1e5+5;
int ans[n],t[n],x[n],y[n];
set<int>s[n];
vector<int>v[n];
BOOL Check[n];
int n,m;
	void DW (int a,int sum) {bool f=false;
			if (t[a]!=4) {if (t[a]==3) {f=true;
			if (!check[x[a]]) sum-=s[x[a]].size ();
			else Sum-=m-s[x[a]].size ();
			Check[x[a]]=!check[x[a]];
			if (!check[x[a]]) sum+=s[x[a]].size ();
		else Sum+=m-s[x[a]].size ();
					else if (t[a]==2) {if (!check[x[a]]) {if (S[x[a]].find (y[a))!=s[x[a]].end ()) {s[x[a]].erase (y[a));
					sum--;
				F=true;
					} else {if (S[x[a]].find (Y[a]) ==s[x[a]].end ()) {S[x[a]].insert (y[a]);
					sum--;
				F=true; }
			} else if (t[a]==1) {if (!check[x[a]]) {if (S[x[a]].find (y[a)) ==s[x[a]].end ()) {S[x[a]].insert (y[a)
					);
					sum++;
				F=true;
					} else {if (S[x[a]].find (Y[a])!=s[x[a]].end ()) {s[x[a]].erase (y[a]);
					sum++;
				F=true;
	}}} Ans[a]=sum;
	for (int i=0;i<v[a].size (); i++) {DW (v[a][i],sum);
		} if (f) {if (t[a]==3) check[x[a]]=!check[x[a]];
			if (t[a]==2) {if (!check[x[a]]) S[x[a]].insert (y[a));
		else S[x[a]].erase (Y[a]);
			} if (t[a]==1) {if (!check[x[a]]) s[x[a]].erase (y[a));
		else S[x[a]].insert (Y[a]);
	int main () {int q;
		while (~SCANF ("%d%d%d", &n,&m,&q)) {memset (check,0,sizeof (check));
		for (int i=0;i<=n;i++) v[i].clear ();
		for (int i=0;i<=n;i++) s[i].clear ();
			for (int i=1;i<=q;i++) {scanf ("%d", &t[i]);
			if (t[i]<3) {scanf ("%d%d", &x[i],&y[i]);
		Else scanf ("%d", &x[i]); for (int i=1;i<=q;i++) {if (t[i]==4) {V[x[i]].push_baCK (i);
			} if (i!=q&&t[i+1]!=4) {v[i].push_back (i+1);
		} if (t[1]!=4) {v[0].push_back (1);
		for (int i=0;i<v[0].size (); i++) {DW (v[0][i],0);
		for (int i=1;i<=q;i++) {printf ("%d\n", Ans[i]);
} return 0; } </span>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.