c++旅程--------打卡的第一天

18.11.02

       从发此贴开始,就努力记录我的c++所学,以便总结。每天都会上传一段代码,并不是为了交流,只为监督自己,提升自己。


 

大神养成记

1.每天都需上传一段代码(包括习题),无论什么情况。

2.每天都需把所学的c++和数据结构重要的内容记录下来。

3.完成上面任务85%。


  今天记载一下之前所学:

  1. 复杂度度量

           i)时间复杂度

               执行时间的这一变化趋势可表示为输入规模的一个函数,称作该算法的时间复杂度。但时间复杂度其实真正的理解为

以冒泡排序为例:n个元素组成的输入序列有n!中,但有时输入并不需要交换,而有时输入需要进行很多次的交换。因此,时间复杂度是从保守估计的角度出发,在规模为n的所有输入中选择执行时间最长者作为T(n),以T(n)度量该算法的时间复杂度。

ii)计算时间复杂度

以起泡排序为例:将处理n的序列所需时间记为T(n),需计算所执行基本操作的总次数,即确定它的上界。

           每一轮内部需要扫描和比较(n-1)对元素,最多需要交换(n-1)次,而比较和交换都属于基本操作,即2(n-1);外部需要扫描(n-1)个元素。因此执行总操作为(2(n-1))^{2},\textup{T}(n)=o(2n^{2}-4n+2)=o(n^{2})(也就是最坏的情况下)。

        iii)渐进复杂度

T(n)有一个上界和下界。

         2.空间复杂度

空间复杂度并不计入输入本身所占用的空间,而是把(转储,中转,索引,映射,缓冲)所消耗的空间全都计入。

 

 

 


之前敲的代码记录一下:

//cut graph cpp   MyCutGraphMesh.h"这个类就不放了"
#include "MyCutGraph.h"

#include  <queue>


namespace MeshLib
{
	 MyCutGraph::MyCutGraph(CMyCutGraphMesh * m_mesh)
	{
		q_mesh = m_mesh;
	 };

	
	 void MyCutGraph::spanning_tree()
	{
		for (CMyCutGraphMesh::MeshFaceIterator fiter(q_mesh); !fiter.end(); ++fiter)
		{
			CMy_CutGraph_Face * PF = *fiter; 
			PF->my_touch() = false;
		}

		CMy_CutGraph_Face * cF = q_mesh->idFace(1);  //把id为1的面置为根节点
		cF->my_touch() = true;
		std::queue<CMy_CutGraph_Face*> qw;
		qw.push(cF);

		do {
			CMy_CutGraph_Face* gh = qw.front();
			for (CMyCutGraphMesh::FaceHalfedgeIterator hfiter(gh); !hfiter.end(); ++hfiter)  //把它周围的面放进队列
			{
				CMy_CutGraph_HalfEdge * HF = *hfiter;
				CMy_CutGraph_Face * SF = (CMy_CutGraph_Face *)HF->he_sym()->face();
				CMy_CutGraph_Edge * EF = (CMy_CutGraph_Edge *)HF->edge();
				if (!SF->my_touch())
				{
					SF->my_touch() = true;
					EF->my_sharp() = true;
					qw.push(SF);
				}
				else continue;
			}
			qw.pop();     //先进先出
		} while (!qw.empty());
		int a=0;
		for (CMyCutGraphMesh::MeshFaceIterator fiter(q_mesh); !fiter.end(); ++fiter)
		{
			CMy_CutGraph_Face * PF = *fiter;
			if (PF->my_touch())
			{
				a += 1;
			}

		}
		std::cout << a;
	

	

	//prune
	
		for (CMyCutGraphMesh::MeshEdgeIterator eiter(q_mesh); !eiter.end(); ++eiter)
		{
			CMy_CutGraph_Edge * pE = *eiter;
			pE->my_sharp() = !pE->my_sharp();
		}

		for (CMyCutGraphMesh::MeshVertexIterator viter(q_mesh); !viter.end(); ++viter)
		{
			CMy_CutGraph_Vertex *pV = *viter;
			pV->dgree() = 0;
		}

		for (CMyCutGraphMesh::MeshEdgeIterator eiter(q_mesh); !eiter.end(); ++eiter)
		{
			CMy_CutGraph_Edge * pE = *eiter;

			if (pE->my_sharp())
			{
				CMy_CutGraph_Vertex *v1 = q_mesh->edgeVertex1(pE);
				CMy_CutGraph_Vertex *v2 = q_mesh->edgeVertex2(pE);
				v1->dgree() += 1;
				v2->dgree() += 1;
			}
			else continue;
		}


		int check_para = 0;
		do {

			for (CMyCutGraphMesh::MeshEdgeIterator eiter(q_mesh); !eiter.end(); ++eiter)
			{
				CMy_CutGraph_Edge * pE = *eiter;
				if (q_mesh->edgeVertex1(pE)->dgree() == 1 || q_mesh->edgeVertex2(pE)->dgree() == 1)
				{
					pE->my_sharp() = false;
					q_mesh->edgeVertex1(pE)->dgree() -= 1;
					q_mesh->edgeVertex2(pE)->dgree() -= 1;
				}
				else continue;

			}

			//检查是否修剪成功
			for (CMyCutGraphMesh::MeshVertexIterator viter(q_mesh); !viter.end(); ++viter)
			{

				CMy_CutGraph_Vertex *pV = *viter;
				if (pV->dgree() == 1)
				{
					check_para += 1;
				}
			}

		} while (check_para != 0);

	}


}
//...........................................//

//MyCutGraph.h

#ifndef _CUT_GRAPH_H
#define _CUT_GRAPH_H

#include "MyCutGraphMesh.h"

namespace MeshLib
{ 
	
    class MyCutGraph 
{
	public:
		MyCutGraph(CMyCutGraphMesh * m_mesh);
		
		
	    void spanning_tree();
		
	

		~MyCutGraph() {};

    protected:
	CMyCutGraphMesh  * q_mesh;


};

}


#endif  _CUT_GRAPH_H

//冒泡排序,虽然很简单,但我得逐渐积累
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string>
#include <iostream>


using namespace std;

#include <math.h>
#include <iostream>

using namespace std;

int main()
{
	int a[10];
	for (int i = 0; i < 10; i++)
	{	
		cin >> a[i];
	}
	int q=10;
	
	do {
		q = q - 1;
		for (int i = 0; i < q; i++)
		{
			if (a[i] > a[i + 1])
			{
				swap(a[i], a[i + 1]);
				
				
			}
			else continue;
		}
		
	} while (q>1 );
	for (int i = 0; i < 10; i++)
	{
		cout << a[i]<<endl;
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值