关于memset()
  • 板块P1239 计数器
  • 楼主dendky
  • 当前回复8
  • 已保存回复8
  • 发布时间2024/10/21 19:39
  • 上次更新2024/10/21 20:50:53
查看原帖
关于memset()
1365127
dendky楼主2024/10/21 19:39
#include <bits/stdc++.h>
using namespace std;
long long n;
long long ans[105];
long long a[105];
void zz(long long cnt){
    while (cnt>0){
        ans[cnt%10]++;
        cnt/=10;
    }
}//桶排,应该是吧。。
int main(){
    ios::sync_with_stdio(false); 
    cin.tie(0); cout.tie(0);
    cin>>n;
    int x=n/10000, y;
    if (n<10000){
        for (int i=1; i<=n; i++) zz(i);//n<1e4特判
    }else {
        for (long long i=1; i<=9999; i++){
            zz(i);
        }//判断1~9999部分
        for (long long i=1; i<=x-1; i++){
            memset (a, 0, sizeof(a));
            y=i;
            while (y>0){
                a[y%10]++;
                y/=10;
            }
            for (long long j=0; j<=9; j++){
                ans[j]+=a[j]*10000;
            }
        }
        for (long long i=0; i<=9; i++){
            ans[i]+=4000*(x-1);
        }
        for (long long i=x*10000; i<=n; i++){
            zz(i);
        }
    }
    for (long long i=0; i<=9; i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}

这是我看了tj后写的,原本没有memset,一直也以为这个函数没什么用,但这题加了60变100,蒟蒻求原因QAQ

2024/10/21 19:39
加载中...