Пример #1
0
m_complex m_inv(m_complex a)
{
    m_complex r = m_conj(a);
    r.re = r.re/(m_abs(a).re*m_abs(a).re);
    r.im = r.im/(m_abs(a).re*m_abs(a).re);
    return r;
}
Пример #2
0
BoardCoord CheckerBoard::getCoordCheckerBetween(BoardCoord first, BoardCoord second)
{
    int dY = m_abs(second.y-first.y);
    int dX = m_abs(second.x-first.x);
    int sign_dX = m_sign(second.x-first.x);
    int sign_dY = m_sign(second.y-first.y);

    int x = first.x;
    int y = first.y;
    for(int i=1; i < dX; ++i)
    {
        if(isChecker(BoardCoord::convertToBoardCoord(x+i*sign_dX, y+i*sign_dY)))
            return BoardCoord::convertToBoardCoord(x+i*sign_dX, y+i*sign_dY);
    }

    return BoardCoord(-1,-1);
}
Пример #3
0
int judge(Ball b)
{
  if((m_abs(b.x) + b.r) > 1 || (m_abs(b.y) + b.r) > 1)
  {
    return false;
  }
  listNode *tmp = head;
  while(tmp)
  {
    Ball ball = tmp->ball;
    if(distance(b, ball) < b.r + ball.r )
    {
      return false;
    }
    tmp = tmp->next;
  }
  return true;
}
Пример #4
0
static SmiInteger64
getAbsMaxInteger64(SmiType *smiType)
{
     SmiType *parent;
     SmiRange *range;
     SmiInteger64 max = SMI_BASETYPE_INTEGER64_MIN;

     range = smiGetFirstRange(smiType);
     if (! range) {
	  parent = smiGetParentType(smiType);
	  return parent ? getAbsMaxInteger64(parent) : max;
     }

     for (; range; range = smiGetNextRange(range)) {
	  if (m_abs(range->maxValue.value.integer64) > max) {
	       max = m_abs(range->maxValue.value.integer64);
	  }
     }
     return max;
}
Пример #5
0
static SmiInteger64
getAbsMinInteger64(SmiType *smiType)
{
     SmiType *parent;
     SmiRange *range;
     SmiInteger64 min = SMI_BASETYPE_INTEGER64_MAX;

     range = smiGetFirstRange(smiType);
     if (! range) {
	  parent = smiGetParentType(smiType);
	  return parent ? getAbsMinInteger64(parent) : min;
     }

     for (; range; range = smiGetNextRange(range)) {
	  if (m_abs(range->minValue.value.integer64) < min) {
	       min = m_abs(range->minValue.value.integer64);
	  }
     }
     return min;
}
Пример #6
0
 int solve(int a[][500],int n)
 {
 int i,j,cur,steps,next;
 for(i=0;i<n;++i)
 for(j=0;j<n;++j)
 {
 row[a[i][j]]=0;
 row[a[i][j]]=i;
 column[a[i][j]]=0;
 column[a[i][j]]=j;
 }
 cur=1;next=2;
 steps=0;
 while(cur<n*n)
 {
 steps+=m_abs(row[cur]-row[next])+m_abs(column[cur]-column[next]);
 cur=next;
 ++next;
 }
 return steps;
 }
Пример #7
0
bool CheckerBoard::isQueenTurn(BoardCoord oldCoord, BoardCoord newCoord)
{
        int dY = m_abs(newCoord.y-oldCoord.y);
        int dX = m_abs(newCoord.x-oldCoord.x);
        int sign_dX = m_sign(newCoord.x-oldCoord.x);
        int sign_dY = m_sign(newCoord.y-oldCoord.y);

        if(dX != dY) return false;

        int x = oldCoord.x;
        int y = oldCoord.y;

        for(int i=1; i < dX; ++i)
        {
            if(isChecker(BoardCoord::convertToBoardCoord(x+i*sign_dX, y+i*sign_dY)))
            {
                std::cout<<"invalidQueenTurn"<<std::endl;
                return false;
            }
        }

        return true;
}
Пример #8
0
bool CheckerBoard::isQueenKillTurn(BoardCoord oldCoord, BoardCoord newCoord)
{
        if(isChecker(newCoord)) return false;
        if(!oldCoord.isValid()||!newCoord.isValid()) return false;

        int dY = m_abs(newCoord.y-oldCoord.y);
        int dX = m_abs(newCoord.x-oldCoord.x);
        int sign_dX = m_sign(newCoord.x-oldCoord.x);
        int sign_dY = m_sign(newCoord.y-oldCoord.y);

        if(dX != dY) return false;

        int x = oldCoord.x;
        int y = oldCoord.y;

        boost::shared_ptr<Checker> active = getChecker(oldCoord);
        boost::shared_ptr<Checker> current;

        int countEnemy = 0;
        for(int i=1; i < dX; ++i)
        {
            if(isChecker(BoardCoord::convertToBoardCoord(x+i*sign_dX, y+i*sign_dY)))
            {
                std::cout<<"isChecker"<<x+i<<";"<<y+i<<std::endl;
                current = getChecker(BoardCoord::convertToBoardCoord(x+i*sign_dX, y+i*sign_dY));
                if(current->getColor() != active->getColor())
                    countEnemy++;
                else
                    return false;
            }
        }

        if(countEnemy != 1)
            return false;

        return true;
}
Пример #9
0
Файл: fsk.c Проект: sashakh/ma
int fsk_demodulate(struct fsk_demodulator *f, int16_t * buf, unsigned count)
{
	const unsigned len = f->filter_len;
	const unsigned shift = f->shift;
	const unsigned phinc0 = f->phinc0;
	const unsigned phinc1 = f->phinc1;
	unsigned idx = f->hist_index;
#ifdef FAST_FSK
	unsigned ph0 = f->phase0;
	unsigned ph1 = f->phase1;
#endif
	int32_t x0, y0, x1, y1, diff_energy;
	unsigned bit;
	unsigned int i;

	for (i = 0; i < count; i++) {
#ifdef FAST_FSK
		int16_t sample = f->history[idx % len];
		f->x0 -= sample * m_cos(ph0 - phinc0 * len);
		f->y0 -= sample * m_sin(ph0 - phinc0 * len);
		f->x1 -= sample * m_cos(ph1 - phinc1 * len);
		f->y1 -= sample * m_sin(ph1 - phinc1 * len);
		sample = buf[i] >> shift;
		f->x0 += sample * m_cos(ph0);
		f->y0 += sample * m_sin(ph0);
		f->x1 += sample * m_cos(ph1);
		f->y1 += sample * m_sin(ph1);
		f->history[idx % len] = sample;
		idx++;
		x0 = f->x0;
		y0 = f->y0;
		x1 = f->x1;
		y1 = f->y1;
		ph0 += phinc0;
		ph1 += phinc1;
#else
		unsigned ph0, ph1;
		unsigned j;
		f->history[idx % len] = buf[i] >> shift;
		idx++;
		ph0 = ph1 = 0;
		x0 = y0 = x1 = y1 = 0;
		for (j = 0; j < len; j++) {
			unsigned n = (idx + j) % len;
			x0 += m_cos(ph0) * f->history[n];
			y0 += m_sin(ph0) * f->history[n];
			x1 += m_cos(ph1) * f->history[n];
			y1 += m_sin(ph1) * f->history[n];
			ph0 += phinc0;
			ph1 += phinc1;
		}
#endif
		x0 >>= COSTAB_SHIFT;
		y0 >>= COSTAB_SHIFT;
		x1 >>= COSTAB_SHIFT;
		y1 >>= COSTAB_SHIFT;

		diff_energy = x1 * x1 + y1 * y1 - x0 * x0 - y0 * y0;

#ifdef CHECK_SIGNAL
#define FSK_THRESHOLD 100000
		if (m_abs(diff_energy) < FSK_THRESHOLD) {
			no_signal_count++;
			/* no signal */ ;
			dbg();
		} else
			no_signal_count = 0;
#endif

		bit = (diff_energy > 0);
		f->bit_count += f->bit_rate;
		if (f->bit != bit) {
			/* 1: send bits: num = bit_count*bit_rate/SAMPLE_RATE */
			if (f->bit_count > SAMPLE_RATE / 2) {
				modem_put_bits(f->modem, f->bit, 1);
			}
			f->bit = bit;
			f->bit_count = 0;
		} else if (f->bit_count >= SAMPLE_RATE) {
			modem_put_bits(f->modem, f->bit, 1);
			f->bit_count -= SAMPLE_RATE;
		}
#define BIG_LOG 1
#ifdef BIG_LOG
		enum { id_s1 = 16, id_s2, id_s3, id_s4 };
#define LOG_VAL(s) { val = (s) ; log_data(id_##s, &(val), sizeof(val)); }
		//dbg("%u: (mark %d.%d, space %d.%d) diff_energy = %d\n",
		//              f->modem->samples_count+i,
		//              x1,y1, x0,y0, diff_energy);
		//{int16_t val;LOG_VAL(s1);LOG_VAL(s2);LOG_VAL(s3);LOG_VAL(s4);}
		log_data(LOG_FSK_DATA, &diff_energy, sizeof(diff_energy));
#endif
	}
#ifdef FAST_FSK
	f->phase0 = ph0 % COSTAB_SIZE;
	f->phase1 = ph1 % COSTAB_SIZE;
#endif
	f->hist_index = idx % len;
	return i;
}
Пример #10
0
vec abs(vec v)
{
	return vec(m_abs(v.x), m_abs(v.y), m_abs(v.z), m_abs(v.w));
}