https://zufeoj.com/contest.php?cid=1483

 

问题 A: A

代码:

zufe 蓝桥选拔-编程知识网zufe 蓝桥选拔-编程知识网

#include <bits/stdc++.h>
using namespace std;const int maxn = 1e5 + 10;
int n;
int num[maxn];
map<int, int> mp;int main() {scanf("%d", &n);for(int i = 0; i < n; i ++) {scanf("%d", &num[i]);mp[num[i]] ++;}sort(num, num + n);int maxx = num[n - 1];for(int i = 0; i <= maxx; i ++)printf("%d\n", mp[i]);return 0;
}

View Code

问题 B: 平方数(sevensqr)

代码:

zufe 蓝桥选拔-编程知识网zufe 蓝桥选拔-编程知识网

#include <bits/stdc++.h>
using namespace std;bool is(int x) {vector<int> num;int t = x;while(t) {num.push_back(t % 10);t /= 10;}map<int, int> mp;for(int i = 0; i < num.size(); i ++) {mp[num[i]] ++;if(mp[num[i]] > 1) return false;}return true;
}int main() {vector<int> ans;for(int i = 1000000; i < 10000000; i ++) {if((int)sqrt(i) == sqrt(i) && is(i))ans.push_back(i);}int cnt = 0;for(int i = 0; i < ans.size(); i ++) {cnt ++;printf("%d ", ans[i]);printf("%s", (cnt % 10 == 0) ? "\n" : "");}return 0;
}

View Code

问题 C: 打印图形

 代码:

zufe 蓝桥选拔-编程知识网zufe 蓝桥选拔-编程知识网

#include <bits/stdc++.h>
using namespace std;int T;
char mp[1010][1010];int main() {scanf("%d", &T);while(T --) {int n;scanf("%d", &n);for(int i = 1; i <= n; i ++) {for(int j = 1; j <= n; j ++) {if(i == j) mp[i][j] = '*';else if(i == 1 || i == n)mp[i][j] = '*';else if(j == 1 || j == n)mp[i][j] = '*';else mp[i][j] = '.';}}for(int i = 1; i <= n; i ++) {for(int j = 1; j <= n; j ++)printf("%c", mp[i][j]);printf("\n");}}return 0;
}

View Code

问题 D: 借书

 代码:

zufe 蓝桥选拔-编程知识网zufe 蓝桥选拔-编程知识网

#include <bits/stdc++.h>
using namespace std;int T;
int n, m, w;
int book[100];int main() {scanf("%d", &T);while(T --) {scanf("%d", &n);for(int i = 1; i <= n; i ++)scanf("%d", &book[i]);scanf("%d", &m);while(m --) {int x;scanf("%d", &x);if(x > 0) book[x] --;else book[abs(x)] ++;}scanf("%d", &w);if(book[w] > 1)printf("yes\n");else printf("no\n");}return 0;
}

View Code

问题 E: 九宫

 代码:

zufe 蓝桥选拔-编程知识网zufe 蓝桥选拔-编程知识网

#include <bits/stdc++.h>
using namespace std;int T;
int maze[10][10];int main() {scanf("%d", &T);for(int y = 1; y <= T; y ++) {memset(maze, 0, sizeof(maze));for(int i = 0; i < 9; i ++)for(int j = 0; j < 9; j ++)scanf("%d", &maze[i][j]);map<int, int> mp;bool flag = true;for(int i = 0; i < 9; i ++) {for(int j = 0; j < 0; j ++) {mp[maze[i][j]] ++;if(mp[maze[i][j]] > 1) {flag = false;//printf("Wrong\n");break;}}mp.clear();}for(int i = 0; i < 9; i ++) {for(int j = 0; j < 9; j ++) {mp[maze[j][i]] ++;if(mp[maze[j][i]] > 1) {flag = false;//printf("Wrong\n");break;}}mp.clear();}for(int i = 0; i < 9; i += 3) {for(int j = 0; j < 9; j += 3) {for(int s = i; s < i + 3; s ++) {for(int t = j; t < j + 3; t ++) {mp[maze[s][t]] ++;if(mp[maze[s][t]] > 1) {flag = false;//printf("Wrong\n");break;}}}mp.clear();}}if(flag) printf("Right\n");else printf("Wrong\n");}return 0;
}

View Code

问题 F: 捡石头

 代码:

zufe 蓝桥选拔-编程知识网zufe 蓝桥选拔-编程知识网

#include <bits/stdc++.h>
using namespace std;int T;int main() {scanf("%d", &T);while(T --) {int n;scanf("%d", &n);int win = 1;if(n % 8 == 0)win = 0;if(win) printf("金\n");else printf("勇\n");}return 0;
}

View Code

问题 G: 竞赛真理

 代码:

zufe 蓝桥选拔-编程知识网zufe 蓝桥选拔-编程知识网

#include <bits/stdc++.h>
using namespace std;int n, t;
int w1[50], w2[50], t1[50], t2[50];
int dp[33][1080010];int main() {scanf("%d%d", &n, &t);for(int i = 0; i < n; i ++)scanf("%d%d%d%d", &w1[i], &t1[i], &w2[i], &t2[i]);for(int i = n - 1; i >= 0; i --) {for(int j = 0; j <= t; j ++) {if(j < t1[i] && j < t2[i])dp[i][j] = dp[i + 1][j];else if(j < t1[i] && j >= t2[i])dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - t2[i]] + w2[i]);else if(j >= t1[i] && j < t2[i])dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - t1[i]] + w1[i]);elsedp[i][j] = max(dp[i + 1][j], max(dp[i + 1][j - t1[i]] + w1[i], dp[i + 1][j - t2[i]] + w2[i]));}}int ans = dp[0][t];printf("%d\n", ans);return 0;
}

View Code

问题 H: 吃西瓜

 代码:

zufe 蓝桥选拔-编程知识网zufe 蓝桥选拔-编程知识网

#include <stdio.h>
#include <string.h>
#define max(a, b) (a)>(b)?(a):(b)
#define INF 0x3f3f3f3f3f3f3f
const int N = 25;int t, A, B, C;
long long g[33][51][51], sum[51][51][51][51], res[51][51][51][51];void init() {scanf("%d%d%d", &A, &B, &C);for (int i = 1; i <= A; i++)for (int j = 1; j <= B; j++)for (int k = 1; k <= C; k++)scanf("%lld", &g[i][j][k]);
}long long solve() {long long ans = -INF;for (int c = 1; c <= A; c++) {for (int i = 1; i <= B; i++) {for (int j = i; j <= B; j++) {for (int k = 1; k <= C; k++) {long long h = 0;for (int l = k; l <= C; l++) {h += g[c][j][l];sum[i][j][k][l] = sum[i][j - 1][k][l] + h;if (c == 1) res[i][j][k][l] = sum[i][j][k][l];else res[i][j][k][l] = max(sum[i][j][k][l], res[i][j][k][l] + sum[i][j][k][l]);ans = max(ans, res[i][j][k][l]);}}}}}return ans;
}int main() {//scanf("%d", &t);//while (t--) {
        init();printf("%lld\n", solve());if (t) printf("\n");//}return 0;
}

View Code

附加:二维数组的最大子矩阵和

   代码:

zufe 蓝桥选拔-编程知识网zufe 蓝桥选拔-编程知识网

#include <bits/stdc++.h>
using namespace std;int n, m;int MaxSum(vector<vector<int> >& a) {int cur = 0;int maxx = INT_MIN;for(int i = 0; i < a.size(); i ++) {vector<int> s(a[0].size());for(int j = i; j < a.size(); j ++) {cur = 0;for(int k = 0; k < s.size(); k ++) {s[k] += a[j][k];cur += s[k];maxx = max(maxx, cur);cur = max(cur, 0);}}}return maxx;
}int main() {scanf("%d%d", &n, &m);vector<vector<int> > v(n, vector<int>(m));for(int i = 0; i < n; i ++) {for(int j = 0; j < m; j ++)scanf("%d", &v[i][j]);}int ans = MaxSum(v);printf("%d\n", ans);return 0;
}

View Code

第一次参加的比赛 超级紧脏 还是要好好学呢 当做题做不出来的时候无比想念 FH

转载于:https://www.cnblogs.com/zlrrrr/p/10074041.html