回溯问题统计了正方形 [英] Backtrack problem count the square

查看:77
本文介绍了回溯问题统计了正方形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过回溯算法计算坐标之间的所有正方形和矩形,我需要帮助来完成我的代码来做那个

表格会像:

如果我输入点(1,1),(1,2),(2,1),(2,2),(3,1),(3,2),(5,2),( 3,3)..

I want to count All the square and rectangle between the coordinates by the backtracking Algorithm and I need help to complete my code to Do that
The Table will be Like :
if I Enter the points (1,1),(1,2),(2,1),(2,2),(3,1),(3,2),(5,2),(3,3)..

___1 2 3 4 5 6 7  
1  * * * 0 0 0 0 
2  * * * 0 * 0 0 
3  * * * 0 0 0 0



这里应该是:正方形的数量= 2第一个是由积分形成的(1,1)&(1,2)&(2,1)&(2,2),第二个由(1,1)&(3,1)&(1,3)& ;(3,3)

和矩形= 1它是(1,1)&(3,1)&(1,2)&(3,2)



我尝试了什么:




Here supposed to be : the count of the squares=2 "the first is formed by the points (1,1)&(1,2)&(2,1)&(2,2), the second by (1,1)&(3,1)&(1,3)&(3,3) "
and Rectangle=1 "it is (1,1)&(3,1)&(1,2)&(3,2)

What I have tried:

#include <iostream>
#include <iomanip>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

const size_t size=20;

char table[size][size];

void table_clear(void){
    for(int v = 0; v<size; ++v)
        for(int h = 0; h<size; ++h)
            table[v][h]=' ';
}

void table_put(pair<int, int> p){
    int v = p.first;
    int h = p.second;
    table[v-1][h-1] = '*';//to zero origin
}

void table_disp(){
    cout << "***";
    for(int i=0; i<size;++i){
        cout << setw(3) << i + 1;
    }
    cout << "\n" << endl;
    for(int i=0;i<size;++i,cout<<endl){
        cout << setw(3) << left << i + 1;
        for(int j=0;j<size;++j){
            cout << setw(3) << right << table[i][j];
        }
        cout<<endl;
    }
}

int main(){
    vector<pair<int,int> > v;
    pair<int, int> end(99,99);
    pair<int, int> XY;

    cout << "Enter each cell in first colony use row space column Enter format, 3 4, for example.\n";
    cout << "Enter 99 99 to end entries." << endl;

while(1){
        int x,y;
        cin >> y;
        cin >> x;
        XY = make_pair(x,y);
        if(XY == end)
            break;
        v.push_back(XY);
    }
    cout<<"\n\n";

    table_clear();
    for(vector<pair<int,int> >::const_iterator iter = v.begin();iter != v.end(); ++iter ) {
        table_put(*iter);
    }
    table_disp();
}





[更新]

它计算为方形或矩形如果点内的四个角度输入= *和!= 0。无论在正方形或矩形内部包含0的事实

喜欢:



[Update]
It is calculated to be a square or a rectangle in the case if the four angles within the Points, which entered=* and !=0."Regardless of the fact that inside the square or rectangle containing 0"
Like:

__1 2 3 4 5 
1 * 0 * 0 * 
2 0 0 * 0 * 
3 * 0 * * 0



这里是square = 1(1,1)&(3,1)&(1,3)&(3,3)和Rectangle = 2 the first(3,1) )&(3,2)&(5,1)&(5,2)the second(1,1)&(3,1)&(1,3)&(3,3) 2)从第一个最近点到(1,1)到回溯方法中表的结尾的计数。


Here is squares=1 (1,1)&(3,1)&(1,3)&(3,3) and Rectangle =2 the first (3,1)&(3,2)&(5,1)&(5,2) the second (1,1)&(3,1)&(1,3)&(3,3) 2) the count beginning from the first nearest point to (1,1) to the End of the Table in Backtracking Method.

推荐答案

该程序应该做什么?

有什么问题?



[更新]

What is supposed to do the program ?
What is the problem ?

[Update]
引用:

我需要帮助来完成代码,使用回溯算法计算所有矩形和正方形的决定因素输入点数*

I need Help to complete the code with Backtracking Algorithm to Count All the rectangles and squares which Determinants between the Entered points " * "

请记住,我们不知道程序应该做什么。

提供更多详细信息并显示示例。

使用改善问题更新你的问题。



[更新]

在你的例如,我只看到2个方格,首先是(1,1)&(1,2)&(1,3)&(2,1)&(2,2)&(2,3) &(3,1)&(3,2)&(3,3)和second(2,5)。

你需要告诉我们找到矩形的规则和广场。



[更新]

上次更新后,

Remember that we don't know what the program is supposed to do.
Give more details and show example.
Use Improve question to update your question.

[Update]
In your example, I see only 2 squares, first is (1,1)&(1,2)&(1,3)&(2,1)&(2,2)&(2,3)&(3,1)&(3,2)&(3,3) and second is (2,5).
You need to tell us the rules for finding the rectangles and squares.

[Update]
After your last update,

引用:

从第一个最近点到(1,1)开始到回溯方法中表的结尾的计数。

the count beginning from the first nearest point to (1,1) to the End of the Table in Backtracking Method.

据我了解的问题,有不需要回溯方法,该方法不适合该问题。解决问题的方法是嵌套循环。

As I understand the question, there is no need of backtracking method, the method don't fit the problem. The method to solve the problem is nested loops.

// square size is (v1, h1) to (v2, h2)
for(int v1 = 0; v1<size; ++v1) { // Upper
    for(int h1 = 0; h1<size; ++h1) { // Left
        if (table[v1][h1]== "*") {// Check if possible
            // set lower
                // set right
                    // check if other points
                        // filled conditions
                        // print solution
        }
    }
}



因为它闻起来像HomeWork,我让你完成代码。

作为程序员,你的工作是创建算法来解决特定问题和你不能依赖别人为你永远做到这一点,所以有一段时间你将不得不学习如何做。越快越好。

创建算法基本上是找到数学并进行必要的调整以适应您的实际问题。



[更新]

您的评论无法阅读。请用计算代码更新您的问题并解释实际问题。

使用改进问题更新您的问题。





向downvoters:评论不起作用。发表的评论只是消失了。


Since it smell like HomeWork, I let you complete the code.
As programmer, your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.
Creating an algorithm is basically finding the maths and make necessary adaptation to fit your actual problem.

[Update]
Your comment was not readable. Please update your question with counting code and explain actual problem.
Use Improve question to update your question.


To downvoters: Comments don't work. posted comments just vanish.


这篇关于回溯问题统计了正方形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆