2 solutions

  • 3
    @ 2025-10-2 9:53:37

    这题的核心思路就是用题目的提示来判断能不能填充1 直接来看代码(此代码为不要三个一的目前最短代码 但不是最快的)

    #include<cstdio>
    char s[101];int n,m,a,i;
    main(){freopen("three.in","r",stdin);freopen("three.out","w",stdout);scanf("%d%d",&n,&m);for(i=0;i<n&&a<m;++i)if(i<2||!(s[i-1]=='1'&&s[i-2]=='1'))s[i]='1',a++;else s[i]='0';while(i<n)s[i++]='0';printf("%s",s);}
    
  • 0
    @ 2025-10-1 11:37:52

    #include <bits/stdc++.h> #include #include #ifdef linux #include #endif #define int long long using std::cin; using std::cout; const int N = 1e3 + 10; int a[N], ans[N], cnt; int n, k;

    void dfs(int n, int k) { for (int i = 1; i <= k; i++) ans[i] = n / k; cnt = n % k; for (int i = 1; i <= n - (n - cnt); i++) ans[i]++; for (int i = 1; i <= n; i++) if (a[i] != 0) for (int j = 1; j <= k; j++) if (a[i] == j) ans[j]--; return ; }

    main(void) { #ifdef linux freopen("light.in", "r", stdin); freopen("light.out", "w", stdout); #endif cin >> n >> k; for (int i = 1; i <= n; i++) { std::cin >> a[i]; } dfs(n, k); for (int i = 1; i <= k; i++) { cout << ans[i] << " "; } return false; }

    • 1

    Information

    ID
    4487
    Time
    1000ms
    Memory
    512MiB
    Difficulty
    5
    Tags
    (None)
    # Submissions
    146
    Accepted
    60
    Uploaded By