Ejemplo n.º 1
0
static void pprint(FILE *log,char *s)
{
  char   CHAR='#';
  int slen;

  slen=strlen(s);
  fprintf(log,"\t<======  "); 
  npr(log,slen,CHAR); 
  fprintf(log,"  ==>\n");
  fprintf(log,"\t<====  %s  ====>\n",s); 
  fprintf(log,"\t<==  "); 
  npr(log,slen,CHAR); 
  fprintf(log,"  ======>\n\n");
}
int main(){
  int a,b,c,d,output_ncr,output_npr;
  scanf("%d %d %d %d",&a,&b,&c,&d);
  output_ncr=ncr(a,b);
  output_npr=npr(c,d);
  printf("%d",(output_ncr-output_npr));
   return 0;
}
Ejemplo n.º 3
0
void search()
{
    int open = 0, closed = -1, i, j;
    for (i = 0; i < 8; i++)
	data[0].ms[i] = i + 1;
    data[0].pre = -1; data[0].f = 0;
    if (npr(data[0].ms) == goal)
    {
	fprintf(fout, "0\n\n");
	return;
    }
    i = checkused(data[0], closed, 'a');
    while (closed < open)
    {
	struct DATA tmp = data[++closed];
	tmp.pre = closed; tmp.f = data[closed].f + 1;
	for (i = 0; i < 4; i++)
	    swap(&tmp.ms[i], &tmp.ms[7 - i]);
	j = checkused(tmp, closed, 'A');
	if (j == 2) return;
	if (j)
	{
	    tmp.abc = 'A';
	    data[++open] = tmp;
	}

	tmp = data[closed];
	tmp.pre = closed; tmp.f = data[closed].f + 1;
	for (i = 0; i < 3; i++)
	{
	    swap(&tmp.ms[i], &tmp.ms[3]);
	    swap(&tmp.ms[7 - i], &tmp.ms[4]);
	}
	j = checkused(tmp, closed, 'B');
	if (j == 2) return;
	if (j)
	{
	    tmp.abc = 'B';
    	    data[++open] = tmp;
	}

    	tmp = data[closed];
	tmp.pre = closed; tmp.f = data[closed].f + 1;
	swap(&tmp.ms[1], &tmp.ms[2]);
	swap(&tmp.ms[1], &tmp.ms[5]);
	swap(&tmp.ms[1], &tmp.ms[6]);
	j = checkused(tmp, closed, 'C');
	if (j == 2) return;
	if (j)
	{
	    tmp.abc = 'C';
	    data[++open] = tmp;
	}
    }
}
Ejemplo n.º 4
0
void prepare()
{
    int i;
    for (i = 0; i < 8; i++)
	fscanf(fin, "%d", &tms[i]);
    multi[0] = 1;
    for (i = 1; i < 10; i++)
	multi[i] = multi[i - 1] * i;
    goal = npr(tms);
    printf("%d\n", goal);
}
Ejemplo n.º 5
0
static void pprint(FILE *log, const char *s, t_mdebin *md)
{
    char CHAR = '#';
    int  slen;
    char buf1[22], buf2[22];

    slen = strlen(s);
    fprintf(log, "\t<======  ");
    npr(log, slen, CHAR);
    fprintf(log, "  ==>\n");
    fprintf(log, "\t<====  %s  ====>\n", s);
    fprintf(log, "\t<==  ");
    npr(log, slen, CHAR);
    fprintf(log, "  ======>\n\n");

    fprintf(log, "\tStatistics over %s steps using %s frames\n",
            gmx_step_str(md->ebin->nsteps_sim, buf1),
            gmx_step_str(md->ebin->nsum_sim, buf2));
    fprintf(log, "\n");
}
Ejemplo n.º 6
0
int main()
{
    unsigned int n, r;
    
    printf("Enter n and r (space separated): ");
    scanf("%d %d", &n, &r);
    
    printf("nPr for n = %d and r = %d is %d", n, r, npr(n, r));
    
    getch();
    return 0;
}
Ejemplo n.º 7
0
int checkused(struct DATA p, int q, char c)
{
    int pp = npr(p.ms);
    if (pp == goal)
    {
	fprintf(fout, "%d\n", p.f);
	int i = write(q);
	if (i > 0 && i % 60 == 0) fprintf(fout, "\n");
	fprintf(fout, "%c\n", c);
	return 2;
    }
    if (used[pp]) return 0;
    else 
    {
	used[pp] = 1;
	return 1;
    }
}