#26714: 如果你卡在WA(line:80),可以參考看看


bubble60324@gmail.com (賢仔)

學校 : 高雄市立前鎮高級中學
編號 : 120822
來源 : [1.174.192.154]
最後登入時間 :
2022-09-22 09:21:26
c086. 00402 - M*A*S*H -- UVa402 | From: [202.151.48.206] | 發表日期 : 2021-08-21 11:09

檢查了很多次 都不太明白卡在這裡的可能原因

以下是我AC的程式碼

我WA(line:80)跟AC的程式碼只差在

我在每個隊伍的最後一個元素輸出後沒有再一個空格

還請知道原因的大神指導一下

#include<bits/stdc++.h>
using namespace std;
int a[55];
bool ta[55];
int n,m,now,nowp;
int sum=0;
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    while(cin >> n >> m){
        sum++;
        for(int x=1;x<=n;x++){
            a[x]=x;
        }
        memset(ta,0,sizeof(ta));
        bool ta1=false;
        nowp=n;
        if(n<=m)ta1=true;
        for(int x=0;x<20;x++){
            cin >> now;
            if(!ta1){
                int num=0;
                for(int y=1;y<=n;y++){
                    if(!ta[y]){
                        num++;
                        if(num==now){
                            num=0;
                            ta[y]=true;
                            nowp--;
                        }
                    }
                    if(nowp==m){
                        ta1=true;
                        break;
                    }
                }
                if(nowp==m){
                    ta1=true;
                }
            }
            // cout << nowp << " ";
        }
        cout << "Selection #" << sum << endl;
        for(int x=1;x<n;x++){
            // cout << "p" << endl;
            if(!ta[x]){
                cout << x << " ";
            }
        }
        if(!ta[n])cout << n;
        cout << endl;
        cout << endl;
    }
    return 0;
}
 
#26715: Re:如果你卡在WA(line:80),可以參考看看


bubble60324@gmail.com (賢仔)

學校 : 高雄市立前鎮高級中學
編號 : 120822
來源 : [1.174.192.154]
最後登入時間 :
2022-09-22 09:21:26
c086. 00402 - M*A*S*H -- UVa402 | From: [202.151.48.206] | 發表日期 : 2021-08-21 11:11

檢查了很多次 都不太明白卡在這裡的可能原因

以下是我AC的程式碼

我WA(line:80)跟AC的程式碼只差在

我在每個隊伍的最後一個元素輸出後沒有再一個空格

還請知道原因的大神指導一下

#include<bits/stdc++.h>
using namespace std;
int a[55];
bool ta[55];
int n,m,now,nowp;
int sum=0;
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    while(cin >> n >> m){
        sum++;
        for(int x=1;x<=n;x++){
            a[x]=x;
        }
        memset(ta,0,sizeof(ta));
        bool ta1=false;
        nowp=n;
        if(n<=m)ta1=true;
        for(int x=0;x<20;x++){
            cin >> now;
            if(!ta1){
                int num=0;
                for(int y=1;y<=n;y++){
                    if(!ta[y]){
                        num++;
                        if(num==now){
                            num=0;
                            ta[y]=true;
                            nowp--;
                        }
                    }
                    if(nowp==m){
                        ta1=true;
                        break;
                    }
                }
                if(nowp==m){
                    ta1=true;
                }
            }
            // cout << nowp << " ";
        }
        cout << "Selection #" << sum << endl;
        for(int x=1;x<n;x++){
            // cout << "p" << endl;
            if(!ta[x]){
                cout << x << " ";
            }
        }
        if(!ta[n])cout << n;
        cout << endl;
        cout << endl;
    }
    return 0;
}

痾 如果不會的你看到這篇文 希望你不要直接抄 

我很抱歉直接貼出AC的程式碼 

我為我的思考不夠周全道歉:(

 

 
#36582: Re: 如果你卡在WA(line:80),可以參考看看


goodlogic (GoodLogic)

學校 : 中原大學
編號 : 236459
來源 : [223.141.195.113]
最後登入時間 :
2024-04-22 12:53:24
c086. 00402 - M*A*S*H -- UVa402 | From: [111.82.202.63] | 發表日期 : 2023-07-25 00:45

檢查了很多次 都不太明白卡在這裡的可能原因

以下是我AC的程式碼

我WA(line:80)跟AC的程式碼只差在

我在每個隊伍的最後一個元素輸出後沒有再一個空格

還請知道原因的大神指導一下

#include
using namespace std;
int a[55];
bool ta[55];
int n,m,now,nowp;
int sum=0;
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    while(cin >> n >> m){
        sum++;
        for(int x=1;x<=n;x++){
            a[x]=x;
        }
        memset(ta,0,sizeof(ta));
        bool ta1=false;
        nowp=n;
        if(n<=m)ta1=true;
        for(int x=0;x<20;x++){
            cin >> now;
            if(!ta1){
                int num=0;
                for(int y=1;y<=n;y++){
                    if(!ta[y]){
                        num++;
                        if(num==now){
                            num=0;
                            ta[y]=true;
                            nowp--;
                        }
                    }
                    if(nowp==m){
                        ta1=true;
                        break;
                    }
                }
                if(nowp==m){
                    ta1=true;
                }
            }
            // cout << nowp << " ";
        }
        cout << "Selection #" << sum << endl;
        for(int x=1;x<n;x++){
            // cout << "p" << endl;
            if(!ta[x]){
                cout << x << " ";
            }
        }
        if(!ta[n])cout << n;
        cout << endl;
        cout << endl;
    }
    return 0;
}

痾 如果不會的你看到這篇文 希望你不要直接抄 

我很抱歉直接貼出AC的程式碼 

我為我的思考不夠周全道歉:(

 

如果把這篇貼過去執行測試也是不能AC

 
ZeroJudge Forum