コード例 #1
0
ファイル: main.cpp プロジェクト: RotileQ/practice
int main(void)
{
	scanf("%d",&tcase);
	int tt=1;
	while(tcase--){
	    scanf("%d",&n);
		int ca=0,cb=0;
		status=0;
		int cnt=0;
		for(int i=0;i<n;i++){
		    int u,v;
			scanf("%d%d",&u,&v);
			int ta=ca,tb=cb;
		    status=getstatus(status,1<<mat[u][v],(cnt&1)?cb:ca);
			if(ca==ta&&cb==tb)
				cnt++;
		}
		int ans;
		if(cnt&1)  ans=minsearch(status,-inf,ca,cb);  
		else
			ans=maxsearch(status,inf,ca,cb);
		printf("Game %d: %c wins.\n",tt++,ans==inf?'A':'B');
		 
	}
	return 0;
} 
コード例 #2
0
ファイル: main.cpp プロジェクト: RotileQ/practice
int maxsearch(int state,int beta,int ca,int cb)
{
	int alpha=-inf;
	if(ca>=5)  return inf;
	else if(cb>=5)  return -inf;
	if(state==STATUS)  return ca>cb?inf:-inf;

	int remain=(~state)&STATUS;
	while(remain){
		int seg=remain&(-remain);
		int ta=ca,tb=cb;
		int now=getstatus(state,seg,ta);
		int tmp;
		if(ta>ca)
			tmp=maxsearch(now,beta,ta,tb);
		else
		    tmp=minsearch(now,alpha,ta,tb);
		if(tmp>alpha)  alpha=tmp; 
		if(tmp>=beta) return alpha;
		remain-=seg;
	}
	return alpha;
}
コード例 #3
0
ファイル: pivot.c プロジェクト: RuedKamp/OMCompiler
/*
pivot performs a full pivotization of a rectangular matrix A of dimension n_cols x n_rows
rowInd and colInd are vectors of length nrwos and n_cols respectively.
They hold the old (and new) pivoting information, such that
  A_pivoted[i,j] = A[rowInd[i], colInd[j]]
*/
int pivot( double *A, modelica_integer n_rows, modelica_integer n_cols, modelica_integer *rowInd, modelica_integer *colInd )
{
  /* parameter, determines how much larger an element should be before rows and columns are interchanged */
  const double fac = 1.125; /* approved by dymola ;) */

  /* temporary variables */
  modelica_integer row;
  modelica_integer i,j;
  modelica_integer maxrow;
  modelica_integer maxcol;
  double maxabsval;
  double pivot;

  /* go over all pivot elements */
  for(row=0; row<min(n_rows,n_cols); row++)
  {
    /* get current pivot */
    pivot = fabs(get_pivot_matrix_elt(A,row,row));

    /* find the maximum element in matrix
       result is stored in maxrow, maxcol and maxabsval */
    if (maxsearch(A, row, n_rows, n_cols, rowInd, colInd, &maxrow, &maxcol, &maxabsval) != 0) return -1;


    /* compare max element and pivot (scaled by fac) */
    if (maxabsval > (fac*pivot))
    {
      /* row interchange */
      swap(rowInd[row], rowInd[maxrow]);
      /* column interchange */
      swap(colInd[row], colInd[maxcol]);
    }

    /* get pivot (without abs, may have changed because of row/column interchange */
    pivot = get_pivot_matrix_elt(A,row,row);
    /* internal error, pivot element should never be zero if maxsearch succeeded */
    assert(pivot != 0);

    /* perform one step of Gaussian Elimination */
    for(i=row+1;i<n_rows;i++)
    {
      double leader = get_pivot_matrix_elt(A,i,row);
      if (leader != 0.0)
      {
        double scale = -leader/pivot;
        /* set leader to zero */
        set_pivot_matrix_elt(A,i,row, 0.0);
        /* subtract scaled equation from pivot row from current row */
        for(j=row+1;j<n_cols;j++)
        {
          double t1 = get_pivot_matrix_elt(A,i,j);
          double t2 = get_pivot_matrix_elt(A,row,j);
          double tmp = t1 + scale*t2;
          set_pivot_matrix_elt(A,i,j, tmp);
        }
      }
    }
  }
  /* all fine */
  return 0;
}