コード例 #1
0
ファイル: hw2_segtree.c プロジェクト: goTJ/tj
int main()
{
	int tmp;
	int i, j;

	while(get_num(&tmp) == 1){
		in[num] = tmp;
		data[num].num = tmp;
		data[num].idx = num;
		num++;
	}
	while(offset < num)
		offset <<= 1;
	qsort(data, num, sizeof(Data), comp);
	for(i=0; i<num; i++){
		int max = 0;
		int first;
		int last;
		for(j=data[i].idx+offset; j!=0; j>>=1){
			if(j&1 && heap[j-1].length > max){
				max = heap[j-1].length;
				if(j >= offset){
					last = j-1-offset;
				}else{
					first = heap[j-1].first;
					last = heap[j-1].last;
				}
			}
		}
		max++;
		j = data[i].idx+offset;
		heap[j].length = max;
		heap[j].last = (max == 1) ? -1 : last;
		for(j>>=1; j!=0; j>>=1){
			if(heap[j].length >= max)
				break;
			heap[j].length = max;
			if(max <= 3)
				heap[j].first = data[i].idx;
			heap[j].last = data[i].idx;
		}
	}
	printf("max length: %d\n", heap[1].length);
	printf("first three: ");
	output3(heap[1].first, 0);
	printf("\n");
	printf("last three: ");
	output3(heap[1].last, 0);
	printf("\n");
	return 0;
}
コード例 #2
0
ファイル: hw2_segtree.c プロジェクト: goTJ/tj
void output3(int i, int n)
{
	if(i == -1 || n == 3)
		return;
	output3(heap[i+offset].last, n+1);
	printf("%d ", in[i]);
}
コード例 #3
0
ファイル: items.c プロジェクト: CHen417/medit
void drawGrid(pScene sc,pMesh mesh) {
  int k;

  /* default */
  if ( ddebug ) printf("draw grid + graduation\n");

  if ( !sc->grid ) {
    sc->grid = glGenLists(1);
    glNewList(sc->grid,GL_COMPILE);
    glBegin(GL_LINES);
    for (k=0; k<5; k++) {
      glVertex3f(k*0.25,0.,0.);  glVertex3f(k*0.25,1.,0.);
      glVertex3f(0.,k*0.25,0.);  glVertex3f(1.,k*0.25,0.);
      glVertex3f(0.,k*0.25,0.);  glVertex3f(0.,k*0.25,1.);
      glVertex3f(0.,0.,k*0.25);  glVertex3f(0.,1.,k*0.25);
      glVertex3f(k*0.25,0.,0.);  glVertex3f(k*0.25,0.,1.);
      glVertex3f(0.,0.,k*0.25);  glVertex3f(1.,0.,k*0.25);
     }
    glEnd();
    glEndList();
  }

  /* call display list */
  glPushMatrix();
  glTranslatef(-0.3*fabs(sc->dmax),0.,-4.7*sc->dmax);
  glRotatef(-60.,1.,0.,0.);
  glRotatef(-120.,0.,0.,1.);
  glScalef(2.5*sc->dmax,2.5*sc->dmax,2.5*sc->dmax);
  glDisable(GL_LIGHTING);

  glColor3f(0.4,0.4,0.4);
  glCallList(sc->grid);

  glColor3fv(sc->par.line);
  output3(0.0,0.0,0.0,"%.2f",mesh->xmin);
  output3(1.1,0.0,0.0,"%.2f",mesh->xmax);
  output3(0.0,1.01,0.0,"%.2f",mesh->ymax);
  output3(0.0,0.0,1.01,"%.2f",mesh->zmax);
  glEnable(GL_LIGHTING);
  glPopMatrix();
}
コード例 #4
0
ファイル: xor.cpp プロジェクト: Aarons100/Kryptos
int break_Rkey_Xor() {

	string inputFile;
	cout << "Enter the name of an existing text file in the current directory: ";
	cin >> inputFile;
	//open input file for reading
	ifstream input(inputFile);
	string bin_text = "";
	//this while loop converts the input to binary form
	while(input.good()) {
		char c = input.get();
		//if input is still valid
		if(input.good()) {
			bin_text += hextobin(c);
		}
	}
	input.close();

	int pos[3];
	find_shortest_distances(bin_text,pos);

	vector <string> keyOneBlocks = breakIntoBlocks(pos[0],bin_text);
	vector <string> keyTwoBlocks = breakIntoBlocks(pos[1],bin_text);
	vector <string> keyThreeBlocks = breakIntoBlocks(pos[2],bin_text);

	vector <string> keyOneTranspose = transpose(keyOneBlocks);
	vector <string> keyTwoTranspose = transpose(keyTwoBlocks);
	vector <string> keyThreeTranspose = transpose(keyThreeBlocks);

	ofstream output("keyOneoutput.txt");
	for(int i = 0; i < keyOneTranspose.size(); i++) {
		sByteXor(keyOneTranspose[i],output);
	}
	output.close();
	ofstream output2("keyTwooutput.txt");
	for(int i = 0; i < keyTwoTranspose.size(); i++) {
		sByteXor(keyTwoTranspose[i],output2);
	}	
	output2.close();
	ofstream output3("keyThreeoutput.txt");
	for(int i = 0; i < keyThreeTranspose.size(); i++) {
		sByteXor(keyThreeTranspose[i],output3);
	}	
	output3.close();

	
	return 0;
}
コード例 #5
0
static void drawPoint (pScene sc, pMesh mesh, int k) {
	pPoint pt;

	pt = &mesh->point[k];

	/*glDisable(GL_DEPTH_TEST);*/
	glDisable(GL_LIGHTING);
	glPointSize(6.0);
	glColor3f(1.0, 0., 0.);
	glBegin(GL_POINTS);
	glVertex3f(pt->c[0], pt->c[1], pt->c[2]);
	glEnd();
	output3(pt->c[0], pt->c[1], pt->c[2], "%d", refitem);
	glEnable(GL_LIGHTING);
	/*glEnable(GL_DEPTH_TEST);*/
}
コード例 #6
0
TEST(PackUnpack, Basic)
{
	nbase::PackBuffer pbuffer;
	nbase::Pack test_pack(pbuffer);

	EXPECT_EQ(0, test_pack.size());

	test_pack.push_uint8(8);
	test_pack.push_uint16(16);
	test_pack.push_uint32(32);
	test_pack.push_uint64(64);

	std::string input1 = "test input string 1";
	std::string input2 = "test input string 2";
	std::string input3 = "test input string 3";
	std::string input4 = "test input string 4";
	std::string input5 = "test input string 5";
	nbase::Varstr var_str(input1.data(), input1.size());
	test_pack.push_varstr(var_str);
	test_pack.push_varstr(input2.c_str());
	test_pack.push_varstr(input3);
	test_pack.push_varstr(input4.data(), input4.size());
	test_pack.push_varstr32(input5.data(), input5.size());

	nbase::Unpack test_unpack(pbuffer.data(), pbuffer.size());
	EXPECT_EQ(8, test_unpack.pop_uint8());
	EXPECT_EQ(16, test_unpack.pop_uint16());
	EXPECT_EQ(32, test_unpack.pop_uint32());
	EXPECT_EQ(64, test_unpack.pop_uint64());
	nbase::Varstr var_output1 = test_unpack.pop_varstr_ptr();
	std::string output1(var_output1.data(), var_output1.size()); 
	EXPECT_EQ(input1, output1);
	nbase::Varstr var_output2 = test_unpack.pop_varstr_ptr();
	std::string output2(var_output2.data(), var_output2.size()); 
	EXPECT_EQ(input2, output2);
	nbase::Varstr var_output3 = test_unpack.pop_varstr_ptr();
	std::string output3(var_output3.data(), var_output3.size()); 
	EXPECT_EQ(input3, output3);
	nbase::Varstr var_output4 = test_unpack.pop_varstr_ptr();
	std::string output4(var_output4.data(), var_output4.size()); 
	EXPECT_EQ(input4, output4);
	nbase::Varstr var_output5 = test_unpack.pop_varstr32_ptr();
	std::string output5(var_output5.data(), var_output5.size()); 
	EXPECT_EQ(input5, output5);	
}
コード例 #7
0
ファイル: CDS-lab3.cpp プロジェクト: lundibundi/KPI-CDS-labs
int main(void)
{
	setlocale(LC_CTYPE, "RUSSIAN");

	freopen("input2.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int m; // Кількість ребер
	int n; // Кількість вершин
	int v, u; // Вершини

	scanf_s("%d%d", &n, &m);
	for (int i = 1; i <= m; i++)
	{
		scanf_s("%d%d", &v, &u);

		g_s[v][u] = 1;
	}

	output1(n);
	output2(n);
	output3(n);
}
コード例 #8
0
static void drawTria (pScene sc, pMesh mesh, int k) {
	pMaterial pm;
	pTriangle pt;
	pPoint p0, p1, p2;
	double ax, ay, az, bx, by, bz, dd;
	float shrink, cx, cy, cz, n[3];

	/* default */
	if (ddebug) printf("draw triangle %d\n", k);

	if (k < 1 || k > mesh->nt) return;

	pt = &mesh->tria[k];
	if (refpick > 0) pt->ref = refpick;

	refmat = matRef(sc, pt->ref);
	p0 = &mesh->point[pt->v[0]];
	p1 = &mesh->point[pt->v[1]];
	p2 = &mesh->point[pt->v[2]];
	pm = &sc->material[refmat];
	cx = (p0->c[0] + p1->c[0] + p2->c[0]) / 3.;
	cy = (p0->c[1] + p1->c[1] + p2->c[1]) / 3.;
	cz = (p0->c[2] + p1->c[2] + p2->c[2]) / 3.;
	shrink = 0.95 * sc->shrink;

	glBegin(GL_TRIANGLES);
	glColor3f(1.0 - pm->dif[0], 1.0 - pm->dif[1], 1.0 - pm->dif[2]);

	/* compute normal */
	ax = p1->c[0] - p0->c[0];
	ay = p1->c[1] - p0->c[1];
	az = p1->c[2] - p0->c[2];
	bx = p2->c[0] - p0->c[0];
	by = p2->c[1] - p0->c[1];
	bz = p2->c[2] - p0->c[2];
	n[0] = ay * bz - az * by;
	n[1] = az * bx - ax * bz;
	n[2] = ax * by - ay * bx;
	dd = n[0] * n[0] + n[1] * n[1] + n[2] * n[2];
	if (dd > 0.0f) {
		dd = 1.0f / sqrt(dd);
		n[0] *= dd;
		n[1] *= dd;
		n[2] *= dd;
	}

	glNormal3fv(n);
	glVertex3f(shrink * (p0->c[0] - cx) + cx,
	           shrink * (p0->c[1] - cy) + cy,
	           shrink * (p0->c[2] - cz) + cz);
	glNormal3fv(n);
	glVertex3f(shrink * (p1->c[0] - cx) + cx,
	           shrink * (p1->c[1] - cy) + cy,
	           shrink * (p1->c[2] - cz) + cz);
	glNormal3fv(n);
	glVertex3f(shrink * (p2->c[0] - cx) + cx,
	           shrink * (p2->c[1] - cy) + cy,
	           shrink * (p2->c[2] - cz) + cz);
	glEnd();

	glColor3f(1.0 - sc->par.back[0], 1.0 - sc->par.back[1], 1.0 - sc->par.back[2]);
	output3(p0->c[0], p0->c[1], p0->c[2], "%d", pt->v[0]);
	output3(p1->c[0], p1->c[1], p1->c[2], "%d", pt->v[1]);
	output3(p2->c[0], p2->c[1], p2->c[2], "%d", pt->v[2]);
}
コード例 #9
0
static void drawHexa (pScene sc, pMesh mesh, int k) {
	pMaterial pm;
	pHexa ph;
	pPoint p0;
	float n[3];
	/*float shrink; */
	int l;

	/* default */
	if (ddebug) printf("draw hexa %d\n", k);

	if (k < 1 || k > mesh->nhex) return;

	ph = &mesh->hexa[k];
	if (refpick > 0) ph->ref = refpick;

	refmat = matRef(sc, ph->ref);
	pm = &sc->material[refmat];
	/*shrink = 0.95 * sc->shrink;*/

	glBegin(GL_QUADS);
	glColor3f(1.0 - pm->dif[0], 1.0 - pm->dif[1], 1.0 - pm->dif[2]);

	for (l = 0; l < 6; l++) {
		pPoint p1, p2, p3;
		float ax, ay, az, bx, by, bz, d;
		float cx, cy, cz;

		p0 = &mesh->point[ph->v[ch[l][0]]];
		p1 = &mesh->point[ph->v[ch[l][1]]];
		p2 = &mesh->point[ph->v[ch[l][2]]];
		p3 = &mesh->point[ph->v[ch[l][3]]];
		cx = (p0->c[0] + p1->c[0] + p2->c[0] + p3->c[0]) / 4.;
		cy = (p0->c[1] + p1->c[1] + p2->c[1] + p3->c[1]) / 4.;
		cz = (p0->c[2] + p1->c[2] + p2->c[2] + p3->c[2]) / 4.;

		/* compute face normal */
		ax = p1->c[0] - p0->c[0];
		ay = p1->c[1] - p0->c[1];
		az = p1->c[2] - p0->c[2];
		bx = p2->c[0] - p0->c[0];
		by = p2->c[1] - p0->c[1];
		bz = p2->c[2] - p0->c[2];
		n[0] = ay * bz - az * by;
		n[1] = az * bx - ax * bz;
		n[2] = ax * by - ay * bx;
		d = n[0] * n[0] + n[1] * n[1] + n[2] * n[2];
		if (d > 0.0f) {
			d = 1.0 / sqrt(d);
			n[0] *= d;
			n[1] *= d;
			n[2] *= d;
		}

		glNormal3fv(n);
		glVertex3f(sc->shrink * (p0->c[0] - cx) + cx,
		           sc->shrink * (p0->c[1] - cy) + cy,
		           sc->shrink * (p0->c[2] - cz) + cz);
		glNormal3fv(n);
		glVertex3f(sc->shrink * (p1->c[0] - cx) + cx,
		           sc->shrink * (p1->c[1] - cy) + cy,
		           sc->shrink * (p1->c[2] - cz) + cz);
		glNormal3fv(n);
		glVertex3f(sc->shrink * (p2->c[0] - cx) + cx,
		           sc->shrink * (p2->c[1] - cy) + cy,
		           sc->shrink * (p2->c[2] - cz) + cz);
		glNormal3fv(n);
		glVertex3f(sc->shrink * (p3->c[0] - cx) + cx,
		           sc->shrink * (p3->c[1] - cy) + cy,
		           sc->shrink * (p3->c[2] - cz) + cz);
	}

	glEnd();

	/* display vertex number */
	glColor3f(1.0 - sc->par.back[0], 1.0 - sc->par.back[1], 1.0 - sc->par.back[2]);

	for (l = 0; l < 8; l++) {
		p0 = &mesh->point[ph->v[l]];
		output3(p0->c[0], p0->c[1], p0->c[2], "%d", ph->v[l]);
	}
}
コード例 #10
0
static void drawTets (pScene sc, pMesh mesh, int k) {
	pMaterial pm;
	pTetra pt;
	pPoint p0, p1, p2, p3;
	float n[3];
	float shrink;
	int l;

	/* default */
	if (ddebug) printf("draw tetra %d\n", k);

	if (k < 1 || k > mesh->ntet) return;

	pt = &mesh->tetra[k];
	if (refpick > 0) pt->ref = refpick;

	refmat = matRef(sc, pt->ref);

	pm = &sc->material[refmat];
	shrink = 0.95 * sc->shrink;

	glBegin(GL_TRIANGLES);
	glColor3f(1.0 - pm->dif[0], 1.0 - pm->dif[1], 1.0 - pm->dif[2]);

	for (l = 0; l < 4; l++) {
		float ax, ay, az, bx, by, bz, d;
		float cx, cy, cz;

		p0 = &mesh->point[pt->v[ct[l][0]]];
		p1 = &mesh->point[pt->v[ct[l][1]]];
		p2 = &mesh->point[pt->v[ct[l][2]]];
		cx = (p0->c[0] + p1->c[0] + p2->c[0]) / 3.;
		cy = (p0->c[1] + p1->c[1] + p2->c[1]) / 3.;
		cz = (p0->c[2] + p1->c[2] + p2->c[2]) / 3.;

		/* compute face normal */
		ax = p1->c[0] - p0->c[0];
		ay = p1->c[1] - p0->c[1];
		az = p1->c[2] - p0->c[2];
		bx = p2->c[0] - p0->c[0];
		by = p2->c[1] - p0->c[1];
		bz = p2->c[2] - p0->c[2];
		n[0] = ay * bz - az * by;
		n[1] = az * bx - ax * bz;
		n[2] = ax * by - ay * bx;
		d = n[0] * n[0] + n[1] * n[1] + n[2] * n[2];
		if (d > 0.0f) {
			d = 1.0 / sqrt(d);
			n[0] *= d;
			n[1] *= d;
			n[2] *= d;
		}

		glNormal3fv(n);
		glVertex3f(shrink * (p0->c[0] - cx) + cx,
		           shrink * (p0->c[1] - cy) + cy,
		           shrink * (p0->c[2] - cz) + cz);
		glNormal3fv(n);
		glVertex3f(shrink * (p1->c[0] - cx) + cx,
		           shrink * (p1->c[1] - cy) + cy,
		           shrink * (p1->c[2] - cz) + cz);
		glNormal3fv(n);
		glVertex3f(shrink * (p2->c[0] - cx) + cx,
		           shrink * (p2->c[1] - cy) + cy,
		           shrink * (p2->c[2] - cz) + cz);
	}

	glEnd();

	/* display vertex number */
	p0 = &mesh->point[pt->v[0]];
	p1 = &mesh->point[pt->v[1]];
	p2 = &mesh->point[pt->v[2]];
	p3 = &mesh->point[pt->v[3]];

	glColor3f(1.0 - sc->par.back[0], 1.0 - sc->par.back[1], 1.0 - sc->par.back[2]);
	output3(p0->c[0], p0->c[1], p0->c[2], "%d", pt->v[0]);
	output3(p1->c[0], p1->c[1], p1->c[2], "%d", pt->v[1]);
	output3(p2->c[0], p2->c[1], p2->c[2], "%d", pt->v[2]);
	output3(p3->c[0], p3->c[1], p3->c[2], "%d", pt->v[3]);

	/*if ( mesh->nfield == 6 )  drawEllipse(sc,mesh,LTets,k);*/
	if (!mesh->nbb)
		circumSphere(sc, mesh, LTets, k);
}
コード例 #11
0
ファイル: main.c プロジェクト: sirianray/lblc
int main(int argc, char *argv[]){
	MPI_Init(&argc, &argv);
        MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, 0, MPI_INFO_NULL, &shmcomm);
        MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
        MPI_Comm_rank(MPI_COMM_WORLD, &myid);

	double t_begin;
	int i, j, k, ii, id, id1;

	t_begin = MPI_Wtime();		// record the begining CPU time
	
	read_param();
	lattice_vec();
	allocate();
	p_allocate();

	if (flow_on!=0) {
		build_stream();
	}

	if (Q_on!=0) {
		build_neighbor();		
	}

	init_surf();
	add_patch();
	p_init();
	p_iden();
	init();

	if (flow_on!=0) cal_fequ(f);	
	if (Q_on!=0) cal_dQ();

	if (Q_on!=0 && flow_on!=0 && newrun_on!=0) {
		while(qconverge==0) {
			t_current++;
			for (ii=0; ii<n_evol_Q; ii++) {
                                cal_dQ();
                                evol_Q();
                        }
			if (t_current%t_print==0) monitor();
		}
		e_tot     =-1;
		k_eng     =-1;
		qconverge = 0;	
		uconverge = 0;
		t_current =-1;
	}

	if (Q_on!=0 && flow_on!=0) {
		cal_W();
		cal_stress();
		cal_sigma_p();
	}
        MPI_Barrier(MPI_COMM_WORLD);

	output1(1,'z',Nx/2,Ny/2);
	output3(1);
	if(myid==0) printf("Q initialized\n");
	MPI_Barrier(MPI_COMM_WORLD);

	while (t_current<t_max && uconverge*qconverge==0) {
		e_toto=e_tot;
		if (Q_on!=0 && qconverge==0) {
			if (flow_on!=0 && uconverge==0) cal_W();
			for (ii=0; ii<n_evol_Q; ii++) {
				cal_dQ();
				evol_Q();
			}			
		}

		if (flow_on!=0 && uconverge==0) {
			if (Q_on!=0 && qconverge==0) {
				cal_stress();
				cal_sigma_p();
			}
			evol_f(f,f2);
		}

		if (Q_on!=0 && qconverge==0) {
			if (flow_on!=0 && uconverge==0) cal_W();
			for (ii=0; ii<n_evol_Q; ii++) {
				cal_dQ();
				evol_Q();
			}			
		}

		if (flow_on!=0 && uconverge==0) {
			if (Q_on!=0 && qconverge==0) {
				cal_stress();
				cal_sigma_p();
			}
			evol_f(f2,f);
		}
		
		if (t_current%t_print==0) monitor();
		if (t_current%t_write==0) {
			output1(0,'z',Nx/2,Ny/2);
			output3(0);
			fflush(stdout);
		}
		t_current++;
	}
	
	
	output_time(t_begin);
	output1(0,'z',Nx/2,Ny/2);
	output3(0);
	
	write_restart();

	p_deallocate();
	deallocate();

	return 0;
}