Cantor的数表

题目:
1/1  1/2  1/3  1/4  1/5
2/1  2/2  2/3  2/4
3/1  3/2  3/3
4/1  4/2
5/1

  样例输入:3
14
7
12345
  样例输出:2/1
4/2
1/4
99/59

代码:
1、
# include <stdio.h>

int main()
{
int n;

while(scanf("%d",&n) == 1)
{
int k = 1, s = 0;
for(;;)
{
s += k;
if(s >= n)  //所求项是第k条对角线的倒数s-n+1个元素
{
printf("%d/%d\n",k-s+n,s-n+1);
break;
}
k++;
}
}
return 0;
}

2、
# include <stdio.h>
# include <math.h>

int main()
{
int n;
while(scanf("%d",&n) == 1)
{
int k = (int)floor((sqrt(8.0*n+1)-1)/2-1e-9)+1;
int s = k*(k+1)/2;
printf("%d/%d\n",k-s+n,s-n+1);
}
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、付费专栏及课程。

余额充值