Esempio n. 1
0
inline void D(int x)
{
    splay(root,x);
    Par(Lch(x))=Par(Rch(x))=0;
    root=Tjoin(Lch(x),Rch(x));
    Tupdate(root);
}
Esempio n. 2
0
int main()
{
    scanf("%d",&N);
    for (int i=1;i<=N;++i)
    {
        scanf("%d",&Val(i));
        Sum(i)=Ms(i)=Lms(i)=Rms(i)=Val(i);
        Par(i)=i-1,Rch(i-1)=i,Size(i)=N-i+1;
        splay(root,i);
    }
    splay(root,1),Par(N+1)=1,Lch(1)=N+1,Size(N+1)=1,splay(root,N+1);
    splay(root,N),Par(N+2)=N,Rch(N)=N+2,Size(N+2)=1,splay(root,N+2);
    tot=N+2;
    for (scanf("%d",&Que);Que--;)
    {
        scanf("%s%d",cmd,&x);
        if (cmd[0]=='D')    D(Findkth(root,x+1));
        else
        {
            scanf("%d",&y);
            if (cmd[0]=='Q')    Q(Findkth(root,x),Findkth(root,y+2));
            else
            if (cmd[0]=='I')    I(Findkth(root,x+1),y);
            else    R(Findkth(root,x+1),y);
        }
    }
	print_r(root); printf("\n");
	print_l(root); printf("\n");
    return 0;
}
Esempio n. 3
0
inline void Q(int x,int y)
{
    splay(root,y);
    Par(Lch(y))=0;
    splay(Lch(y),x);
    Par(x)=y;
    printf("%d\n",Ms(Rch(x)));
}
Esempio n. 4
0
global func RandomString()
{
 var amount;
 for(var cnt=0;Par(cnt);cnt++)
 amount++;
 
 return(Par(Random(amount)));
}
Esempio n. 5
0
inline void zag(int x)
{
    int y=Par(x),z=Par(y);
    Rch(y)=Lch(x),Par(Rch(y))=Lch(x)=y;
    if (Lch(z)==y)    Lch(z)=x;
    else    Rch(z)=x;
    Par(x)=z,Par(y)=x;
    Tupdate(y);
}
// Logs an error message
global func ErrorLog(string msg) {
  var out = Format(msg,Par(1),Par(2),Par(3),Par(4),Par(5),Par(6),Par(7),Par(8),Par(9));
  var out = Format("ERROR: %s",out);
  Log(out);
  if(this)
    Log(" in: %s @(%d,%d)",GetName(),GetX(),GetY());
}
Esempio n. 7
0
void DrawWindowContent() {
  int w = nWWidth;
  int h = nWHeight;

  WSetColor(DARKGRAY);
  WFillRectangle(0, 0, w, h);
  WSetColor(BLACK);
  // axis
  WDrawLine(0, h / 2, w, h / 2);
  WDrawLine(w / 2, 0, w / 2, h);
  // arrows
  WDrawLine(w / 2, 0, w / 2 - 5, 5);
  WDrawLine(w / 2, 0, w / 2 + 5, 5);

  WDrawLine(w, h / 2, w - 5, h / 2 - 5);
  WDrawLine(w, h / 2, w - 5, h / 2 + 5);
  WSetColor(RED);
  WDrawString("Q=quit, F1..F4 -- change scale, F5/F6 -- change node count", 10,
              20);

  double diff = 0;
  for (int i = 1; i <= N - 1; i++) {

    int k = i;
    if (i == 1)
      k = 2;
    if (i == N - 1)
      k = N - 2; // edge conditions

    int ss = int((X(i) - a) / (b - a) * w);
    int se = int((X(i + 1) - a) / (b - a) * w);

    for (int j = ss; j <= se; j++) {
      double t1 = (double(j) / double(w)) * (b - a) + a;
      double t2 = (double(j + 1) / double(w)) * (b - a) + a;
      WSetColor(GREEN);

      WDrawLine(MX(t1), MY(Par(k, t1)), MX(t2), MY(Par(k, t2)));
      WSetColor(BLUE);
      WDrawLine(MX(t1), MY(f(t1)), MX(t2), MY(f(t2)));
      if (diff < fabs(f(t1) - Par(k, t1)))
        diff = fabs(f(t1) - Par(k, t1));
    }
  }
  WSetColor(RED);
  for (int i = 1; i <= N; i++)
    WDrawLine(MX(X(i)), h / 2 - 3, MX(X(i)), h / 2 + 3);

  char str[256];
  WSetColor(RED);
  sprintf(str, "Difference: %1.20lf", diff);
  WDrawString(str, 10, 40);
}
Esempio n. 8
0
// Debug log for AI purposes.
global func AI_Log(string log_message)
{
	if (!AI_Logging)
		return;
	log_message = Format(log_message,Par(1),Par(2),Par(3),Par(4),Par(5),Par(6),Par(7),Par(8),Par(9));
		Log(Format("[AI]%s: %s", this->GetName(), log_message));
	return;
}
Esempio n. 9
0
File: Par.cpp Progetto: jdh8/dds
int main()
{
  ddTableResults DDtable;
  parResults pres;

  int res;
  char line[80];
  bool match;

#if defined(__linux) || defined(__APPLE__)
  SetMaxThreads(0);
#endif

  for (int handno = 0; handno < 3; handno++)
  {
    SetTable(&DDtable, handno);

    res = Par(&DDtable, &pres, vul[handno]);

    if (res != RETURN_NO_FAULT)
    {
      ErrorMessage(res, line);
      printf("DDS error: %s\n", line);
    }

    match = ComparePar(&pres, handno);

    printf("Par, hand %d: %s\n\n",
           handno + 1, (match ? "OK" : "ERROR"));

    PrintTable(&DDtable);

    PrintPar(&pres);
  }
}
Esempio n. 10
0
bool loop_par(
  int * vul_list,
  ddTableResults * table_list,
  parResults * par_list,
  int number)
{
  /* This is so fast that there is no batch or multi-threaded
     version. We run it many times just to get meaningful times. */

  parResults presp;

  for (int i = 0; i < number; i++)
  {
    for (int j = 0; j < input_number; j++)
    {
      int ret;
      if ((ret = Par(&table_list[i], &presp, vul_list[i]))
          != RETURN_NO_FAULT)
      {
        printf("loop_par i %i, j %d: Return %d\n", i, j, ret);
        exit(0);
      }
    }

    if (! compare_PAR(&presp, &par_list[i]))
    {
      printf("loop_par i %d: Difference\n", i);
    }
  }

  return true;
}
Esempio n. 11
0
inline void splay(int &root,int x)
{
    for (int y,z;Par(x);)
    {
        y=Par(x),z=Par(y);
        if (!z)
            if (Lch(y)==x)    zig(x);
            else    zag(x);
        else
        if (Lch(z)==y)
            if (Lch(y)==x)    zig(y),zig(x);
            else    zag(x),zig(x);
        else
            if (Rch(y)==x)    zag(y),zag(x);
            else    zig(x),zag(x);
    }
    Tupdate(root=x);
}
Esempio n. 12
0
inline int Tjoin(int u,int v)
{
    if (!u)    return v;
    if (!v)    return u;
    int p=u;
    for (;Rch(p);p=Rch(p));
    splay(u,p);
    return Rch(p)=v,Par(v)=p,p;
}
Esempio n. 13
0
inline void I(int x,int y)
{
    splay(root,x);
    int v=Lch(x);
    for (;Rch(v);v=Rch(v));
    Rch(v)=++tot,Par(tot)=v,Size(tot)=1;
    Sum(tot)=Ms(tot)=Lms(tot)=Rms(tot)=Val(tot)=y;
    splay(root,tot);
}
Esempio n. 14
0
File: Par.cpp Progetto: bohag/dds
int STDCALL CalcPar(ddTableDeal tableDeal, int vulnerable,
                    ddTableResults * tablep, parResults * presp)
{

  int res;

  res = CalcDDtable(tableDeal, tablep);

  if (res != 1)
    return res;

  res = Par(tablep, presp, vulnerable);

  return res;
}
Esempio n. 15
0
global func ScheduleGameCall(string szFunction, int iInterval, int iRepeat) {
	szFunction = Format("GameCall(\"%s\"", szFunction);
	var par;
	for(var i = 3; par = Par(i); i++) {
		if(GetType(par) == C4V_C4Object) {
			par = Format("Object(%d)", ObjectNumber(par));
			szFunction = Format("%s, %s", szFunction, par);
			continue;
		}
		//par = CastAny(par);
		szFunction = Format("%s, %v", szFunction, par);
	}
	szFunction = Format("%s)", szFunction);
	return Schedule(szFunction, iInterval, iRepeat);
}
Esempio n. 16
0
// Eine Funktion zeitverzögert und ggf. wiederholt aufrufen
global func ScheduleCall(object pObj, string strFunction, int iInterval, int iRepeat, par0, par1, par2, par3, par4)
{
  // Default
  if(!iRepeat) iRepeat = 1;
  if(!pObj) pObj = this();
  // Effekt erzeugen
  var iEffect = AddEffect("IntScheduleCall", pObj, 1, iInterval, pObj);
  if(iEffect <= 0) return(false);
  // Variablen setzen
  EffectVar(0, pObj, iEffect) = strFunction;
  EffectVar(1, pObj, iEffect) = iRepeat;
  // EffectVar(2): Nur zur Abwärtskompatibilität reserviert
  EffectVar(2, pObj, iEffect) = pObj; 
  for(var i = 0; i < 5; i++)
    EffectVar(i + 3, pObj, iEffect) = Par(i + 4);
  return(true);
}
Esempio n. 17
0
//int MAPClc(double *Param,double *MaxStep,int Iter,
//           XAr_func HiF,GR_XAr_func GrF,double *Exper,double Misfit,double *HiPnt)
int MAPClc(double *Param,double *MaxStep,int Iter,
    XAr_func HiF,double ErrMisfit,int MinHi,
    GR_XAr_func GrF,double *Exper,double *HiPnt)
  {

   MAPVar =new MAPVarStrc; 
   MAPVar->Hi_Func=HiF;
   MAPVar->HiPntCoef=HiPnt;MAPVar->LongPar=Param;MAPVar->Iter=0;
   if (MinHi)
     {MAPVar->Gr_Func=GrF;MAPVar->ExperPoint=Exper;MAPVar->SetCorrelation=CorrelationHi;}
   else MAPVar->SetCorrelation=CorrelationMin;

   int cur=0,k;
   for (k=1;k<=Param[0];k++) 
     if (fabs(MaxStep[k])>MathZer) {cur++;MAPVar->LongNum[cur]=k;}
   VecCl Step(cur),Par(cur);
   for (k=1;k<=cur;k++) 
     {
      Step[k]=MaxStep[MAPVar->LongNum[k]];
      Par[k]=Param[MAPVar->LongNum[k]];
     }
      
   MatrCl DirMat(cur);
   double Hi;
   if ( (Iter>0) && (!MAPGetDir(Par,Step,DirMat,ErrMisfit,Hi)) ) 
     {delete MAPVar;return 0;};
   for (k=1;k<=Iter;k++) MAPIter(Par,Step,DirMat,Hi);
   
   for (k=1;k<=cur;k++) 
     {
      MaxStep[MAPVar->LongNum[k]]=Step[k];
      Param[MAPVar->LongNum[k]]=Par[k];
     }
//cout<<"\n N iter "<<MAPVar->Iter<<"\n";
   delete MAPVar;
   return 1;
  };
Esempio n. 18
0
JNIEXPORT jobjectArray JNICALL Java_com_iq007_bridge_doubledummysolver_DoubleDummySolver_00024BridgeWorker_CalcParPBN
  (JNIEnv * env, jobject obj1, jstring jDealPBNString, jint jVulnerability)
  {
        jobjectArray result;
        jclass objectClass = env->FindClass("java/lang/Object");
        result = env->NewObjectArray(4, objectClass, 0);

        int vulnerability = (int) jVulnerability;

        const char *dealPBNString = env->GetStringUTFChars(jDealPBNString, JNI_FALSE);
        ddTableDealPBN tableDealPBN;
        strlcpy(tableDealPBN.cards, dealPBNString, sizeof(tableDealPBN.cards));

        LOGI("tableDealPBN: %s", tableDealPBN.cards);

        ddTableResults  tableResults;
        parResults      tableParResults;

        InitStart(0,0);

        int returnResultCalcDDtable = CalcDDtablePBN(tableDealPBN, &tableResults);
        LOGI("CalcDDtablePBN returned: %d", returnResultCalcDDtable);

        int returnResultCalcPar = Par(&tableResults, &tableParResults, vulnerability);
        LOGI("Par returned: %d", returnResultCalcPar);

        jchar jcharBuffer1[2][16];// = new jcharArray[2][16];
        for(int i=0;i<2;i++){
            for (int j = 0; j<16; j++) {
                jcharBuffer1[i][j] = (jchar)tableParResults.parScore[i][j];
            }
        }

        jchar jcharBuffer2[2][128];// = new jcharArray[128];
        for(int i=0;i<2;i++){
            for (int j = 0; j<128; j++) {
                jcharBuffer2[i][j] = (jchar)tableParResults.parContractsString[i][j];
            }
        }

        for(int i=0;i<2;i++){
            jcharArray strainsArray1;
            strainsArray1 = env->NewCharArray(16);
            env->SetCharArrayRegion(strainsArray1, 0, 16, jcharBuffer1[i]);
            env->SetObjectArrayElement(result, i, strainsArray1);
            for (int j=0;j<16;j++){
              LOGI("Result[%d][%d]: %d", i,j, tableParResults.parScore[i]);
          }
        }
        for(int i=2;i<4;i++){
            jcharArray strainsArray2;
            strainsArray2 = env->NewCharArray(128);
            env->SetCharArrayRegion(strainsArray2, 0, 128, jcharBuffer2[i-2]);
            env->SetObjectArrayElement(result, i, strainsArray2);
            for (int j=0;j<128;j++){
              LOGI("ResultPar[%d][%d]: %d", i-2,j, tableParResults.parContractsString[i-2][j]);
          }
        }

        env->ReleaseStringUTFChars(jDealPBNString, dealPBNString);

        return result;
  }
Esempio n. 19
0
// Displays the message if the debug mode is on
// always per-object
global func DebugMessage(string msg,  name) {
  if(Debug(name))
    Message(msg,this,Par(2),Par(3),Par(4),Par(5),Par(6),Par(7),Par(8),Par(9));
}
Esempio n. 20
0
func Moewen()
{
  ObjectSetAction(CreateObject(SL9Z,Par(),LandscapeHeight()/3,-1),"Moewen");
}
Esempio n. 21
0
//Sound-Objekte platzieren
func Meeresrauschen()
{
  ObjectSetAction(CreateObject(SL9Z,Par(),LandscapeHeight()/2,-1),"Meer");
}
Esempio n. 22
0
 Par Frame::tz() const { return Par( z().copy<Tnv>() * mScale ).trs(mPos); }    ///< Null Point Pair in local z direction
Esempio n. 23
0
// Logs if debug mode is on
global func DebugLog(string msg, name) {
  if(Debug(name))
    Log(msg,Par(2),Par(3),Par(4),Par(5),Par(6),Par(7),Par(8),Par(9));
}