2020蓝桥杯模拟赛(二)

蓝桥杯模拟赛训练二


#include <iostream>
#include <queue>
using namespace std;
int main() {
	int cnt = 0;
	int x = 1200000;
	for (int i = 1; i <= x; i++ ) {
		if (x % i == 0) {
			cnt++;
		}
	}
	cout << cnt << endl;

	return 0;
}

#include <iostream>
#include <queue>
using namespace std;

int f(int x) {
	int cnt = 0;
	while (x) {
		if (x % 10 == 9) {
			cnt++;
			break;
		}
		x /= 10;
	}
	return cnt;
}

int main() {
	int cnt = 0;
	for (int i = 1; i <= 2019; i++) {
		cnt += f(i);
	}
	cout << cnt << endl;

	return 0;
}


#include <iostream>
#include <queue>
using namespace std;

bool f(int i) {
	int a = i % 10;//最后一位
	i /= 10;
	if (i == 0) {
		return true;
	}
	
	while (i) {
		if (a < i % 10) return false;
		a = i % 10;
		i /= 10;
	}

	return true;
}

int main() {
	int cnt = 0;
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cnt += f(i);
	}
	cout << cnt << endl;

	return 0;
}

#include <iostream>
#include <queue>
#include <vector>
using namespace std;
const int max = 105;
char map[105][105];
int visit[105][105];
int n, m;
int dir[4][2] = { {0, 1} , {1, 0} , {-1 , 0} , {0, -1} };

bool in(int x, int y) {
	if (x >= 0 && y >= 0 && x < n && y < m) return true;

	return false;
}

void change() {
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {

			if (visit[i][j] == 2) { //可以去扩增
				for (int k = 0; k < 4; k++) {
					
					int dx = i + dir[k][0];
					int dy = j + dir[k][1];
					
					if (in(dx, dy) && visit[dx][dy] == 0) {

						map[dx][dy] = 'g';
						visit[dx][dy] ++;
					}
				}
			}
		}
		
	}
	
}

void grow() {
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (visit[i][j] != 0 )
				visit[i][j] ++;
		}
	}

}
void print() {

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			printf("%c", map[i][j], visit[i][j]);
		}
		printf("
");
	}
}



int main() {
	
	cin >> n >> m;
	int k;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> map[i][j];
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (map[i][j] == 'g') {
				visit[i][j] ++;
			}
		}
	}

	cin >> k;
	grow();
	
	while (k--) {
		change();
		grow();
		
	}
	print();

	return 0;
}

主要考察结构体配合vector的多级排序问题

#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
const int Max = 100005;
int n, m;
struct node {
	int x; //先按分值排序
	int y; // 再按顺序排序
	node(int o, int v) {
		x = o;
		y = v;
	}
};
bool Less(node xx, node yy) {
	if (xx.y < yy.y) return true;
	 return false;
}
bool Great(node xx, node yy) {
	if (xx.x >= yy.x) return true;
	return false;
}
int main() {
	cin >> n >> m;
	int x;
	vector<node> s;
	for (int i = 0; i < n; i++) {
		
		scanf("%d", &x);
		s.push_back(node( x, i + 1));
	}
	sort(s.begin(), s.end(),Great); //先按分值大小排序
	sort(s.begin(), s.begin() + m, Less);
	for (int i = 0; i < m; i++) {
		printf("%d", s[i].x);
	}
	
	return 0;
}
原文地址:https://www.cnblogs.com/DengSchoo/p/12584483.html