其他分享
首页 > 其他分享> > Codeforces Round #529 (Div. 3) 练习赛

Codeforces Round #529 (Div. 3) 练习赛

作者:互联网

image-20200904205312641

Examples

input

6
baabbb

output

bab

input

10
ooopppssss

output

oops

思路:

模拟等差数列即可

#include<bits/stdc++.h>
using namespace std;
int main() {
	//freopen("in.txt", "r", stdin);
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int n; string s, ss = "";
	cin >> n >> s; int t = 1;
	for (int i = 0; i < n; i += t) {
		ss += s[i], ++t;
	}
	cout << ss << endl;
}

Examples

input

4
1 3 3 7

output

2

input

2
1 100000

output

0

Note

In the first example you can remove \(7\) then instability of the remaining array will be \(3−1=2\).

In the second example you can remove either 11 or 100000100000 then instability of the remaining array will be $100000−100000=0 $ and \(1−1=0\) correspondingly.

思路:

取删最小值或最大值的min

#include<bits/stdc++.h>
using namespace std;
int a[100100];
int main() {
	//freopen("in.txt", "r", stdin);
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int n; cin >> n;
	for (int i = 1; i <= n; ++i)cin >> a[i];
	sort(a + 1, a + 1 + n);
	cout << min(a[n - 1] - a[1], a[n] - a[2]) << endl;
}

image-20200904205614259

Examples

input

9 4

output

YES
1 2 2 4 

思路:

#include<bits/stdc++.h>
using namespace std;
multiset<int>s;
int main() {
	//freopen("in.txt", "r", stdin);
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int n, k;
	cin >> n >> k;
	int m = n;
	for (int i = 0; m; m >>= 1, ++i)if (m & 1)s.insert(1 << i);
	if (n < k || s.size() > k) cout << "NO" << endl;
	else {
		while (s.size() < k) {
			int a = *(--s.end()); s.erase(--s.end());
			if (a == 1)break;
			s.insert(a / 2);
			s.insert(a / 2);
		}
		cout << "YES" << endl;
		while (s.size()) {
			cout << *s.begin() << " ";
			s.erase(s.begin());
		}
	}
}

Ps:成功复习了一遍DFS.

#include<bits/stdc++.h>
using namespace std;
#define maxn 234567
vector<int>g[maxn],o;
int n,x,y,s,t;
void dfs(int u,int p)
{
    if(o.size()==n)return ;
    o.push_back(u);
    if(o.size()==n)return ;
    for(int i=0; i<2; i++)
    {
        if(g[u][i]==p)continue;
        dfs(g[u][i],u);
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d%d",&x,&y);
        if(i==1)s=x,t=y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    if(g[1][1]==s||g[1][1]==t)swap(g[1][0],g[1][1]);
    dfs(1,0);
    for(int i=0; i<n-1; i++)printf("%d ",o[i]);
    printf("%d\n",o[n-1]);
    return 0;
}

标签:练习赛,cout,output,int,cin,input,tie,Div,529
来源: https://www.cnblogs.com/RioTian/p/13616169.html