积累Count on a Tree

Posted kkkek

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了积累Count on a Tree相关的知识,希望对你有一定的参考价值。

#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <math.h>
#include <Windows.h>
#include <stdlib.h>
#include <time.h>

int zhi = 100;

void shezhi()
{

    printf("请输入你要猜数最大是多少(默认100)
");
    scanf("%d", &zhi);
    printf("最大值修改为%d
", zhi);
}
void mune()
{
    printf("=====================================
");
    printf("=====    1.开始 2.设置 0.退出   =====
");
    printf("=====================================
");

}
void game()
{
    int num1 = 0;
    int num2 = 0;
    int i = 10;
    num1 = rand() % zhi + 1;
    while (1)
    {
        printf("请猜数字:>
");
        scanf("%d", &num2);
        if (num2 > num1)
        {
            i--;
            printf("你输入的太大了,你还有%d次机会
",i);     
        }
        else if (num2<num1)
        {
            i--;
            printf("你输入的太小了,你还有%d次机会
",i);
        }
        else
        {
            printf("恭喜你!猜对了
");
            Sleep(1000);
            system("cls");
            printf("=====================================
");
            printf("===== 恭喜你!猜对了! 答案是%d =====
",num2);
            printf("=====================================
");
            Sleep(1000);
            system("cls");
            break;
        }
        if (i == 0)
        {
            printf("游戏结束!正确答案是%d
", num1);
            Sleep(1000);
            system("cls");
            break;
        }
    }

}
int main()
{

    int input = 0;
    srand((unsigned int)time(NULL));   
    do
    {
        mune();
        printf("请选择:>");
        scanf("%d", &input);
        switch (input)
        {
        case 1:
            Sleep(500);
            system("cls");
            printf("=====================================
");
            printf("=====     游  戏    开  始      =====
");
            printf("=====================================
");
            game();
            break;
        case 0:
            Sleep(500);
            system("cls");
            printf("=====================================
");
            printf("=====     游  戏    结  束      =====
");
            printf("=====================================
");
            break;
        case 2:
            shezhi();
            break;
        default:
            printf("重新选择
");
            Sleep(500);
            system("cls");
            break;
        }
    } while (input);
    return 0;
}

以上是关于积累Count on a Tree的主要内容,如果未能解决你的问题,请参考以下文章

「SPOJ10707」Count on a tree II

P2633 Count on a tree(树上主席树)

SPOJ 10628. SPOJ COT Count on a tree

Count on a tree II

SPOJ Count on a tree

BZOJ-2588Count on a tree 主席树 + 倍增