跳到正文

个人记录

26.8.15

luluowo约 11 分钟
原文
文章信息与版本

文章信息

发布
2026年8月16日
收录
2026年8月16日
更新
2026年11月13日
篇幅
约 11 分钟

版本

  1. v2当前
  2. v1

声明:代码仅供参考,请勿抄袭!

题目名称难度思路(没有/有一点/有)分数
T805941 T3入门有30
T805942 T4入门有20
T805943 T5普及−有一点-
T805944 T6普及−没有-
T805946 T7普及−没有-

题目详细

T3

  • 题意

    这道题是需要统计n个数字中,每个数字的出现次数,然后按照原数组中的顺序输出,格式为数字 次数,每个数字输出一次。

  • 思路

    将每个数字存入一个桶中,因为有负数,所以需要将输入的数偏移1000再存入桶中,最后再按原数组的顺序输出。

  • 原来的错误代码

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
int s[10000005], tong[10000005];
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    int n;
    cin>>n;
    for(int i = 1;i<=n;i++)
    {
        cin>>s[i];
        tong[s[i]]++;
    }
    for(int i = 1; i <= 100000;i++){
        if (tong[s[i]] > 0){
            cout<<s[i]<<" "<<tong[s[i]]<<endl;
            tong[s[i]] = 0;
        }
    }
	return 0;
}
  • AC代码(记得看注释)
C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
int s[10000005], tong[10000005];//定义一个tong,用来存每个数出现的次数
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    int n;
    cin>>n;
    for(int i = 1;i<=n;i++)
    {
        cin>>s[i];
        tong[s[i] + 1000]++;//偏移后存入桶中
    }
    for(int i = 1; i <= 100000;i++){//将桶遍历一遍
        if (tong[s[i] + 1000] > 0){//如果这个数的个数不为0
            cout<<s[i]<<" "<<tong[s[i] + 1000]<<endl;//那么输出
            tong[s[i] +1000] = 0;//变为0
        }
    }
	return 0;
}
  • 错因

    一开始没有进行偏移,负数无法存入,导致RE

  • 备注

    审题不仔细,没有发现有负数情况

T4

  • 题意

    这道题的意思是输入两个数a和b,输出从a到b之间所有由0, 1, 2, …, 位数-1的数的个数

  • 思路

    for循环遍历,判断i是否为由0, 1, 2, …, 位数-1的数,如果是,则将sum加1。

  • 原来的错误代码

C++
#include<bits/stdc++.h>
using namespace std;
#define int unsigned long long
#define endl '\n'
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    int n, m;
    cin >> n >> m;
    int num = 0;
    for (int i = n; i <= m; i++){
        string s = to_string(i);
        char a[10000005];
        int sum = 0;
        for (int j = 0; j <= s.size()-1; j++){
            a[j] = s[j];
            sum++;
        }
        sort(a+1, a+sum+1);
        int l = 0;
        int k = 0;
        for (int j = 0; j < sum; j++){
            if (l == a[j] - '0'){
                k++;
            }
            l++;
        }
        if (k+1 == sum){
            num++;
        }
    }
    cout << num;
	return 0;
}
  • AC代码(记得看注释)
C++
#include<bits/stdc++.h>
using namespace std;
#define int unsigned long long
#define endl '\n'
int f(int a){//交给函数来做
    int tong[15] = {};//定义一个桶
    int cnt = 0;//最终的循环次数
    while (a){
        tong[a % 10]++;//将桶的的这一位++
        a /= 10;//踢掉这一位
        cnt++;//次数++
    }
    for (int i = 0; i < cnt; i++){
        if (tong[i] == 0){
            return 0;//如果这一位没有,则不为幸运数字。
        }
    }
    return 1;//返回1
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    int n, m, sum = 0;
    cin >> n >> m;
    for (int i = n; i <= m; i++){
        sum += f(i);//如果是,则会加一,否则加0
    }
    cout << sum;//输出
	return 0;
}
  • 错因

    一开始写到一半不知道判断条件怎么写了,就把所有条件列出来了,结果没发现什么规律

  • 备注

    题目有点没读懂,所以没写出来判断条件,题目储备量不够

T5

  • 题意

    输入n, m,n*n的矩阵,还有m行数据,为op,x,y,如果op是1,表示交换第x行和第y行,如果op是0,表示交换第x列和第y列。

  • 思路

    先定义一个a[][]表示n行n列的矩阵和ans[][],表示最终答案, 然后进行输入,输入n, m, n*n的矩阵, m行数据,如果op为1,则把a的x行给ans的y行,a的y行给ans的x行,否则把a的x列给ans的y列,a的y列给ans的x列。

  • 原来的错误代码

    没写

  • AC代码

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N = 1e3 + 5;
int a[N][N], h[100005], l[100005];
signed main()
{
    int n, w;
    cin >> n >> w;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= n; j++){
            cin >> a[i][j];
            l[j] = j;
        }
        h[i] = i;
    }
    for (int i = 1; i <= w; i++){
        int a, b, c;
        cin >> a >> b >> c;
        if (a == 1) swap(h[b], h[c]);
        else swap(l[b], l[c]);
    }
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= n; j++){
            cout << a[h[i]][l[j]] << " ";
        }
        cout << endl;
    }
	return 0;
}
  • 错因

不知到从何下手,不会写

  • 备注

题目储备量不够

T6

  • 题意

    输入四组字符串,根据四组数据制作字母柱状图,将其输出(由空格和星号组成)

  • 思路

    输入四组字符串,将其存入桶,最后遍历桶,如果比最大值i大,则输出“ *”,否则输出“2space”。

  • 原来的错误代码

    没写

  • AC代码

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
int tong[1005];
signed main()
{
    int maxx = 0;
    for (int i = 1; i <= 4; i++){
        string a;
        getline(cin, a);
        for (int j = 0; j < a.size(); j++){
            if (a[j] >= 'A' && a[j] <= 'Z'){
                tong[a[j]]++;
                maxx = max(tong[a[j]], maxx);
            }
        }
        
    }
    //tong['A']10 tong['B']2
    for(int i = maxx; i >= 1; i--)
    {
    	for(int j ='A'; j <= 'Z'; j++)
    	{
    		if (tong[j] >= i){
    			cout << "* ";
			}
			else{
				cout << "  ";
			}
		}
		cout << endl;
	}
    cout << "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z";
	return 0;
}
  • 错因

    没见过这类题,没有思路

T7

  • 题意 输入n, w,每次输入每个选手p的成绩,则当前计划获奖人数为 max(1,⌊p×w%⌋),其中 w 是获奖百分比。

  • 思路

    输入n, w,每次输入每个选手p的成绩,计算出 max(1,⌊p×w%⌋),将其输出。

  • 原来的错误代码

    没写

  • AC代码

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
int tong[1005];
signed main()
{
    int n, m;
    cin >> n >> m;
    for (int p = 1; p <= n; p++){
        int t;
        cin >> t;
        tong[t]++;
        int fs = max(1ll, p * m / 100);
        int cnt=0;
        for(int j=600;j>=0;j--){
            cnt += tong[j];
            if(cnt >= fs)
            {
                cout<<j<<" ";
                break;
            }
        }
    }
	return 0;
}
  • 错因:一开始没有思路,不会写

  • 备注

    没见过这类题,没有思路

原文