int main() { while(scanf("%d",&n),n) { for(int i=0;i<n;i++) scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].z); double a=0,b; while(1) { b=prim(a); if(fabs(b-a)<eps) break; a=b; } printf("%.3f\n",a); } }
int main(int argc, char **argv) { int i; while(scanf("%d", &num) != EOF) { min = 0; memset(adj, 0, sizeof(adj)); memset(in, 0, sizeof(in)); for(i=0; i<num; i++) key[i] = INF; for(i=0; i<num*num; i++) scanf("%d", &adj[i/num][i%num]); prim(); printf("%d\n", min); } }
//------------------------------------------------------------------------ void draw_nodes_draft() { pixfmt pixf(rbuf_window()); base_renderer rb(pixf); primitives_renderer prim(rb); int i; for(i = 0; i < m_graph.get_num_nodes(); i++) { graph::node n = m_graph.get_node(i, width(), height()); prim.fill_color(m_gradient_colors[147]); prim.line_color(m_gradient_colors[255]); prim.outlined_ellipse(int(n.x), int(n.y), 10, 10); prim.fill_color(m_gradient_colors[50]); prim.solid_ellipse(int(n.x), int(n.y), 4, 4); } }
int main(){ int i,j,c; scanf("%d",&c); while(c--){ scanf("%d",&n); max=0; for(i=0;i<n;++i) visit[i]=0; for(i=0;i<n;++i) for(j=0;j<n;++j) scanf("%d",&w[i][j]); prim(); printf("%d\n%",max); } return 0; }
void speedtest(short test) { unsigned BACKGROUND; if(test == 0) BACKGROUND=0xB00000; if(test == 1) BACKGROUND=0xFFFFFF; short start = 240; short cpuspeed = start; unsigned char cad[256]; FILE *speed; do { speed = fopen("/mnt/sd/speed.txt", "w"); ClearScreen(BACKGROUND); if(test == 0) v_putcad(1,1,0x00ff00,BACKGROUND,"Prim-Speedtest"); if(test == 1) v_putcad(1,1,0x006600,BACKGROUND,"Ant-Speedtest"); v_putcad(1,6,0xffffff,BACKGROUND,"Testing Speed"); if(cpuspeed > start) { sprintf(cad,"%uMhz checked",cpuspeed-5); v_putcad(1,9,0xffffff,BACKGROUND,cad); } gp2x_video_flip(); ClearScreen(BACKGROUND); if(test == 0) v_putcad(1,1,0x00ff00,BACKGROUND,"Prim-Speedtest"); if(test == 1) v_putcad(1,1,0x006600,BACKGROUND,"Ant-Speedtest"); v_putcad(1,6,0xffffff,BACKGROUND,"Testing Speed"); if(cpuspeed > start) { sprintf(cad,"%uMhz checked",cpuspeed-5); if(test == 0) v_putcad(1,9,0xffffff,BACKGROUND,cad); if(test == 1) v_putcad(1,9,0x000000,BACKGROUND,cad); } gp2x_video_flip(); fprintf (speed,"set CPU-Frequency = %uMHz\r\n",cpuspeed); set_FCLK(cpuspeed); if(test == 0) prim(); if(test == 1) ant(); fprintf(speed,"%uMhz checked\n\n", cpuspeed); cpuspeed = cpuspeed + 5; fclose(speed); execl("sync",NULL); } while(1); }
int main() { int cas,g; int i,f; scanf("%d",&cas); for(i=0; i<cas; i++) { scanf("%d",&n); for(f=0; f<n; f++) for(g=0; g<3; g++) scanf("%lf",&pos[f][g]); init(); prim(); printf("%.2lf\n",solve()); } return 0; }
int main() { int t; scanf("%d",&t); while(t--){ int i,j; scanf("%d",&n); for(i=0;i<n;i++) for(j=0;j<n;j++){ scanf("%d",&matrix[i][j]); if(!matrix[i][j]) matrix[i][j]=HIGH_VALUE; } printf("%d\n",prim()); } return 0; }
void primElemColInd() { int nrElem; for(int i=0; i<m; i++) { nrElem=0; for(int j=0; j<n; j++) { if(prim(a[j][i])) { nrElem++; } else { j=n; //Daca nu este prim j=n si trece la coloana urmatoare } } if(nrElem==n) { h++; ind[h]=i; } } }
FlowVRCegGeometryBuffer::prim FlowVRCegGeometryBuffer::createPrimitiveForTexture( Texture *tx ) const { FlowVRCegTexture *fvrtx = dynamic_cast<FlowVRCegTexture*>(tx); if(!fvrtx) return prim(); // should not happen ChunkRenderWriter &scene = m_parent.getChunkWriter(); prim p( m_parent.generateID(), m_parent.generateID(), m_parent.generateID() ); std::cout << "FlowVRCegGeometryBuffer::createPrimitiveForTexture() -- creating primitive [" << p.m_id << "]" << std::endl; scene.addPrimitive( p.m_id, ("menu-tx-gb["+fvrtx->getFileName()+"]") ); // no tg-group here on purpose scene.addParamID( p.m_id, ChunkPrimParam::VSHADER,"", m_parent.m_nIdVs ); scene.addParamID( p.m_id, ChunkPrimParam::PSHADER,"", m_parent.m_nIdPs ); scene.addParamID( p.m_id, ChunkPrimParam::VBUFFER_ID,"position", p.m_vbId ); scene.addParamID( p.m_id, ChunkPrimParam::VBUFFER_ID,"texcoord0",p.m_vbId ); scene.addParamID( p.m_id, ChunkPrimParam::VBUFFER_ID,"color0", p.m_vbId ); scene.addParamID( p.m_id, ChunkPrimParam::VBUFFER_NUMDATA,"texcoord0", 1 ); scene.addParamID( p.m_id, ChunkPrimParam::VBUFFER_NUMDATA,"color0", 2 ); // Add a shader parameter scene.addParamEnum(p.m_id, ChunkPrimParam::PARAMVSHADER, "ModelViewProj", ChunkPrimParam::ModelViewProjection); scene.addParamID(p.m_id, ChunkPrimParam::TEXTURE, "texture", fvrtx->getCgId() ); // Link index buffer idIB to primitive id // we will get a number of triangles, and right now we do not unify them to have different texture coordinates // so pass Type::Null here to indicate that the vertices are drawn 'as-is' int indexBufferType = Type::Null; scene.addIndexBuffer(p.m_ibId, 0, indexBufferType, ChunkIndexBuffer::Triangle); scene.addParamID(p.m_id, ChunkPrimParam::IBUFFER_ID, "", p.m_ibId ); scene.addParam(p.m_id, ChunkPrimParam::PARAMOPENGL, "Blend", true ); scene.addParam(p.m_id, ChunkPrimParam::PARAMOPENGL, "DepthTest", false); scene.addParam(p.m_id, ChunkPrimParam::PARAMOPENGL, "DepthWrite", false ); // draw the primitive above all others // scene.addParam(p.m_id, ChunkPrimParam::ORDER, "", std::numeric_limits<int>::max() ); // draw last scene.addParam( p.m_id, ChunkPrimParam::TRANSFORM_OVERRIDE, "", true ); return p; }
int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif while(scanf("%d", &n) && n) { m = (n-1)*n/2; for(int i = 0; i < m; i++) { int x, y, w; scanf("%d %d %d",&x,&y,&w); g[x][y] = g[y][x] = w; } printf("%d\n",prim()); } return 0; }
int main() { FILE * f = fopen("matrix2.txt","r"); readFromAdjMatrix(f); printAdjMatrix(); bfs(0); dfs(0); dfsRecurs(0); prim(0); dijkstra(0); bellmanFord(0); kruskal(); return 0; }
int main() { int n; int i, j; double ans; while(scanf("%d", &n) != EOF){ for(i = 0; i < n; i ++) scanf("%lf%lf", &p[i].x, &p[i].y); for(i = 0; i < n; i ++) for(j = 0; j < n; j ++){ graph[i][j] = distance(p[i], p[j]); } // calculate the adjacent matrix ans = prim(n); printf("%.2lf\n", ans); } return 0; }
int main() { int a, b, cost, edgenum; while(scanf("%d", &nodenum) && nodenum) { memset(map, INF, sizeof(map)); edgenum = nodenum * (nodenum - 1) / 2; for(int i = 1; i <= edgenum; ++i) //输入边的信息 { scanf("%d%d%d", &a, &b, &cost); if(cost < map[a][b]) map[a][b] = map[b][a] = cost; } prim(); printf("%d\n", sum); //最小生成树权值之和 } return 0; }
int main(int argc, char* argv[]){ int i = 0, k = 1; if(argv[1] == NULL) {printf("Argumente invalide\n"); return -1; } if(argv[1][0] == 48 && argv[1][1] != '\0') k = 0; if(argv[2] != NULL) {printf("Argumente invalide\n"); return -1; } while(argv[1][i] != '\0'){ if(argv[1][i] > 57 || argv[1][i] < 48) k = 0; else nr = nr * 10 + (argv[1][i] - 48); i = i + 1; } if( k == 1){ if(nr < 2) printf("Numarul nu este prim\n"); else if (prim(nr) == 1) printf("Numarul este prim\n"); else printf("Numarul nu este prim\n"); } else {printf("Data introdusa nu este un intreg\n"); return -1;} return 0; }
int main() { int i, j, ntest, npoints; double dist; scanf("%d", &ntest); while(ntest--) { scanf("%d", &npoints); for(i = 0; i < npoints; i++) scanf("%lf %lf", &pontos[i].x, &pontos[i].y); n = npoints; // calcula as distancias de todos para todos for(i = 0; i < n; i++) for(j = 0; j < n; j++) { dist = sqrt(pow(pontos[i].x - pontos[j].x, 2) + pow(pontos[i].y - pontos[j].y, 2)); //printf("%d, %d = %.2lf", i, j, dist); mat[i][j] = mat[j][i] = dist; } prim(); s = 0; for(i = 0; i < n; i++) { for(j = 0; j < n; j++) { s += aux[i][j]; //printf("%.2lf ", aux[i][j]); } //printf("\n"); } // somatório dos pesos das arestas pertencentes 'a árvore printf("%.2lf\n", s); if (ntest > 0) printf("\n"); } return 0; }
EvalRes term(const char *s, char **s1, int d) { // printf("Getting term from `%s`\n", s); EvalRes p = prim(s, s1, d); char *s2 = *s1; Token sgn = get_token(*s1, s1); if (sgn.st == InvalidToken) return everr(InvalidToken); if (sgn.t == MUL) return mul_res(p, term(*s1, s1, d)); else if (sgn.t == DIV) return div_res(p, term(*s1, s1, d)); else if (sgn.t == END || sgn.t == RP || sgn.t == MINUS || sgn.t == PLUS) { if (sgn.t == RP && d <= 0) return everr(SyntaxError); *s1 = s2; return p; } else return everr(SyntaxError); }
int main() { FILE *fp = fopen("prim.txt", "r"); int len; fscanf(fp, "%d\n", &len); int i, j; WEIGHT weight; for(i = 0; i < len; ++i) for(j = 0; j < len; ++j) fscanf(fp, "%d", &weight[i][j]); fclose(fp); prim(weight, len); return 0; }
int main() { FILE * f = fopen("matrix.txt","r"); readFromAdjMatrix(f); printAdjMatrix(); initRand(); bfs(0); dfs(0); dfsRecurs(0); prim(0); dijkstra(0); bellmanFord(0); kruskal(); vertexCover(adjMatrix); return 0; }
int main() { while(scanf("%d",&n),n) { for(int i=1;i<=n;++i) { v[i].input(); } preCreateGraph(); double expect = 100.0, real = 0.0; while(dblcmp(real - expect)) { expect = real; createGraph(expect); real = prim(); } printf("%.3lf\n", real); } return 0; }
void main() { int prev[MAX] = {0}; int dist[MAX] = {0}; Graph* pG; // 自定义"图"(输入矩阵队列) //pG = create_graph(); // 采用已有的"图" pG = create_example_graph(); //print_graph(*pG); // 打印图 //DFSTraverse(*pG); // 深度优先遍历 //BFS(*pG); // 广度优先遍历 prim(*pG, 0); // prim算法生成最小生成树 //kruskal(*pG); // kruskal算法生成最小生成树 // dijkstra算法获取"第4个顶点"到其它各个顶点的最短距离 //dijkstra(*pG, 3, prev, dist); }
int main(int argc, char const *argv[]) { int casen = 1; while (scanf("%d", &N), N) { for (int i=1; i<=N; i++) { scanf("%lf%lf", &cities[i].x, &cities[i].y); } for (int i=1; i<=N; i++) { for (int j=i+1; j<=N; j++) { map[i][j] = map[j][i] = distance(i, j); } } double ans = prim(); if (casen != 1) printf("\n"); printf("Case #%d:\n", casen++); printf("The minimal distance is: %.2lf\n", ans); } return 0; }
int main() { int i, j; while (1 == scanf("%d", &nNum)) { for (i=0; i<nNum; ++i) { for (j=0; j<nNum; ++j) { scanf("%d", &mat[i][j]); } }/* End of For */ ans = prim(); /* 利用 prim 算法构造最少生成树 */ printf("%d\n", ans); }/* End of While */ return 0; }
int main() { int i; while(EOF!=scanf("%d",&N)) { for(i=1;i<=N;i++) scanf("%d %d %d",&x[i],&y[i],&h[i]); left=0; right=30; while(fabs(left-right)>eps) { mid=(left+right)/2.0; if(prim()) left=mid; else right=mid; } printf("%.3lf\n",left); } return 0; }
void PbrtSceneImporter::_pbrtShape(PbrtImport::SubString i_name, const PbrtImport::ParamSet &i_params) { if (_VerifyWorld("Shape")==false) return; intrusive_ptr<const AreaLightSource> p_area; // Create primitive for static shape. PbrtImport::ShapeFactory shape_factory(mp_log); intrusive_ptr<const TriangleMesh> p_mesh = shape_factory.CreateShape(i_name.to_string(), m_current_transform, m_graphicsState, i_params); if (!p_mesh) return; intrusive_ptr<const Material> mtl = m_graphicsState.CreateMaterial(i_params); // Possibly create area light for shape if (m_graphicsState.areaLight != "") { PbrtImport::LightSourceFactory light_source_factory(mp_log); p_area = light_source_factory.CreateAreaLight(m_graphicsState.areaLight, m_current_transform, m_graphicsState.areaLightParams, p_mesh); } intrusive_ptr<const Texture<double>> p_bump_map; if (m_graphicsState.m_material_to_bump_map.find(mtl.get())!=m_graphicsState.m_material_to_bump_map.end()) p_bump_map = m_graphicsState.m_material_to_bump_map.find(mtl.get())->second; intrusive_ptr<const Primitive> prim( new Primitive(p_mesh, Transform(), mtl, p_area, p_bump_map) ); // Add primitive to scene or current instance if (mp_renderOptions->currentInstance) { if (p_area) PbrtImport::Utils::LogError(mp_log, "Area lights not supported with object instancing."); mp_renderOptions->currentInstance->push_back(prim); } else { mp_renderOptions->primitives.push_back(prim); if (p_area != NULL) mp_renderOptions->lights.m_area_light_sources.push_back(p_area); } }
void slove() { int i, j, k,w; // input scanf("%d %d", &n, &m); //initial for(i = 0; i <= n; i++) { for(j = 0; j <= n; j++) { arcs[i][j] = Infinite; } } for(k = 0; k < m; k++) { scanf("%d %d %d", &i, &j, &w); arcs[i][j] = arcs[j][i] = w; } // prim prim(); // output for(i = 1; i <= n; i++) if(D[i]) { printf("-1\n"); return ; } printf("%d\n",mincost); }
int main() { double x[MAXN], y[MAXN], z[MAXN]; double maxx; while(~scanf("%d", &N)&&N) { maxx = 0; for(int i=1; i <= N; i++) scanf("%lf %lf %lf", &x[i], &y[i], &z[i]); for(int i=1; i <= N; i++) for(int j=1; j <= N; j++) { d[j][i] = d[i][j] = i == j? 0: sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])); h[j][i] = h[i][j] = i == j? 0: fabs(z[i]-z[j]); maxx = max(maxx, h[i][j]); } L = N*maxx; while(prim(L),fabs(tc)>eps) L = ht/dt; printf("%.3lf\n", L); } return 0; }
/* * Take a grid graph and make it into a maze. */ void mazeify(grid_t *grid) { graph_t *subgraph; int num_additional_edges = grid->graph->num_edges / 100; int i, e; /* Construct minimum spanning tree */ prim(grid->graph); /* Select additional edges at random to create imperfect maze */ for (i = 0; i < num_additional_edges; ++i) { e = rand() % grid->graph->num_edges; grid->graph->edges[e].selected = 1; } /* Select both directions of each undirected edge */ /* (Note: Parallelization of this step requires some thought.) */ graph_select_reverse_edges(grid->graph); /* Replace the graph with the maze */ subgraph = graph_subgraph(grid->graph); graph_destroy(grid->graph); grid->graph = subgraph; }
void main() { int i, j; clrscr(); printf("\nEnter the no. of vertices :"); scanf("%d", &n); printf("\nEnter the costs of edges in matrix form :"); for (i = 0; i < n; i++) for (j = 0; j < n; j++) { scanf("%d", &cost[i][j]); } printf("\nThe matrix is : "); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { printf("%d\t", cost[i][j]); } printf("\n"); } prim(); getch(); }
int main() { int i; while(EOF!=scanf("%d",&N)) { if(N==0) break; for(i=1;i<=N;i++) scanf("%d %d %d",&x[i],&y[i],&h[i]); left=0; right=10000000; while(left+eps<=right) { mid=(left+right)/2.0; if(prim()) left=mid; else right=mid; } printf("%.3lf\n",left); } return 0; }
void CDynamicMeshOES2::Draw(int nFirstIndex, int nIndexCount) { if (!(ShaderUtil()->OnDrawMesh(this, nFirstIndex, nIndexCount))) { MarkAsDrawn(); return; } VPROF("CDynamicMeshOES2::Draw"); m_HasDrawn = true; if (!(m_IndexOverride || m_VertexOverride || ((m_TotalVertices > 0) && ((m_TotalIndices > 0) || (m_Type == MATERIAL_POINTS))) )) return; if (!SetRenderState((m_VertexOverride || HasFlexMesh()) ? 0 : m_FirstVertex)) return; int baseIndex = (!m_IndexOverride || (m_pIndexBuffer == MeshMgr()->GetDynamicIndexBuffer())) ? m_FirstIndex : 0; if (nIndexCount && (nFirstIndex != -1)) { nFirstIndex += baseIndex; } else { nFirstIndex = baseIndex; if (m_IndexOverride) nIndexCount = m_pIndexBuffer->IndexCount(); else nIndexCount = (m_Type == MATERIAL_POINTS) ? m_TotalVertices : m_TotalIndices; } Assert(nIndexCount); CPrimList prim(nFirstIndex, nIndexCount); s_nPrims = 1; s_pPrims = &prim; ShaderAPI()->DrawMesh(this); }