其他分享
首页 > 其他分享> > Codeforces Round #733

Codeforces Round #733

作者:互联网

image

#include <bits/stdc++.h>
using namespace std;

void solve(){
	int n;
	cin >> n;
	int maxn = -1;
	while(n){
		maxn = max(maxn, n % 10);
		n /= 10;
	}
	cout << maxn << endl;
}
int main(){
	int t;
	cin >> t;
	while(t --){
		solve();
	}
	
	return 0;
}

image
image

#include <bits/stdc++.h>
using namespace std;

int maze[22][22];
void solve(){
	int h, w;
	cin >> h >> w;
	memset(maze, 0, sizeof maze);
	if(h % 2 == 0 && w % 2 == 0){
		for(int i = 1; i <= w; i += 2)
			maze[1][i] = 1, maze[h][i] = 1;
		for(int i = 3; i <= h - 2; i += 2)
			maze[i][1] = 1, maze[i][w] = 1;
	}else if(h % 2 == 1 && w % 2 == 1){
		for(int i = 1; i <= w; i += 2)
			maze[1][i] = 1, maze[h][i] = 1;
		for(int i = 3; i <= h; i += 2)
			maze[i][1] = 1, maze[i][w] = 1;
	}else if(h % 2 == 0 && w % 2 == 1){
		for(int i = 1; i <= w; i += 2)
			maze[1][i] = 1, maze[h][i] = 1;
		for(int i = 3; i <= h - 2; i += 2)
			maze[i][1] = 1, maze[i][w] = 1;
	}else if(h % 2 == 1 && w % 2 == 0){
		for(int i = 1; i <= w; i += 2)
			maze[1][i] = 1, maze[h][i] = 1;
		for(int i = 3; i <= h - 2; i += 2)
			maze[i][1] = 1, maze[i][w] = 1;
	}
	for(int i = 1; i <= h; i ++){
		for(int j = 1; j <= w; j ++)
			cout << maze[i][j];
		cout << endl;
	}
}
int main(){
	int t;
	cin >> t;
	while(t --){
		solve();
	}
	
	return 0;
}

image
image

#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 10;
int a[N], b[N];

int cnt;
void solve(){
	priority_queue<int> p11, p22;
	int n;
	cin >> n;
	for(int i = 1; i <= n; i ++){
		int x;
		cin >> x;
		p11.push(x);
		a[i] = x;
	}
	for(int i = 1; i <= n; i ++){
		int x;
		cin >> x;
		p22.push(x);
		b[i] = x;
	}
	sort(a + 1, a + 1 + n, greater<int>());
	sort(b + 1, b + 1 + n, greater<int>());
	int sum1 = 0, sum2 = 0;
	for(int i = 1; i <= n - n / 4; i ++){
		int t = p11.top();
		p11.pop();
		sum1 += t;
		t = p22.top();
		p22.pop();
		sum2 += t;
	}
	if(sum1 >= sum2){
		cout << 0 << endl;
		return;
	}
	int ans = 0;
	int flag = n - n / 4;
	while(sum1 < sum2){
		++ ans;
		if((n + ans) % 4 == 0){
			if(flag){
				sum1 -= a[flag];
				flag --;
				sum1 += 100;
			}else
				sum1 += 100;
		}else{
			sum1 += 100;
		}
		
		if(p22.size()){
			if((n + ans) % 4 == 0){
				sum2 += 0;
			}else{
				sum2 += p22.top();
				p22.pop();
			}
		}else
			sum2 += 0;
	}
		cout << ans << endl;
}
int main(){
	int t;
	cin >> t;
	while(t --){
		cnt ++;
		solve();
	}
	
	return 0;
}

image
image

#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 10;

void solve(){
	int n, cnt = 0;
	vector<int> vec1, vec2;
	scanf("%d", &n);
	int a[n + 1], source[n + 1], ans[n + 1];
	memset(ans, 0, sizeof ans);
	memset(source, 0, sizeof ans);
	for(int i = 1; i <= n; i ++){
		scanf("%d", &a[i]);
		if(!source[a[i]]){
			cnt ++;
			source[a[i]] = i;
			ans[i] = a[i];
		}else{
			vec1.push_back(i);
		}
	}
	for(int i = 1; i <= n; i ++){
		if(source[i] == 0)
			vec2.push_back(i);
	}
	for(int i = 0; i < vec1.size(); i ++)
		ans[vec1[i]] = vec2[i];
	for(int i = 1; i <= n; i ++){
		if(ans[i] == i){
			ans[i] = a[i];
			int s = source[a[i]];
			ans[s] = i;
			source[a[i]] = i;
		}
	}
	printf("%d\n", cnt);
	for(int i = 1; i <= n; i ++)
		printf("%d ", ans[i]);
	printf("\n");
}
int main(){
	int t;
	scanf("%d", &t);
	while(t --){
		solve();
	}
	
	return 0; 
}

标签:std,int,void,Codeforces,733,solve,using,include,Round
来源: https://www.cnblogs.com/pureayu/p/15032988.html