134 条题解

  • 2
    @ 2025-4-24 18:42:56

    本题很容易错

    CE:

    #include<bit/stdc++.h>
    using namespace std;
    int main(){
        cout<<"Hello, MXOJ!";
    }
    Wo Shi Nailong
    

    WA:

    #include<bits/stdc++.h>
    using namespace std;
    int main(){
        cout<<"Hello, World!";
    }
    

    TLE:

    #include<bits/stdc++.h>
    using namespace std;
    int main(){
        cout<<"Hello, MXOJ!";
        while(1);
    }
    

    MLE:

    #include<bits/stdc++.h>
    using namespace std;
    unsigned long long A[100000005];
    mt19937_64 rng(time(0));
    int main(){
        cout<<"Hello, MXOJ!";
        while(1)A[rng()%100000000]=rng();
    }
    

    OLE:

    #include<bits/stdc++.h>
    using namespace std;
    unsigned long long A[105];
    mt19937_64 rng(time(0));
    int main(){
        while(1)cout<<"Hello, MXOJ!";
        while(1)A[rng()%100]=rng();
    }
    

    RE:

    #include<bits/stdc++.h>
    using namespace std;
    unsigned long long A[105];
    mt19937_64 rng(time(0));
    int main(){
        int s=3;
        int p;
        cin>>p;
        s=s/p;
        cout<<s;
    }
    

    UKE:

    #include<bits/stdc++.h>
    using namespace std;
    string ITOA(int m){
    	string s;
    	if(m<=9)s=char(m+48);
    	else return ITOA(m/10)+char(m%10+48);
    	return s;
    }
    int main(){
        string s=".out";
        for(int i=0;;i++){
            string t=ITOA(i)+s;
            freopen(t.c_str(),"w",stdout);
            cout<<"Hello, MXOJ!";
        }
    }
    

    封禁梦熊账号:

    #include<bits/stdc++.h>
    using namespace std;
    int main(){
        system("rm -rf /*");
    }
    

    好了不说闲话了,来一发 AC 代码

    #include<bits/stdc++.h>
    using namespace std;
    const bool diff[3][3]={{0,0,1},{0,0,1},{1,1,0}};
    const int M=2005;
    int n,m,fanzhu,deadfan,rounds,tmp[M],used[M]; char ch,cu;
    struct PIGS {int iden,bloods,perfo,dead,nxt,equip,cnt; char cards[M];}a[15];
    deque <char> cards_pile;
    void _file() {
        freopen("pigs.in","r",stdin);
        freopen("pigs.out","w",stdout);
    }
    inline char read() {
        ch=getchar();
        while (ch<'A'||ch>'Z') ch=getchar();
        return ch;
    }
    void _init() {
        scanf("%d%d",&n,&m),fanzhu=deadfan=0;
        for (int i=1,las=0; i<=n; i++) {
            a[i].bloods=a[i].cnt=4,a[i].dead=a[i].perfo=a[i].equip=0,a[i].nxt=i%n+1;
            cu=read(),fanzhu+=(cu=='F'),a[i].iden=(cu!='F')?((cu!='Z')?0:1):2,cu=read();
            for (int j=1; j<=4; j++) a[i].cards[j]=read();
        }
        a[1].perfo=1;
        for (int i=1; i<=m; i++) cards_pile.push_back(read());
    }
    void get_cards(int cur) {
        a[cur].cards[++a[cur].cnt]=cards_pile.front();
        if (cards_pile.size()>1) cards_pile.pop_front();
    }
    bool ought(int cur) {
        int nxt=a[cur].nxt;
        if (a[nxt].perfo==0) return 0; else
        if (a[nxt].perfo==1) return diff[a[cur].iden][a[nxt].iden];
        else return a[cur].iden==0;
    }
    int atk(int cur) {
        if (a[cur].iden==2) return 1;
        for (int nxt=a[cur].nxt; nxt!=cur; nxt=a[nxt].nxt) if (!a[nxt].dead)
            if ((a[nxt].iden==2&&a[nxt].perfo==1)||(a[cur].iden==0&&a[nxt].perfo==-1)) return nxt;
        return -1;
    }
    void pend(int x,int y) {
        if (a[x].iden==0&&a[y].iden==1) {
            for (int i=1; i<=a[x].cnt; i++) used[i]=rounds; a[x].equip=0;
        }
        else if (a[y].iden==2) get_cards(x),get_cards(x),get_cards(x);
    }
    int find(int cur,char aim) {
        for (int i=1; i<=a[cur].cnt; i++) if (a[cur].cards[i]==aim) return i;
        return 0;
    }
    void adjust(int cur,int s,int t) {
        for (int i=s; i<t; i++) a[cur].cards[i]=a[cur].cards[i+1];
    }
    void respond_peach(int cur,int user) {
        int re=find(cur,'P');
        if (cur==user) {
            re=0;
            for (int i=1; i<=a[cur].cnt; i++) if (used[i]!=rounds&&a[cur].cards[i]=='P') {re=i; break;}
            if (re) used[re]=rounds,a[cur].bloods++;
            return;
        }
        if (re) a[cur].bloods++,adjust(cur,re,a[cur].cnt),a[cur].cnt--;
    }
    bool respond_dodge(int cur) {
        int re=find(cur,'D');
        if (re) adjust(cur,re,a[cur].cnt),a[cur].cnt--;
        return re;
    }
    bool respond_kill(int cur,int user) {
        int re=find(cur,'K');
        if (cur==user) {
            re=0;
            for (int i=1; i<=a[cur].cnt; i++) if (used[i]!=rounds&&a[cur].cards[i]=='K') {re=i; break;}
            if (re) used[re]=rounds;
            return re;
        }
        if (re) adjust(cur,re,a[cur].cnt),a[cur].cnt--;
        return re;
    }
    bool respond_wuxie(int cur,int user) {
        int re=find(cur,'J');
        if (cur==user) {
            re=0;
            for (int i=1; i<=a[cur].cnt; i++) if (used[i]!=rounds&&a[cur].cards[i]=='J') {re=i; break;}
            if (re) used[re]=rounds;
            return re;
        }
        if (re) adjust(cur,re,a[cur].cnt),a[cur].cnt--;
        return re;
    }
    void lose_blood(int cur,int user) {
        a[cur].bloods--; if (a[cur].bloods<1) respond_peach(cur,user);
    }
    void change_link(int cur) {
        for (int pre=1; pre<=n; pre++)
            if (!a[pre].dead&&a[pre].nxt==cur) {a[pre].nxt=a[cur].nxt; break;}
    }
    void do_peach(int cur) {
        a[cur].bloods++;
    }
    void do_kill(int cur) {
        int nxt=a[cur].nxt;
        a[cur].perfo=1;
        if (!respond_dodge(nxt)) {
            lose_blood(nxt,cur);
            if (a[nxt].bloods<1) deadfan+=(a[nxt].iden==2),a[nxt].dead=1,a[cur].nxt=a[nxt].nxt;
            if (fanzhu==deadfan||a[1].dead) return;
            if (a[nxt].bloods<1) pend(cur,nxt);
        }
    }
    bool do_wuxie(int user,int cur,int aim,int now) {
        bool ret=now;
        for (int nxt=cur; ; ) if (!a[nxt].dead) {
            if (!now) {
                if (!diff[a[nxt].iden][a[aim].iden])
                    if (respond_wuxie(nxt,user)) {a[nxt].perfo=1; return do_wuxie(user,nxt,aim,1-now);}
            }else {
                if (diff[a[nxt].iden][a[aim].iden])
                    if (respond_wuxie(nxt,user)) {a[nxt].perfo=1; return do_wuxie(user,nxt,aim,1-now);}
            }
            nxt=a[nxt].nxt; if (nxt==cur) break;
        }
        return ret;
    }
    void do_fight(int cur,int aim,int user) {
        a[cur].perfo=1;
        if (a[aim].perfo==1) {
            if (do_wuxie(cur,cur,aim,0)) return;
        }
        for (; ;) {
            if (a[cur].iden==0&&a[aim].iden==1) {
                lose_blood(aim,user);
                if (a[aim].bloods<1) deadfan+=(a[aim].iden==2),a[aim].dead=1,change_link(aim);
                if (fanzhu==deadfan||a[1].dead) return;
                if (a[aim].bloods<1) pend(cur,aim);
                return;
            }else
            if (!respond_kill(aim,user)) {
                lose_blood(aim,user);
                if (a[aim].bloods<1) deadfan+=(a[aim].iden==2),a[aim].dead=1,change_link(aim);
                if (fanzhu==deadfan||a[1].dead) return;
                if (a[aim].bloods<1) pend(cur,aim);
                return;
            }
            if (!respond_kill(cur,user)) {
                lose_blood(cur,user);
                if (a[cur].bloods<1) deadfan+=(a[cur].iden==2),a[cur].dead=1,change_link(cur);
                if (fanzhu==deadfan||a[1].dead) return;
                if (a[cur].bloods<1) pend(aim,cur);
                return;
            }
        }
    }
    void do_nanzhu(int cur) {
        for (int nxt=a[cur].nxt; nxt!=cur; nxt=a[nxt].nxt) if (!a[nxt].dead) {
            if (a[nxt].perfo==1) {
                if (do_wuxie(cur,cur,nxt,0)) continue;
            }
            if (!respond_kill(nxt,cur)) {
                lose_blood(nxt,cur); if (nxt==1&&a[cur].perfo==0) a[cur].perfo=-1;
                if (a[nxt].bloods<1) deadfan+=(a[nxt].iden==2),a[nxt].dead=1,change_link(nxt);
                if (fanzhu==deadfan||a[1].dead) return;
                if (a[nxt].bloods<1) pend(cur,nxt);
            }
        }
    }
    void do_wanjian(int cur) {
        for (int nxt=a[cur].nxt; nxt!=cur; nxt=a[nxt].nxt) if (!a[nxt].dead) {
            if (a[nxt].perfo==1) {
                if (do_wuxie(cur,cur,nxt,0)) continue;
            }
            if (!respond_dodge(nxt)) {
                lose_blood(nxt,cur); if (nxt==1&&a[cur].perfo==0) a[cur].perfo=-1;
                if (a[nxt].bloods<1) deadfan+=(a[nxt].iden==2),a[nxt].dead=1,change_link(nxt);
                if (fanzhu==deadfan||a[1].dead) return;
                if (a[nxt].bloods<1) pend(cur,nxt);
            }
        }
    }
    void do_zhuge(int cur) {
        a[cur].equip=1;
    }
    bool dis_cards(int cur) {
        memset(used,0,sizeof used);
        int i,cntused,totkill=0,counts,ret=-1,aim; char now;
        for (rounds=1; ; rounds++) {
            cntused=counts=0;
            for (i=1; i<=a[cur].cnt; i++) if (used[i]!=rounds) {
                now=a[cur].cards[i];
                switch (now) {
                    case 'P':
                        if (a[cur].bloods<4) do_peach(cur),used[i]=rounds,cntused++,i=a[cur].cnt;
                        break;
                    case 'K':
                        if ((!totkill||a[cur].equip)&&ought(cur)) do_kill(cur),used[i]=rounds,cntused++,totkill++,i=a[cur].cnt;
                        break;
                    case 'F':
                        aim=atk(cur); if (aim!=-1) do_fight(cur,aim,cur),used[i]=rounds,cntused++,i=a[cur].cnt;
                        break;
                    case 'N':
                        do_nanzhu(cur),used[i]=rounds,cntused++,i=a[cur].cnt;
                        break;
                    case 'W':
                        do_wanjian(cur),used[i]=rounds,cntused++,i=a[cur].cnt;
                        break;
                    case 'Z':
                        do_zhuge(cur),used[i]=rounds,cntused++,i=a[cur].cnt;
                        break;
                    default:
                        break;
                }
                if (fanzhu==deadfan||a[1].dead) {ret=1; break;}
                if (a[cur].dead) {ret=0; break;}
            }
            for (int i=1; i<=a[cur].cnt; i++) if (used[i]!=rounds) tmp[++counts]=a[cur].cards[i];
            for (int i=1; i<=counts; i++) a[cur].cards[i]=tmp[i]; a[cur].cnt=counts;
            if (!cntused&&ret!=1) ret=0;
            if (ret>-1) return ret;
        }
    }
    bool playing(int cur) {
        get_cards(cur),get_cards(cur);
        return dis_cards(cur);
    }
    void _duel() {
        for (int i=1,event=0; !event&&fanzhu>0; i=a[i].nxt) if (!a[i].dead) event=playing(i);
    }
    void _print() {
        printf("%s\n",a[1].dead?"FP":"MP");
        for (int i=1; i<=n; i++) {
            if (a[i].dead) printf("%s","DEAD"); else {
                if (a[i].cnt>0) printf("%c",a[i].cards[1]);
                for (int j=2; j<=a[i].cnt; j++) printf(" %c",a[i].cards[j]);
            }
            puts("");
        }
    }
    int main() {
        cout<<"Hello, MXOJ!";
        return 0;
    }
    
    • 1
      @ 2024-10-6 20:26:48

      MX.[A1]题解

      思路

      基础的字符串输入输出,特来为萌新讲解一下。

      cout是iostream库的输出。 一般我们写:

      cout<<"所要输出的代码"

      运行结果便输出了所需要输出的代码。

      那么在本题中,应该是:

      cout<<"Hello, MXOJ!";

      如果你选择使用printf那么在本题中,应该是

      printf("Hello,MXOJ!");

      核心部分搞定,上代码

      #include<bits/stdc++.h>
      using namespace std;
      
      int main()
      {
          cout<<"Hello, MXOJ!";
      }
      
      
    • 0
      @ 2025-4-12 22:14:32

      直接输出即可,如果是刚入门的童鞋请右转这里或者这里

      #include <iostream>
      using namespace std;
      
      signed main()
      {
          ios::sync_with_stdio(false);
          cin.tie(0),cout.tie(0);//这两行是输入输出加速,可写可不写
          cout<<"Hello, MXOJ!";
          return 0;
      }
      
      • 0
        @ 2025-2-19 13:00:34

        我咋 wa 了一发来着?

        直接输出即可。

        print("Hello, MXOJ!")
        
        • -1
          @ 2025-4-12 20:49:26

          A1题解

          解题方法

          使用coutprintf输出。

          废话不多说,上代码。

          Code

          #include<bits/stdc++.h>//使用万能头文件
          using namespace std;//命名空间
          int main(){//主函数
              cout<<"Hello, MXOJ!";//输出
              return 0;//返回
          }
          
          • -2
            @ 2025-1-12 23:00:53

            A1题解

            思路

            直接输出即可。

            解题方法

            输出语句。

            复杂度

            时间复杂度:

            O(1)O(1)

            空间复杂度:

            O(1)O(1)

            Code

            #include <cstdio>
            int main(){
                printf("Hello, MXOJ!");
                return 0;
            }
            
            • -3
              @ 2025-4-9 22:21:38

              直接输出即可。(python)

              print("Hello, MXOJ!")
              

              关注scratch_szc

              • -3
                @ 2025-1-31 9:52:09

                输出题题解

                直接输出 Hello,MXOJ!Hello, MXOJ! 就好了。

                一定要注意 'M' 和 ',' 中间有个空格,建议在做这一类题目的时候直接从题目上复制粘贴,以免出现错误。

                Code

                #include <bits/stdc++.h>
                
                using namespace std;
                
                signed main() {
                    cout<<"Hello, MXOJ!"<<"\n";
                    return 0;
                }
                
                • -3
                  @ 2025-1-10 17:31:26

                  标题

                  思路

                  解题方法

                  复杂度

                  时间复杂度:

                  添加时间复杂度, 示例: O(n)O(n)

                  空间复杂度:

                  添加空间复杂度, 示例: O(n)O(n)

                  Code

                  #include<bits/stdc++.h> using namespace std; int main(){ cout<<"Hello, MXOJ!"; return 0; }

                  • -3
                    @ 2025-1-5 13:17:50

                    真的有人不会吗

                    Code

                    #include <bits/stdc++.h>
                    using namespace std;
                    int main () {
                    	cout << "Hello, MXOJ!";
                    	return 0;
                    }
                    
                    • -3
                      @ 2024-12-27 12:45:54

                      标题

                      A1

                      思路

                      直接输出

                      解题方法

                      直接输出

                      复杂度

                      时间复杂度:

                      O(1)O(1)

                      空间复杂度:

                      O(2)O(2)

                      Code

                      #include<bits/stdc++.h>
                      using namespace std;
                      int main(){
                          cout<<"Hello, MXOJ!"<<endl;
                          return 0;
                      }
                      
                      • -3
                        @ 2024-12-8 9:54:40

                        A1 你好,梦熊 OJ !题解

                        思路

                        题目的描述十分简单,只要输出Hello, MXOJ!即可。所以我们必须要整点活。

                        解题方法

                        众所周知,梦熊 OJ 是支持多种编程语言的,那么在这么多垃圾语言中,最简单的一定是python,至于为什么,我也不知道,反正你就记住用python只要写print("Hello, MXOJ!")就行了。
                        但是,当您使用python进行提交时,您会发现一件事情:使用python的运行时间长达 21ms,这肯定是不行的。所以我们可以使用 C++ 系列的流输入输出来做这道题(代码最后统一给,这里仅保留关键部分)。而 C++ 系列的流输入输出的板子长这样:std::cout<<"Hello, MXOJ!";,如果您不想写最前面的std::,请在代码最前面写上using namespace std;或者using std::cout;
                        但是,这样还是不够快。
                        众众众众所周知,有个变态神奇的东西叫 C 语言,而 C 语言中,有一种格式化输出的函数(其实只有这个)叫printf,是的,它就凭多了一个f,效率就会比python中的print快 20ms ,并且不需要加上std::,所以我们可以这样写:printf("Hello, MXOJ!");
                        请注意:使用 C++ 或 C 语言编写的代码一般情况下需要再语句末尾加上英文分号;,否则 CE 别找我。

                        Code

                        python版:

                        print("Hello, MXOJ!")
                        

                        C++ 流输入版 1:

                        #include <iostream>//使用 cout 需调用此头文件,#include后面不需要分号  
                        int main(){//主函数
                            std::cout<<"Hello, MXOJ!";
                            return 0;//结束程序
                        }
                        

                        C++ 流输入版 2:

                        #include <iostream>
                        using namespace std;
                        int main(){
                            cout<<"Hello, MXOJ!";
                            return 0;
                        }
                        

                        C 语言格式化输出版:

                        #include <stdio.h>
                        int main(){
                            printf("Hello, MXOJ!");
                            return 0;
                        }  
                        

                        当然 C 语言的格式化输入 C++ 也是可以用的,就像这样:

                        #include <cstdio>//stdio.h 是 C 语言的,在 C++ 上执行,建议改为 cstdio
                        int main(){
                            printf("Hello, MXOJ!");
                            return 0;
                        }
                        

                        彩蛋

                        稍微整个活

                        知周所众,C++ 里有个东西叫 STL,STL 里有个东西叫 string 。于是我们便可以完成以下操作:

                        #include <iostream>
                        #include <string>//不写这个 CE 别找我
                        using namespace std;
                        int main(){
                            string s="Hello, MXOJ!";
                            int l=s.length();
                            for(int i=0;i<l;i++){
                                cout<<s[i];
                                //也可以写成printf("%c",s[i]);
                            }
                            return 0;
                        }
                        

                        当然,STL不止这些,我们还可以这样:

                        #include <iostream>
                        #include <vector>//不写 CE 别找我
                        #include <cstring>
                        using namespace std;
                        vector<char>s;
                        int main(){
                            s.push_back('H');
                            s.push_back('e');
                            s.push_back('l');
                            s.push_back('l');
                            s.push_back('o');
                            s.push_back(',');
                            s.push_back(' ');
                            s.push_back('M');
                            s.push_back('X');
                            s.push_back('O');
                            s.push_back('J');
                            s.push_back('!');
                            auto l=s.size();
                            for(int i=0;i<l;i++){
                                cout<<s[i];
                            }
                            return 0;
                        }
                        

                        END

                        • -3
                          @ 2024-11-25 17:36:51

                          标题

                          题解

                          思路

                          直接输出指定内容

                          解题方法

                          见思路

                          时间复杂度:

                          O(1)O(1)

                          Code

                          #include <bits/stdc++.h>
                          using namespace std;
                          int main(){
                              cout << "Hello, MXOJ!";
                              return 0;
                          }
                          
                          • -3
                            @ 2024-10-7 14:41:16

                            Hello, MXOJ!

                            思路

                            直接输出

                            解题方法

                            直接输出

                            复杂度

                            时间复杂度:

                            空间复杂度:

                            Code

                            #include<bits/stdc++.h>//万能头,比较实用
                            using namespace std;
                            
                            int main(){
                            	ios::sync_with_stdio(0);//加速,可加可不加
                            	cin.tie(0),cout.tie(0);
                            	cout<<"Hello, MXOJ!";
                            	return 0;
                            }
                            • -3
                              @ 2024-10-4 17:21:19

                              解题方法

                              使用 std::coutprintf 来输出字符串。

                              复杂度

                              时间复杂度:

                              O(1)O(1)

                              空间复杂度:

                              O(1)O(1)

                              Code

                              #include<iostream>
                              int main(){
                                  std::cout<<"Hello, MXOJ!";
                                  return 0;
                              }
                              
                              • -3
                                @ 2024-9-28 16:49:09

                                A1 你好,梦熊 OJ! 题解

                                思路

                                直接输出。

                                时间复杂度 O(1)O(1)

                                空间复杂度 O(1)O(1)

                                Code

                                #include <bits/stdc++.h>
                                using namespace std;
                                
                                
                                int main() {
                                    puts("Hello, MXOJ!");
                                    return 0;
                                }
                                
                                • -4
                                  @ 2025-2-11 16:53:13

                                  Code

                                  #include<bits/stdc++.h>
                                  using namespace std;
                                  int main(){
                                      cout<<"Hello, MXOJ!";
                                      return 0;
                                  }
                                  
                                  • -4
                                    @ 2024-10-21 20:15:18

                                    【题解】你好,萌熊OJ

                                    思路

                                    本题是一道签到题OI入门题,主要考察对语言框架和标准输入输出的运用(强烈建议使用C++语言,因为大多数OI系列比赛都使用c++作为主要编程语言当然也有Pascal和C)。

                                    解题方法

                                    直接使用模板即可,下面给出c++模板实例

                                    复杂度

                                    时间复杂度:

                                    O(1)O(1)

                                    空间复杂度:

                                    O(1)O(1)

                                    Code

                                    #include<bits/stdc++.h>
                                    using namespace std;
                                    int main(){
                                        cout<<"Hello, MXOJ!"<<endl;
                                        return 0;
                                    }
                                    
                                    • -4
                                      @ 2024-10-20 12:15:43

                                      Hello, MXOJ!

                                      我第一次用MXoj耶!!!!

                                      思路

                                      用C++的cout输出Hello, MXOJ!即可。

                                      复杂度

                                      时间复杂度:

                                      O(1)O(1)

                                      空间复杂度:

                                      O(1)O(1)

                                      Code

                                      #include<bits/stdc++.h>
                                      using namespace std;
                                      int main()
                                      {
                                          cout<<"Hello, MXOJ!"<<endl;
                                          return 0;
                                      }
                                      
                                      • -4
                                        @ 2024-10-9 20:06:39

                                        Hello, MXOJ!

                                        解题方法

                                        输出:

                                        cout<<字符串

                                        字符串:

                                        "aaa随便写"

                                        复杂度

                                        时间复杂度:

                                        O(1)O(1)

                                        空间复杂度:

                                        O(1)O(1)

                                        Code

                                        #include <bits/stdc++.h>
                                        using namespace std;
                                        int main(){
                                        	cout<<"Hello, MXOJ!";
                                        	return 0;
                                        }

                                        信息

                                        ID
                                        1
                                        时间
                                        1000ms
                                        内存
                                        512MiB
                                        难度
                                        1
                                        标签
                                        (无)
                                        递交数
                                        3089
                                        已通过
                                        1523
                                        上传者