Codeforces Round #368 (Div. 2) a,b,c,d__codeforces

Source: Internet
Author: User
Tags cmath
This is a disaster. FST the staggered program deleted the stdio.h results reload CPP What's all sorts of miserable
A. Brain ' s Photos
Any one of the C M y appears to be color, otherwise black and white
B. Bakery
Very easy to get the answer is definitely the length of a side
Enumeration Edge, find one end of the warehouse is not the end, take the minimum value can be
C. Pythagorean Triples
can be divided into n odd and even direct construction
Even: n^2-1,n^2+1
Odd: N^2/2,n^2/2+1
D. Persistent Bookcase

We built all the operations into a tree and then traced it directly to DFS.


A.

#include <map>
#include <cmath>
#include <queue>
#include <vector>
# include<cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int main ()
{
	int n,m;
	scanf ("%d%d", &n,&m);
	int i,j;
	string x;
	BOOL Flag=true;
	for (i=1;i<=n;i++)
	{for
		(j=1;j<=m;j++)
		{
			cin>>x;
			if (x== "C" | | x== "M" | | x== "Y")
				flag=false
		}
	if (flag)
		printf ("#Black &white\n");
	else
		printf ("#Color \ n");
	return 0;
}

B.

#include <map> #include <cmath> #include <queue> #include <vector> #include <cstdio> # include<string> #include <cstring> #include <iostream> #include <algorithm> using namespace std
;
	struct line {int s,t,x;
int next;
}A[200001];
int head[100001];
int edge;
BOOL v[100001];
	inline void Add (int s,int t,int x) {a[edge].next=head[s];
	Head[s]=edge;
	A[edge].s=s;
	a[edge].t=t;
A[edge].x=x;
	int main () {int n,m,k;
	scanf ("%d%d%d", &n,&m,&k);
	int i,j;
	int s,t,x;
		for (i=1;i<=m;i++) {scanf ("%d%d%d", &s,&t,&x);
		edge++;
		Add (s,t,x);
		edge++;
	Add (t,s,x);
	int minn=2100000000;
                for (i=1;i<=k;i++) {scanf ("%d", &x);

	V[x]=true;
                for (i=1;i<=edge;i++) {s=a[i].s;t=a[i].t;
          if (V[s]&&!v[t]) minn=min (minn,a[i].x);
	} if (minn!=2100000000) printf ("%d\n", Minn);
	else printf (" -1\n");
return 0; }


C.

#include <map>
#include <cmath>
#include <queue>
#include <vector>
# include<cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int main ()
{
	long long x;
	scanf ("%i64d", &x);
	if (x<=2)
		printf (" -1\n");
	else if (x (Long Long) 2==0)
	{
		long long n=x/(long Long) 2;
		printf ("%i64d%i64d\n", n*n-(Long Long) 1,n*n+ (long Long) 1);
	else
	{
		long long n=x*x;
		printf ("%i64d%i64d\n", n/(Long Long) 2,n/(long Long) 2+1);
	return 0;
}

D.

#include <map> #include <cmath> #include <queue> #include <vector> #include <cstdio> # include<string> #include <cstring> #include <iostream> #include <algorithm> using namespace std
;
	struct line {int s,t,x;
int next;
}A[300001];
int head[200001];
int edge;
	inline void Add (int s,int t) {A[edge].next=head[s];
	Head[s]=edge;
	A[edge].s=s;
a[edge].t=t;
	} struct ques {int x,p;
int i,j;
}ASK[100001];
int n,m;
int xt[1001][1001];
int sx[1001];
int ans[100001];
BOOL v[100001];
	inline void dfs (int d,int sum) {ans[d]=sum;
	int i;
		for (i=head[d];i!=0;i=a[i].next) {int t=a[i].t;
					if (ask[t].x==1) {if (!v[ask[t].i]) {if (xt[ask[t].i][ask[t].j]!=1) {sx[ask[t].i]++;
					Xt[ask[t].i][ask[t].j]=1;
					DFS (T,SUM+1);
					sx[ask[t].i]--;
				xt[ask[t].i][ask[t].j]=0;
			else Dfs (t,sum);
					} else {if (xt[ask[t].i][ask[t].j]!=0) {sx[ask[t].i]++;
					xt[ask[t].i][ask[t].j]=0; DFS (T,SUM+1);
					sx[ask[t].i]--;
				Xt[ask[t].i][ask[t].j]=1;
			else Dfs (t,sum);
					} else if (ask[t].x==2) {if (!v[ask[t].i]) {if (xt[ask[t].i][ask[t].j]!=0) {sx[ask[t].i]--;
					xt[ask[t].i][ask[t].j]=0;
					DFS (T,SUM-1);
					sx[ask[t].i]++;
				Xt[ask[t].i][ask[t].j]=1;
			else Dfs (t,sum);
					} else {if (xt[ask[t].i][ask[t].j]!=1) {sx[ask[t].i]--;
					Xt[ask[t].i][ask[t].j]=1;
					DFS (T,SUM-1);
					sx[ask[t].i]++;
				xt[ask[t].i][ask[t].j]=0;
			else Dfs (t,sum);
			} else if (ask[t].x==3) {int dt=sx[ask[t].i];
			SX[ASK[T].I]=M-DT;
			if (v[ask[t].i]) V[ask[t].i]=false;
			else v[ask[t].i]=true;
			DFS (T,SUM-DT+SX[ASK[T].I]);
			SX[ASK[T].I]=DT;
			if (v[ask[t].i]) V[ask[t].i]=false;
		else v[ask[t].i]=true;
	int main () {int q;
	scanf ("%d%d%d", &n,&m,&q);
	int i,j;
		for (i=1;i<=q;i++) {scanf ("%d", &ask[i].x); if (ask[i].x==1| |
ask[i].x==2)			scanf ("%d%d", &AMP;ASK[I].I,&AMP;ASK[I].J);
		Else scanf ("%d", &ask[i].i);
	Ask[i].p=i;
	int la=0;
			for (i=1;i<=q;i++) {if (ask[i].x!=4) {edge++;
			Add (la,i);
		La=i;
			else {la=ask[i].i;
			while (ask[la].x==4) la=ask[la].i;
		Ask[i].i=la;
	} memset (ANS) (ans,-1,sizeof);
	DFS (0,0);
	for (i=1;i<=q;i++) if (ans[i]==-1) ans[i]=ans[ask[i].i];
	for (i=1;i<=q;i++) printf ("%d\n", Ans[i]);
return 0; }


Related Article

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.