• 个人简介

    https://www.arealme.com/spacebar-clicker/cn/ 啥都能算的c++超级计算器 ∽ 超级计算器啥都能算的c++超级计算器超级计算器#505

    • Waiting 评测:评测请求正在等待被评测机抓取

    • Fetched 评测:评测请求已被评测机抓取,正在准备开始评测

    • Compiling 评测:正在编译中

    • Judging 评测:编译成功,正在评测中

    • Accepted 通过:程序输出完全正确

    • Wrong Answer 不通过:程序输出与标准答案不一致(不包括行末空格以及文件末空行)

    • Time Limit Exceeded 不通过:程序运行时间超过了题目限制

    • Memory Limit Exceeded 不通过:程序运行内存空间超过了题目限制

    • Runtime Error 不通过:程序运行时错误(如数组越界、被零除、运算溢出、栈溢出、无效指针等)

    • Compile Error 不通过:编译失败

    • System Error 错误:系统错误(如果您遇到此问题,请及时在讨论区进行反馈)

    • Canceled 其他:评测被取消

    • Unknown Error 其他:未知错误

    • Ignored 其他:被忽略

      setw
      二维前缀和公式:f[i][j]=f[i][j-1]+f[i-1][j]-f[i-1][j-1]+y[i][j]
      
      f[x][y]-f[x][j-1]-f[i-1][y]+f[i-1][j-1];
      结构体:struct sck
      后面要分号。
      sort:左边包含,右边不包含。
      sort从大到小:
      

      bool cmp(int x,int y) { return x>y; } sort(a+1,a+n+1,cmp) bool cmp(sck x,sck y) { return x.name>y.name; }

      
      

      向下排序 floor() 向上排序 ceil() 四舍五入 round() 只取整数 int()

      
      
      
      
      
      
    cin>>n>>m;
    	a[1]=1;
    	a[0]=1;
    	long long k=sqrt(m);
    	for(int i=2;i<=k;i++)
    		if(a[i]==0)
    			for(int j=i*i;j<=m;j+=i)
    				a[j]=1;
    
    int sck(int x,int y)
    {
    	if(y==0)return x;
    	else return sck(y,x%y);
    }
    
    #include<bits/stdc++.h>
    using namespace std;
    long long n;
    int main()
    {
    	freopen("change.in","r",stdin);
    	freopen("change.out","w",stdout);
    	cin>>n;
    	printf("%o",n);
    }
    
    #include <iostream>
    #include <conio.h>
    #include <windows.h>
    #include <vector>
    #include <ctime>
    
    using namespace std;
    
    const int WIDTH = 30;
    const int HEIGHT = 20;
    const int INIT_LENGTH = 3;
    
    enum Direction { STOP = 0, LEFT, RIGHT, UP, DOWN };
    
    HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD CursorPosition;
    
    class Snake {
    private:
        vector<COORD> body;
        Direction dir;
        bool gameOver;
        COORD food;
        int score;
        
    public:
        Snake() : gameOver(false), score(0) {
            // 初始化蛇的位置(屏幕中央)
            COORD head = { WIDTH / 2, HEIGHT / 2 };
            body.push_back(head);
            
            // 创建初始蛇身
            for (int i = 1; i < INIT_LENGTH; i++) {
                COORD segment = { static_cast<SHORT>(head.X - i), head.Y };
                body.push_back(segment);
            }
            
            dir = STOP;
            generateFood();
        }
    
        void generateFood() {
            // 随机生成食物位置
            food.X = rand() % (WIDTH - 2) + 1;
            food.Y = rand() % (HEIGHT - 2) + 1;
            
            // 确保食物不在蛇身上
            for (auto segment : body) {
                if (food.X == segment.X && food.Y == segment.Y) {
                    generateFood();
                    break;
                }
            }
        }
    
        void draw() {
            system("cls"); // 清屏
            
            // 绘制上边界
            for (int i = 0; i < WIDTH; i++)
                cout << "#";
            cout << endl;
    
            // 绘制游戏区域
            for (int y = 1; y < HEIGHT - 1; y++) {
                for (int x = 0; x < WIDTH; x++) {
                    if (x == 0 || x == WIDTH - 1) {
                        cout << "#"; // 左右边界
                    }
                    else {
                        bool drawn = false;
                        
                        // 绘制蛇头
                        if (x == body[0].X && y == body[0].Y) {
                            cout << "O";
                            drawn = true;
                        }
                        // 绘制蛇身
                        else {
                            for (int i = 1; i < body.size(); i++) {
                                if (x == body[i].X && y == body[i].Y) {
                                    cout << "o";
                                    drawn = true;
                                    break;
                                }
                            }
                        }
                        
                        // 绘制食物
                        if (!drawn && x == food.X && y == food.Y) {
                            cout << "F";
                            drawn = true;
                        }
                        
                        // 绘制空白
                        if (!drawn) cout << " ";
                    }
                }
                cout << endl;
            }
    
            // 绘制下边界
            for (int i = 0; i < WIDTH; i++)
                cout << "#";
            cout << endl;
    
            // 显示分数
            cout << "Score: " << score << endl;
        }
    
        void input() {
            if (_kbhit()) {
                switch (_getch()) {
                    case 'a': if (dir != RIGHT) dir = LEFT; break;
                    case 'd': if (dir != LEFT) dir = RIGHT; break;
                    case 'w': if (dir != DOWN) dir = UP; break;
                    case 's': if (dir != UP) dir = DOWN; break;
                    case 'x': gameOver = true; break;
                }
            }
        }
    
        void logic() {
            // 移动蛇身(从尾部开始更新位置)
            for (int i = body.size() - 1; i > 0; i--) {
                body[i] = body[i - 1];
            }
            
            // 根据方向移动蛇头
            switch (dir) {
                case LEFT:  body[0].X--; break;
                case RIGHT: body[0].X++; break;
                case UP:    body[0].Y--; break;
                case DOWN: body[0].Y++; break;
            }
            
            // 检查是否吃到食物
            if (body[0].X == food.X && body[0].Y == food.Y) {
                // 增加蛇身长度
                COORD newSegment = body.back();
                body.push_back(newSegment);
                
                // 生成新食物
                generateFood();
                
                // 增加分数
                score += 10;
            }
            
            // 检查碰撞边界
            if (body[0].X <= 0 || body[0].X >= WIDTH - 1 || 
                body[0].Y <= 0 || body[0].Y >= HEIGHT - 1) {
                gameOver = true;
            }
            
            // 检查碰撞自身
            for (int i = 1; i < body.size(); i++) {
                if (body[0].X == body[i].X && body[0].Y == body[i].Y) {
                    gameOver = true;
                    break;
                }
            }
        }
    
        bool isGameOver() const {
            return gameOver;
        }
    };
    
    int main() {
        srand(static_cast<unsigned>(time(0)));
        Snake game;
        
        while (!game.isGameOver()) {
            game.draw();
            game.input();
            game.logic();
            Sleep(100); // 控制游戏速度
        }
        
        cout << "\nGame Over! Final Score: " << game.isGameOver() << endl;
        system("pause");
        return 0;
    }
    
  • 通过的题目

  • 最近活动

    This person is lazy and didn't join any contests or homework.
  • 最近编写的题解

    This person is lazy and didn't write any solutions.

题目标签

聪明人游戏
1