月中第二次测评2024.4.14

前言:

这次第二次测评总分900,得830,难度偏简单。

详细成绩:

除e题外其余全都满分。

题目分析:

a题:

作答代码:

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

char cv[100000];

int main(){
	freopen("a.in","r",stdin);
	freopen("a.out","w",stdout); 
	char a,b; //两个字符a,b 
	cin >> a >> b;
	int av = a-65,bv = b-65,cnt = 0; //a-65用ASCLL码算出A-0,其余同理可得 
	int c = av+bv; //计算出a+b的int值 
	bool flag = 1;
	while(c || flag){ //特判c == 0输出A的情况 
		cv[cnt++] = char(c%10+65); //c%10+65是计算出A-0的值 
		c/=10;
		flag = 0;
	} 
	for(int i = cnt-1; i >= 0; i--){ //因为是逆序存储所以要逆序输出 
		cout << cv[i];
	}
	return 0;
}

标程:

#include <bits/stdc++.h>
using namespace std;
int main()
{
    freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);

    char a, b;
    cin >> a >> b;
    int ans = (a - 'A') + (b - 'A');
    if (ans < 10)
        cout << (char)('A' + ans);
    else
        cout << (char)('A' + ans / 10)
             << (char)('A' + ans % 10);
    return 0;
}

b题:

作答代码:

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

int main(){
	freopen("b.in","r",stdin);
	freopen("b.out","w",stdout); 
	long long a,b,ab = 1,ba = 1;
	cin >> a >> b;
	for(int i = 1; i <= b; i++) ab *= a; //循环计算a^b的值 
	for(int i = 1; i <= a; i++) ba *= b; //循环计算b^a的值 
	//判断输出 
	if(ab > ba) cout << "first" << endl;
	else if(ab < ba) cout << "second" << endl;
	else cout << "same" << endl;
	return 0;
}


// plan B
//#include<bits/stdc++.h>
//using namespace std;
//
//int main(){
//	int a,b; cin >> a >> b;
//	long long ab = pow(a,b);
//	long long ba = pow(b,a);
//	if(ab > ba) cout << "first" << endl;
//	else if(ab < ba) cout << "second" << endl;
//	else cout << "same" << endl;
//}

标程:

#include <bits/stdc++.h>
using namespace std;
int main()
{
    freopen("b.in", "r", stdin);
	freopen("b.out", "w", stdout);
    int a, b;
    cin >> a >> b;
    long long ab, ba;
    ab = 1;
    for (int i = 1; i <= b; i++)
        ab *= a;
    ba = 1;
    for (int i = 1; i <= a; i++)
        ba *= b;
    if (ab > ba)
        cout << "first";
    else if (ab < ba)
        cout << "second";
    else
        cout << "same";
    return 0;
}
c题:

作答代码:

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

int a[100000],b[100000];

int main(){
	freopen("c.in","r",stdin);
	freopen("c.out","w",stdout); 
	long long ans = 0; //用于存储答案 
	int n,m,x;
	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		cin >> b[i];
		a[b[i]]++; //用桶的思想,标记数组 
	}
	for(int i = 1; i <= m; i++){
		cin >> x;
		a[b[x]]--;
	}
	for(int i = 1; i <= 10000; i++){
		if(a[i] >= 2){
			ans += (a[i]*(a[i]-1))/2; //组合排列计算公式:[n*(n-1) ]/2
		}
	}
	cout << ans << endl;
	return 0;
}

标程:

#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[1005];
int b[1005];
int cnt[105];
int main()
{
    freopen("c.in", "r", stdin);
	freopen("c.out", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= m; i++)
        cin >> b[i];
    for (int i = 1; i <= n; i++)
        cnt[a[i]]++;
    for (int i = 1; i <= m; i++)
        cnt[a[b[i]]]--;
    int ans = 0;
    for (int i = 1; i <= 100; i++)
        if (cnt[i] >= 2)
            ans += cnt[i] * (cnt[i] - 1) / 2;
    cout << ans << "\n";
    return 0;
}

d题:

作答代码:

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

int main(){
	freopen("d.in","r",stdin);
	freopen("d.out","w",stdout); 
	string s; 
	int n,m;
	getline(cin,s); //全行输入以防空格情况 
	cin >> n >> m;
	n -= 1; //第n个字符对应的下标为n-1 
	for(int i = 1; i <= m; i++){
		if(n >= s.size()) n = 0; //r如果n到达边界从0开始重新遍历 
		cout << s[n];
		n++;
	}
	return 0;
}

标程:

依我拙见好像是一个破环成链的思想。

#include <bits/stdc++.h>
using namespace std;
int main()
{
    freopen("d.in", "r", stdin);
	freopen("d.out", "w", stdout);

    string s, t;
    int n, m;
    cin >> s;
    cin >> n >> m;
    t = "";
    while (t.length() < n + m - 1)
        t += s;
    for (int i = n; i <= n + m - 1; i++)
        cout << t[i - 1];
    return 0;
}

e题:

这道题是我唯一没有满分的题目。正解是一个方向数组,但是我是暴力判断每一种可能但是少判断了两种,应该是为12种可能。

修改过的作答代码:

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

int a[200][200];

int main(){
	freopen("e.in","r",stdin);
	freopen("e.out","w",stdout); 
	int n,m;
	long long cnt = 0; //long long 防爆 
	cin >> n >> m;
	for(int i = 3; i <= n+2; i++){ //i从3开始省判断边界 
		for(int j = 3; j <= m+2; j++){
			char x; cin >> x;
			if(x == '#') a[i][j] = 1;
			else a[i][j] = 0;
		}
	} 
	for(int i = 3; i <= n+2; i++){
		for(int j = 3; j <= m+2; j++){
			if(a[i][j] == 1) continue;
			else {
				bool flag = 0;
				//三个横连情况 
				if((a[i][j-1] && a[i][j-2]) || (a[i][j-1] && a[i][j+1]) || (a[i][j+1] && a[i][j+2])) flag = 1;
				//三个竖连情况 
				if((a[i-1][j] && a[i-2][j]) || (a[i-1][j] && a[i+1][j]) || (a[i+1][j] && a[i+2][j])) flag = 1;
				//六个斜连情况 
				if((a[i-1][j-1] && a[i+1][j+1]) || (a[i+1][j+1] && a[i+2][j+2]) || (a[i-1][j-1] && a[i-2][j-2]) || (a[i-1][j+1] && a[i+1][j-1]) || (a[i-1][j+1] && a[i-2][j+2]) || (a[i+1][j-1] && a[i+2][j-2])) flag = 1;
				if(flag) cnt++; //位置数++ 
			}
		}
	}
	cout << cnt << endl; //输出位置数 
	return 0;
}

标程:

#include <bits/stdc++.h>
using namespace std;
int n, m;
char g[55][55];
// 左上、上、右上、左、右、左下、下右下
int dx[] = {0, -1, -1, -1, 0, 0, 1, 1, 1};
int dy[] = {0, -1, 0, 1, -1, 1, -1, 0, 1};
int main()
{
    freopen("e.in", "r", stdin);
	freopen("e.out", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 2; i <= n + 1; i++)
        for (int j = 2; j <= m + 1; j++)
            cin >> g[i][j];
    int ans = 0;
    for (int i = 2; i <= n + 1; i++)
        for (int j = 2; j <= m + 1; j++)
        {
            if (g[i][j] == '#')
                continue;
            bool flag = false;
            // 作为端点的八个方向
            for (int k = 1; k <= 8; k++)
            {
                int x = i + dx[k];
                int y = j + dy[k];
                int xx = i + 2 * dx[k];
                int yy = j + 2 * dy[k];
                if (g[x][y] == '#' && g[xx][yy] == '#')
                {
                    flag = true;
                    break;
                }
            }
            if (flag)
            {
                ans++;
                continue;
            }
            // 作为中间点的四个方向
            for (int k = 1; k <= 4; k++)
            {
                int x = i + dx[k];
                int y = j + dy[k];
                int xx = i - dx[k];
                int yy = j - dy[k];
                if (g[x][y] == '#' && g[xx][yy] == '#')
                {
                    flag = true;
                    break;
                }
            }
            if (flag)
                ans++;
        }
    cout << ans << "\n";
    return 0;
}

f题:

Ok呀!一道前缀和的板子题,不过需要注意的是数据类型的判定longlong。其实难度没有e题高

作答代码:

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

const int N = 1e5+20;

long long a[N],sa[N],sb[N];

int main(){
	freopen("f.in","r",stdin);
	freopen("f.out","w",stdout); 
	int n,m; cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		sa[i] = sa[i-1]+a[i]; //计算a的前缀和sa 
	}
	sort(a+1,a+n+1); // 对a进行排序,使得a变成b数组 
	for(int i = 1; i <= n; i++){
		sb[i] = sb[i-1]+a[i]; //构建b数组的前缀和sb 
	}
	cin >> m;
	for(int i = 1; i <= m; i++){
		int t,l,r;
		cin >> t >> l >> r;
		if(t == 1) cout << sa[r]-sa[l-1] << endl; //t == 1,输出a的l-r 
		else cout << sb[r]-sb[l-1] << endl; //t == 2,输出b的l-r 
	}
	return 0;
}

标程:

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;
int a[N];
int n, m;
long long s1[N], s2[N];

int main() {
    freopen("f.in", "r", stdin);
	freopen("f.out", "w", stdout);
    scanf("%d", &n);
    
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        s1[i] = s1[i - 1] + a[i]; 
    }
    
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; i++) {
        s2[i] = s2[i - 1] + a[i];
    }
    
    scanf("%d", &m);
    while (m --) {
        int o, l, r; scanf("%d%d%d", &o, &l, &r);
        if (o == 1) {
            cout << s1[r] - s1[l - 1] << endl;
        } else {
            cout << s2[r] - s2[l - 1] << endl;
        }
    }
    
    return 0;
}

 

总结:

这次考试中我本来可以ak的,但是因为情况考虑不充分,方向数组没有掌握而丢分,实属不应该,下次我一定会ak!!呀!!!

记录一下朋友们的分数哈哈哈:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值