莫名其妙的负数
  • 板块P2089 烤鸡
  • 楼主呕你叽娃
  • 当前回复4
  • 已保存回复4
  • 发布时间2023/7/22 04:28
  • 上次更新2023/11/3 08:20:03
查看原帖
莫名其妙的负数
358521
呕你叽娃楼主2023/7/22 04:28

自己试数据的时候发现大于11的最后几行会出现负数类似-2 0 -8 -3 -8 -5 -6 -1 -8 -5,这是怎么了

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

int N, counter = 0, l[1000000];
int a[10] = {1000000000, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1};

void measure(int total, int flag, int num){
    if(flag == 10 && total == N) {
        l[counter] = num;
        counter++;
        return;
    }
    if(flag == 10 && total < N) return;
    for(int j = 1; j < 4; j++){
        if(total+j > N) continue;
        else{
            if(num == 0) measure(total+j, flag+1, j);
            else{
                measure(total+j, flag+1, num*10+j);
            }
        }
    }
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("friedChicken.in", "r", stdin);
        freopen("friedChicken.out", "w", stdout);
    #endif
    cin >> N;
    measure(0, 0, 0);
    if(counter == 0) {
        cout << 0 << endl;
        return 0;
    }
    cout << counter << endl;
    for(int j = 0; j < counter; j++){
        for(int i = 0; i < 10; i++){
            cout << l[j]/a[i] << " ";
            l[j] = l[j]%a[i];
        }
        cout << endl;
    }
    
}
2023/7/22 04:28
加载中...