P1319 压缩技术

P1319 压缩技术

Lizzycoder @ 2022-04-04 20:51:55

为什么TLE?( 求助大神:( )

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,sum = 0;
    int lie = 0;
    cin >> n;
    int x,jo;
    while(sum < n * n)
    {
        cin >> x;
        jo ++;
        if(jo % 2 == 1)
        {
            for(int i = 1;i <= x;i++)
            {
                if(lie < n)
                {
                    cout<< 1;
                    lie ++;
                }
                else
                {
                    lie = 0;
                    cout<<endl;
                    cout<<1;
                    lie++;
                }
            }
        }
        else
        {
            for(int i = 1;i <= x;i++)
            {
                if(lie < n)
                {
                    cout<< 0;
                    lie ++;
                }
                else
                {
                    lie = 0;
                    cout<<endl;
                    cout<<0;
                    lie++;
                }
            }
        }
    }
}

by Lizzycoder @ 2022-04-04 20:52:12

0分


by Avocadooo @ 2022-04-04 21:01:14

while(sum<n*n) sum始终为 0???


by Lizzycoder @ 2022-04-04 21:22:50

@乔木生夏凉 加上了sum++; 可是还是90分。


by Lizzycoder @ 2022-04-05 16:36:41

@乔木生夏凉 谢谢指导,过了:)


by 大宝和小宝 @ 2022-05-14 09:59:48

#include <iostream>
using namespace std;
int a[40005];
int main() {
    int n,s=0,c=0;
    cin>>n;
    for(int i=1;i<=40005;i++){
        if(s>=n*n){
            break;
        }
        cin>>a[i];
        s=s+a[i];
    }
   for(int i=1;i<=40005;i++){
        if(i%2!=0){
            for(int j=1;j<=a[i]; j++){
                cout<<0;
                c++;
                if(c%n==0){
                    cout<<endl;
                }
            }
        }
        else{
            for(int j=1;j<=a[i];j++){
                cout<<1;
                c++;
                if(c%n==0){
                    cout<<endl;
                }
            }
        }
    }
    return 0;
}

by Lizzycoder @ 2022-08-23 19:17:15

@大宝和小宝 谢谢(迟来的)


|