Cantor的数表

#include <stdio.h>
#include <stdlib.h>
#include <string.h>



int main()
{
    int n,x=1,y=1,count=1;
    scanf("%d",&n);
    for(;;)

    {

        //往左走

        if(count<n)
        {
            y++;
            count++;

        }

         //往左下方走

        while(y>1 && count<n)
        {
            x++;
            y--;
            count++;

        }

        //往下走

        if(count<n)
        {
            x++;
            count++;

        }

        //往右上方走

        while(x>1 && count<n)
        {
            x--;
            y++;
            count++;
        }
        if(count==n)
            break;
    }
    printf("%d/%d",x,y);

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我理解了你的问题。首先,对于不了解 Cantor 集的人来说,它是由 Georg Cantor 发明的一类自相似的集合。Cantor 集是一个闭集,也就是说它包含所有的极限点。在 Cantor 集中,每个点都可以被表示为三进制数,其中每个数字可以是0、1或2。那么,我们可以使用 MFC 编程在窗口中一次性绘制 n=0~5 的所有 Cantor 集。 下面是代码示例: ```c++ void CCantorView::OnDraw(CDC* pDC) { CCantorDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; int nWidth = 700; // 窗口宽度 int nHeight = 400; // 窗口高度 int nMaxIter = 5; // 最大迭代次数 int nRectWidth = nWidth / pow(3, nMaxIter); // 矩形宽度 int nRectHeight = 20; // 矩形高度 int nXPos = 0; // 矩形起始横坐标 int nYPos = 50; // 矩形起始纵坐标 // 绘制 Cantor 集 for (int i = 0; i <= nMaxIter; i++) { for (int j = 0; j < pow(3, i); j++) { if (i == 0) { // 绘制第一级矩形 pDC->Rectangle(nXPos, nYPos, nXPos + nRectWidth, nYPos + nRectHeight); nXPos += nRectWidth; } else { // 绘制更高级别的矩形 if (j % 3 != 1) { pDC->Rectangle(nXPos, nYPos, nXPos + nRectWidth, nYPos + nRectHeight); } nXPos += nRectWidth; } } nXPos = 0; nYPos += nRectHeight * 2; nRectWidth /= 3; } } ``` 这段代码会在窗口中绘制从 0 级到 5 级的所有 Cantor 集,其中每个级别的集合都在上一级别的集合上方。你可以在 `OnDraw` 函数中调用这个函数,然后在你的程序中使用该函数来绘制 Cantor 集。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值