⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tmp.c

📁 经典cure聚类算法,实现用c++语言.大家
💻 C
字号:
#include <stdio.h>#include <stdlib.h>#define RandomInRange(u) ((int)(drand48()*((double)(u))))#define SWAP(a, b, tmp) \                        do {(tmp) = (a); (a) = (b); (b) = (tmp);} while(0)void main( int argc, char **argv) {  int i, j, k, nrecs = 0, nparts = 0;  float *coords, xmax, xmin;  int *part;  char filename[256];  FILE *fp;  if (argc != 3) {    printf("Usage: %s <cfile> <pfile> <# records> <# parts>\n", argv[0]);    exit(0);  }  /* get size of the data first */  fp = fopen(argv[2], "r");  while (fscanf(fp, "%d", &k) != EOF) {	++nrecs;	if (k > nparts)		nparts = k;  }  ++nparts;  rewind(fp);  printf("Reading the %d partition file %s...\n", nparts, argv[2]);  part = (int *)malloc(sizeof(int)*nrecs);  for (i=0; i<nrecs; i++)    fscanf(fp, "%d", part+i);  fclose(fp);  printf("Reading %d coordinates from %s...\n", nrecs, argv[1]);  coords = (float *)malloc(sizeof(float)*2*nrecs);  fp = fopen(argv[1], "r");  xmax = 0.0;  xmin = 100000;  for (i=0; i<nrecs; i++) {    fscanf(fp, "%f %f", coords+2*i, coords+2*i+1);    if (xmax < coords[2*i])      xmax = coords[2*i];    if (xmin > coords[2*i])      xmin = coords[2*i];  }  fclose(fp);  /* Write the temporary plot files */  for (k=0; k<nparts; k++) {    sprintf(filename, "c%d", k);    fp = fopen(filename, "w");    for (i=0; i<nrecs; i++) {      if (part[i] == k)         fprintf(fp, "%f %f\n", coords[2*i], coords[2*i+1]);    }    fclose(fp);  }  /* Write the driver file */  fp = fopen("driver.gp", "w");  fprintf(fp, "set xrange [%d:%d]\n", (int)(.8*xmin), (int)(1.2*xmax));  fprintf(fp, "plot ");  for (k=0; k<nparts; k++) {    fprintf(fp, "\"c%d\" ", k);    if (k+1 < nparts)      fprintf(fp, ", ");  }  fprintf(fp, "\n pause -1  \"Hit return to continue\"\n");  fclose(fp);  system("gnuplot driver.gp");}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -