Пример #1
0
DWORD WINAPI philosopherET(LPVOID number)
{
	int *i = (int *)number;
	while(true)
	{
		if(!mutexP())
			continue;
		printf("哲学家%d,思考中...\n",*i);
		//尝试拿走右手边筷子
		if(!Try(*i))
			continue;
		if(!Try((*i+1)%5))
			continue;
		//拿走筷子
		Take(*i);
		Take((*i+1)%5);
		printf("哲学家%d,吃饭中\n",*i);
		Sleep(1000);
		//放下筷子
		release(*i);    //放下右手边筷子
		release(*i);    //放下左手边筷子
		mutexV();
	}
	return 0;
}
Пример #2
0
action_result grinder_strategy_core_fn::next_action() {
    Try(intros_action());
    Try(assumption_action());
    Try(activate_hypothesis());
    Try(grinder_intro_action());
    Try(next());
    return action_result::failed();
}
Пример #3
0
action_result grinder_strategy_core_fn::hypothesis_pre_activation(hypothesis_idx hidx) {
    Try(assumption_contradiction_actions(hidx));
    Try(no_confusion_action(hidx));
    TrySolve(assert_cc_action(hidx));
    Try(discard_action(hidx));
    Try(subst_action(hidx));
    Try(pre(hidx));
    return action_result::new_branch();
}
Пример #4
0
static optional<expr> apply_cc() {
    flet<bool> set(get_config().m_cc, true);
    return mk_pre_action_strategy("cc",
                                  [](hypothesis_idx hidx) {
                                      Try(no_confusion_action(hidx));
                                      Try(assert_cc_action(hidx));
                                      return action_result::new_branch();
                                  })();
}
Пример #5
0
int	AliasSearch::Search(const char *address, AliasHandler &h)
{
char	*p=0;
const char *q;
char	*hostdomain=0;

	q=strrchr(address, '@');

	/* islocal checks both local domains, and hosted domains,
	** we want to replace domain with 'me' only for local domains.
	*/
	if (!q || (config_islocal(q+1, &hostdomain) && hostdomain == 0))
					/*
					** Make sure we look for aliases for
					** "me"
					*/
	{
		const char *me=config_defaultdomain();
		char *r;

		if (!q)
			q=address+strlen(address);

		p=(char *)courier_malloc(q-address+2+strlen(me));
		if (!p)	clog_msg_errno();
		memcpy(p, address, q-address);
		strcat(strcpy(&p[q-address], "@"), me);
		r=udomainlower(p);	/* For stupid people */
		free(p);
		p=r;
		address=p;
	}
	if (hostdomain)	free(hostdomain);

	if (Try(module_record, address, h) == 0 &&
		TryVirtual(module_record, address, &h) == 0 &&
		Try(local_record, address, h) == 0 &&
		TryVirtual(local_record, address, &h) == 0)
	{
		int rc;

#if HAVE_LDAP
		if (p)
			*strrchr(p, '@')=0;
		// Strip local domain from addresses passed to aliasd

		rc=TryAliasD(address, &h);
#else
		rc=1;
#endif
		if (p)	free(p);
		return (rc);
	}
	if (p)	free(p);
	return (0);
}
void Try(int q, int p)
{
	f << q << " " << (q + p) % n << endl;
	cout << q << " " << (q + p) % n << endl;
	if (kq[q][p] != 0)
	{
		if (kq[q][p] != 1)
			Try(q, kq[q][p]);
		if (p - kq[q][p] != 1)
			Try((q + kq[q][p]) % n, p - kq[q][p]);
	}
}
Пример #7
0
Location* Location::Read(Buffer *buf)
{
  String *filename = NULL;
  uint32_t line = 0;

  Try(ReadOpenTag(buf, TAG_Location));
  Try(filename = String::ReadCache(buf));
  Try(ReadUInt32(buf, &line));
  Try(ReadCloseTag(buf, TAG_Location));

  return Make(filename, line);
}
Пример #8
0
double skew(void)
{
	struct timespec tr[MAX_SAMPLES], tm[MAX_SAMPLES];
        int i;
        double result;

        for (i = 0; i < MAX_SAMPLES; i++) {
                Try(clock_gettime(CLOCK_MONOTONIC,&tm[i]));
                Try(clock_gettime(CLOCK_REALTIME,&tr[i]));
                result += timerdiff(&tr[i],&tm[i]);
        }
        return result / MAX_SAMPLES;
}
Пример #9
0
BlockModset* BlockModset::Read(Buffer *buf)
{
  BlockModset *res = NULL;

  Try(ReadOpenTag(buf, TAG_BlockModset));
  while (!ReadCloseTag(buf, TAG_BlockModset)) {
    switch (PeekOpenTag(buf)) {
    case TAG_BlockId: {
      Try(!res);
      BlockId *id = BlockId::Read(buf);
      res = Make(id);

      // clear out the modset in case it was in memory so we don't add the
      // same entries multiple times.
      res->ClearModset();
      break;
    }
    case TAG_ModsetEntry: {
      Try(res);

      Try(ReadOpenTag(buf, TAG_ModsetEntry));
      Exp *lval = Exp::Read(buf);
      Exp *kind = NULL;
      if (PeekOpenTag(buf) == TAG_Exp)
        kind = Exp::Read(buf);
      Try(ReadCloseTag(buf, TAG_ModsetEntry));

      res->AddModset(lval, kind);
      break;
    }
    case TAG_ModsetAssign: {
      Try(res);

      Try(ReadOpenTag(buf, TAG_ModsetAssign));
      Exp *left = Exp::Read(buf);
      Exp *right = Exp::Read(buf);
      Bit *guard = Bit::Read(buf);
      Try(ReadCloseTag(buf, TAG_ModsetAssign));

      res->AddAssign(left, right, guard);
      break;
    }
    default:
      Try(false);
    }
  }

  Try(res);
  return res;
}
Пример #10
0
void Load()
{
	Stackit;

	CoreSystemCreate("Corification", Update, Render);

	lpCoreBackground = new CoreBackground();

	lpCoreTexture = CoreSys.Vault->LinkTexture("Res/Block.png");
	lpCoreDynBody = CoreSys.CoreDynBodyCreate(CoreVector(), *lpCoreTexture);

	Try(lpHelp = new HelpText());
	Try(lpShip = new Ship());
	lpCoreFlareList = new CoreFlareList();
}
Пример #11
0
int main(){
  init();
  ll n;
  scanf("%lld",&n);
  ll i=0,prev=0;
  tlen=0;
  while(1){
    if(n%p[i]==0){
      if(p[i]!=prev){
        ++tlen;
        t[tlen-1]=p[i];
        c[tlen-1]=1;
        prev=p[i];
      }else{
        ++c[tlen-1];
      }
      n/=p[i];
    }else{
      ++i;
    }
    if(i>=plen|| n==1) break;
  }
  if(i>=plen){
    t[tlen]=n;
    ++c[tlen];
    ++tlen;
  }
  res=1;
  Try(0);
  printf("%lld",res);
  return 0;
}
Пример #12
0
void Try(int Position_Color, 
			int Labels[], int Num_Comp, 
			int LabelsB[], int Num_Blocks, 
			int Sol[], int Num_Sol){
   int k,i;
   int continue_to_try;
   int app_Labels[Size];
   int app_LabelsB[Size];

	if (Demo==1){
   	printf("\nTRY COLOR: %d, position=%d, with Freq %d\n",Colors[Position_Color],Position_Color,Freq[Position_Color]);
   	Print_Summary(Labels,Num_Comp,LabelsB,Num_Blocks,Sol,Num_Sol);
   }
   continue_to_try=Try_Add_Color(Position_Color,
   					Labels,&Num_Comp,
					LabelsB,&Num_Blocks,
					   Sol,&Num_Sol);
   if (Num_Blocks==1){
    	for (k=0; k<Num_Sol; k++){	// := 1 to Num_Sol
   		Best_Sol[k]=Sol[k];
      }
   	Best_Num_Sol=Num_Sol;
      Best_call=call;
      printf(" \n ********************************* BEST SOL %d\n",Best_Num_Sol);
      if (Demo==1){
         Print_Summary(Labels,Num_Comp,LabelsB,Num_Blocks,Sol,Num_Sol);
      }
   }
   else{
      if (continue_to_try==1){
      	for (i=0; i<n; i++)	app_Labels[i]=Labels[i];
      	for (i=0; i<n; i++)	app_LabelsB[i]=LabelsB[i];
        	k=Position_Color+1;
        	while((k<c)&&(Num_Sol<Best_Num_Sol-1)){
         	if ((Num_Sol==Best_Num_Sol-2)&&(Freq[k]<(Num_Comp-1)))	break;
            for (i=0; i<n; i++){
         		Labels[i]=app_Labels[i];
         	}
            for (i=0; i<n; i++){
         		LabelsB[i]=app_LabelsB[i];
         	}
            Try(k,	
					Labels,Num_Comp,
					LabelsB,Num_Blocks,
					Sol,Num_Sol);
            k=k+1;
            if (Demo==1){
            	if(k<c){
            		printf(" \n Continue Inner_Try of %d, position=%d, with the next color %d, position=%d\n",Colors[Position_Color],Position_Color,Colors[k],k);
            	}
            }
         }
      }
   }
   if (Demo==1){
   	if (continue_to_try==0)	printf("----> End Try color %d, position=%d\n",Colors[Position_Color],Position_Color);
      else printf(" \n End Inner_Try of %d, position=%d, with color %d, position=%d\n",Colors[Position_Color],Position_Color,k,Colors[k]);
   	getch();
   }
}
Пример #13
0
int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    Try(n, 0);
    return 0;
}
Пример #14
0
void Try(int a)
{
 if (d>2)
 {
  if (a==0)
  {
   if (kt(b[0]+b[1])==0 && kt(b[1]+b[2])==0)
   {
    for (int i=0;i<=2;i++) cout<<b[i]<<"+";
    cout<<endl;
    l[m++]=b[0]+b[1];
    l[m++]=b[1]+b[2];
   }
  }
 }
 else
 {
  for (int i=2;i<=a;i++)
   if (nt(i)==1)
   {
    b[d]=i;
    d++;
    Try(a-i);
    d--;
   }
 }
}
Пример #15
0
 void main()
 {
   Init(-1); /* 初始化迷宫,通道值为-1 */
   printf("此迷宫从入口到出口的路径如下:\n");
   m[begin.x][begin.y]=1; /* 入口的足迹为1 */
   Try(begin,1); /* 由第1步入口试探起 */
 }
Пример #16
0
void Try(int x, int y)
{
	int i;
	for(i=0; i<8; i++)
	{
		if(!InRange(x+dx[i])) continue;
		if(!InRange(y+dy[i])) continue;
		if(bVisited[x+dx[i]][y+dy[i]]) continue;
		
		bVisited[x+dx[i]][y+dy[i]] = 1;
		cntVisited ++;
		seqVisited[x+dx[i]][y+dy[i]] = ++seq;
		if(cntVisited == (N+1)*(N+1))
			FindSolution();
		else
		{
			if(x==4 && y==3)
			{
				int x6=0;
				x6++;
			}
			Try(x+dx[i], y+dy[i]);
		}
		bVisited[x+dx[i]][y+dy[i]] = 0;
		cntVisited --;
		seqVisited[x+dx[i]][y+dy[i]] =0,  seq--;
	}
}
Пример #17
0
int main(void)
{
  int n, i, j, k;

  scanf("%d", &n);
  while (n--)
  {
    debug = 0;
    memset (move_col, 0, sizeof(move_col));
    scanf("%d%d%d", &p, &c, &m);
    for (i = 0; i < m; ++i)
    {
      for (j = 0; j < p; ++j)
      {
        scanf("%d ", &k);
        move_pos[i][j] = k;
        ++move_col[i][k - 1];
      }
      scanf("%d%d", black + i, white + i);
    }
    for (i = 0; i < p; ++i) test[i] = 1;
    perform = 1;
    while (perform)
    {
      i = 0;
      while ((i < m) && (Try(i)))
        ++i;
      if (i == m) /* vyzkousel jsem vsechny tahy a vyhovuje to */
        Yes();
    }
    /* printf("Debug: %d\n", debug); */
  }
  return 0;
}
Пример #18
0
void main()
{
	Input("CHIADAGIAC.INP");
	ThucHien();
	Output("CHIADAGIAC.OUT");
	int vt = 0;
	for (int i = 1; i < n; ++i)
	{
		if (L[vt][n - 2] > L[i][n - 2])
			vt = i;
	}
	for (i = 0; i < n; ++i)
	{
		for (int j = 0; j < n - 1; ++j)
			cout << setprecision(2) << L[i][j] << "  ";
		cout << endl;
	}
	cout << endl << endl;
	for (i = 0; i < n; ++i)
	{
		for (int j = 0; j < n - 1; ++j)
			cout << kq[i][j] << " ";
		cout << endl;
	}
	f << L[vt][n - 2] << endl;
/*
	struct 
	{
		int d;
		int t;
	} s[MAX + 1];
	int top = 1;
	int q;
	int p;
	s[top].d = vt;
	s[top].t = n - 2;

	while (top > 0)
	{
		q = s[top].d;
		p = s[top].t;
		top--;
		f << q << " " << (q + p) % n << endl;
		cout << q << " " << (q + p) % n << endl;
		if (kq[q][p] != 0)
		{
			s[top + 1].d = q;
			s[top + 1].t = kq[q][p];
			if (kq[q][p] != 1)
				top++;
			s[top + 1].d = (q + kq[q][p]) % n;
			s[top + 1].t = p - kq[q][p];
			if (p - kq[q][p] != 1)
				++top;
		}
	}
*/
	Try(vt, n - 2);
}
Пример #19
0
 virtual action_result next_action() override {
     Try(intros_action());
     Try(activate_hypothesis());
     Try(trivial_action());
     Try(assumption_action());
     Try(recursor_action());
     Try(ematch_action());
     Try(constructor_action());
     Try(by_contradiction_action());
     TryStrategy(mk_backward_strategy());
     Try(qfc_action(list<gexpr>()));
     return action_result::failed();
 }
int main(void)
{
	struct timespec pre_time, post_time;
	struct timespec req, res;
	double diff;
	int k,i;
	static int bla=0;
	
	ioperm(0x378,3,1);
		
	req.tv_sec = 0;
	req.tv_nsec = 10;
	Try(clock_getres(CLOCK, &res));
	printf("Clock resolution %12.3f usec\n", 
	       (double)res.tv_nsec/NSEC_PER_USEC);
	printf("Requested time    difference(usec)\n");
	for (i=0; i<30; i++){
		req.tv_nsec *= 10;
		if (req.tv_nsec >= NSEC_PER_SEC) {
			req.tv_nsec = 100;
			req.tv_sec++;
		}
//		req.tv_sec = 0;
//		req.tv_nsec = 500 * 1000;
//		for (k = 0; k < 20; k++) {
			Try(clock_gettime(CLOCK, &pre_time));
			Try0(clock_nanosleep(CLOCK, 0, &req, NULL));
			Try(clock_gettime(CLOCK, &post_time));
			timersum(&post_time, &post_time, &req);
			if(bla) {
				outb(0x1,0x378);
				bla = 0;
			} else { 
				outb(0x0,0x378);
				bla = 1;
			}
		
			diff = better_timerdiff(&post_time, &pre_time)/NSEC_PER_USEC;
			////diff = timerdiff(&post_time, &pre_time);
			printf("%12.9f\t %12.9f\n", (double)req.tv_sec + ((double)req.tv_nsec/NSEC_PER_SEC), diff);
//		}
	}

	return 0;
}
Пример #21
0
ForceInline Void main2(Int argc, Char **argv)
{
    SColumnMask mask = { 0 };

    SetConsoleCtrlHandler(HandlerRoutine, True);
    GenerateChart(Max);
    Try(&mask, 0);
    printf("\n");
}
void Try(int sx, int sy, int r){
     if(r == 6){
          if(C[sx - 1][sy] == '#'){
                  P[r] = 'f';
                  ok = 1;
                  return;
                  } 
          if(C[sx][sy - 1] == '#'){
                  P[r] = 'l';
                  ok = 1;
                  return;
                  }
          if(C[sx][sy + 1] == '#'){
                  P[r] = 'r';
                  ok = 1;
                  return;    
                  }
          }
     if(ok) return;
     if(C[sx - 1][sy] == I[r]){
             P[r] = 'f';
             Try(sx - 1, sy, r + 1);
             if(ok) return;
             else
             P[r] = 'a';
             }
     if(ok) return;
     if(C[sx][sy - 1] == I[r]){
          P[r] = 'l';
          Try(sx, sy - 1, r + 1);
             if(ok) return;
             else
          P[r] = 'a';
          }
     if(ok) return;
     if(C[sx][sy + 1] == I[r]){
          P[r] = 'r';
          Try(sx, sy + 1, r + 1);
             if(ok) return;
             else
          P[r] = 'a';
          }
//     if(ok) return;
     }
Пример #23
0
void BlockSummary::ReadList(Buffer *buf, Vector<BlockSummary*> *sums)
{
  Assert(buf->pos == buf->base);

  while (buf->pos != buf->base + buf->size) {
    BlockSummary *sum;
    Try(sum = Read(buf));
    sums->PushBack(sum);
  }
}
Пример #24
0
/**
 * @brief Saves right-side file
 */
void CHexMergeDoc::OnFileSaveRight()
{
	if (m_pView[MERGE_VIEW_RIGHT]->GetModified())
	{
		const String &pathRight = m_filePaths.GetRight();
		if (Try(m_pView[MERGE_VIEW_RIGHT]->SaveFile(pathRight.c_str())) == IDCANCEL)
			return;
		UpdateDiffItem(m_pDirDoc);
	}
}
Пример #25
0
void Cut(int iBegin,int iTarget)
{
	char cPart[MAX];int i;
	for(i=iBegin+1;i<=iLen;i++)
	{
		memcpy(cPart,cNumber+iBegin,i-iBegin);cPart[i-iBegin]='\0';
		if(Try(i,iTarget-atoi(cPart))==TRUE)
			{cout<<" "<<cPart;Cut(i,iTarget-atoi(cPart));}
	}
}
Пример #26
0
void main()
{
 clrscr();
 cout<<"a=";
 cin>>a;
 d=0;
 m=0;
 Try(a);
 getch();
}
Пример #27
0
void BlockModset::ReadList(Buffer *buf, Vector<BlockModset*> *mods)
{
  Assert(buf->pos == buf->base);

  while (buf->pos != buf->base + buf->size) {
    BlockModset *mod;
    Try(mod = Read(buf));
    mods->PushBack(mod);
  }
}
Пример #28
0
/**
 * @brief Saves both files
 */
void CHexMergeDoc::OnFileSave() 
{
	BOOL bUpdate = FALSE;
	if (m_pView[MERGE_VIEW_LEFT]->GetModified())
	{
		const String &pathLeft = m_filePaths.GetLeft();
		if (Try(m_pView[MERGE_VIEW_LEFT]->SaveFile(pathLeft.c_str())) == IDCANCEL)
			return;
		bUpdate = TRUE;
	}
	if (m_pView[MERGE_VIEW_RIGHT]->GetModified())
	{
		const String &pathRight = m_filePaths.GetRight();
		if (Try(m_pView[MERGE_VIEW_RIGHT]->SaveFile(pathRight.c_str())) == IDCANCEL)
			return;
		bUpdate = TRUE;
	}
	if (bUpdate)
		UpdateDiffItem(m_pDirDoc);
}
Пример #29
0
static optional<expr> apply_ematch_simp() {
    flet<bool> set(get_config().m_ematch, true);
    return mk_action_strategy("ematch_simp",
                              [](hypothesis_idx hidx) {
                                  Try(no_confusion_action(hidx));
                                  TrySolve(assert_cc_action(hidx));
                                  return action_result::new_branch();
                              },
                              unit_propagate,
                              ematch_simp_action)();
}
bool Bicolorable(){
     for(i = 0; i < n; i++){
           if(N[i].Painted == false){
               color = 1;
               N[i].Painted = true;
               N[i].Color = color;  
               if(!Try(i)) return false;          
               }
//           if(!Try(i)) return false;
           }
     return true;
     }