Daily algorithm - day 46

Daily algorithm

those times when you get up early and you work hard; those times when you stay up late and you work hard; those times when don’t feel like working — you’re too tired, you don’t want to push yourself — but you do it anyway. That is actually the dream. That’s the dream. It’s not the destination, it’s the journey. And if you guys can understand that, what you’ll see happen is that you won’t accomplish your dreams, your dreams won’t come true, something greater will. mamba out


Those spare your hard work pay, you do not want to train, when you feel tired but still have to adhere to teeth when that chasing a dream, do not care what the end there, the road to enjoy the process, perhaps you can not dream of success, but there will be more great things will follow. mamba out ~

2020.4.1


627Div3

A

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>

using namespace std;
const int N = 105;
int t, a[N];
int n;
void work()
{
	cin >> n;
	bool flag1 = 0, flag2 = 0;
	for(int i = 1;i <= n ;i ++)
	{
		scanf("%d",&a[i]);
		if(a[i] % 2 == 0)
		{
			flag1 = 1;
		}else flag2 = 1;
	}
	if(flag1 && flag2){
		cout << "NO" << endl;
	}else cout << "YES" << endl;
} 
int main()
{

	cin >> t;
	while(t--)
	{
		work();
	}
	return 0;
}

B

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>

using namespace std;
const int N = 5005;
int t , n;
void work()
{
	int a[N] = {0};
	cin >> n;
	for(int i = 1;i <= n ;i ++)
	{
		scanf("%d",&a[i]);
	}
	int k = 0;
	for(int i = 1; i <= n ;i ++)
	{
		for(int j = i + 1;j <= n ;j ++)
		{
			if(a[j] != a[i])k = 0;
			if(a[j] == a[i] && j - i > 1 && !k)
			{
				cout << "YES" << endl;
				return ;
			}
		}
	}
	cout << "NO" << endl;
	return;
}
int main()
{
	cin >> t;
	while(t--)
	{
		work();
	}
	return 0;
}

C

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <algorithm>

using namespace std;

int t = 0;


void work()
{
	string s;cin >> s;
	unsigned int i = 0;
	int minc = 0;int t = 0;
	while(i < s.size())
	{
		if(s[i] == 'L'){
			t++;
		}
		if(s[i] == 'R' || i == s.size() - 1){
			minc = max(minc,t);
			t = 0;
		}
		i++;
	}
	cout << minc + 1 << endl;
}
int main()
{
	cin >> t;
	while(t--)
	{
		work();
	}
	return 0;
}

P1111 road repairs

Review road trim review disjoint-set sleepy ~~~

#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;
const int N = 1010;
const int M = 200005;
int f[N] , n , m;
struct node{
	int a , b , c;
};
node a[M];
bool cmp(node a,node b)
{
	return a.c < b.c;
}
int find(int k)
{
	if(f[k] == k)return k;
	else return f[k] = find(f[k]);
}
int main()
{
	cin >> n >> m;
	for(int i = 0;i < m;i ++)
	{
		scanf("%d %d %d",&a[i].a,&a[i].b,&a[i].c);	
	}
	sort(a , a + m , cmp);
	for(int i = 1;i <= n ;i ++)f[i] = i;
	int cnt = 1;
	for(int i = 0;i < m;i ++)
	{
		int x = find(a[i].a), y = find(a[i].b);
		if(x != y)
		{
			f[x] = y;
			cnt++;
		}
		if(cnt == n){
			cout << a[i].c << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

Guess you like

Origin www.cnblogs.com/wlw-x/p/12616866.html