Ejemplo n.º 1
0
int findAnswer(int l,int r)
{
	int mid=(l+r)/2,x,y,z;
	if(r>l)
	{
		x=findAnswer(l,mid);
		y=findAnswer(mid+1,r);
		z=merge(l,mid,r);
		return x+y+z;
	}
	else return 0;
}
Ejemplo n.º 2
0
int main()
{
	ll n,k,t,counter,temp,i;
	fact[0]=1;
	for(i=1;i<100001;i++)
		fact[i]=(fact[i-1]*i)%MOD;
	p[0]=1;
	for(i=1;i<100001;i++)
		p[i]=(p[i-1]*2)%MOD;
	populate_inverse();
	scanf("%lld",&t);
	while(t--)
	{
		scanf("%lld%lld",&n,&k);
		counter=0;
		for(i=0;i<n;i++)
		{
			scanf("%lld",&temp);
			if(temp==0)
				counter++;
		}
		n-=counter;
		printf("%lld\n",findAnswer(n,k,counter));
	}
	return 0;
}
Ejemplo n.º 3
0
int main()
{
	int t,n,i,j;
	answerArray=(int*)malloc(sizeof(int)*(MAX+1));
	for(i=0;i<MAX;i++)
		answerArray[i]=-1;
	/*
	for(i=5;i<MAX;i++)
		if(answerArray[i]==-1)
		{
			//printf("%d \n",i);
			answerArray[i]=findAnswer(i);
			if(answerArray[i]==1)
				for(j=i;j<MAX;j+=i)
					answerArray[j]=answerArray[i];
		}
	*/
	//printf("Enter the number of test cases : ");
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		if(answerArray[n]==-1)
		{
			answerArray[n]=findAnswer(n);
			if(answerArray[n]==1)
				for(i=n;i<=MAX;i+=n)
					answerArray[i]=1;
		}
		if(answerArray[n]==1)
			printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}
Ejemplo n.º 4
0
int main(void) {
    int i, queen[14];
    scanf("%d", &n);

    cnt = 0;

    findAnswer(1, queen);

    printf("%d\n", cnt);

    return 0;
}
Ejemplo n.º 5
0
int main()
{
    int t,n;
    char arr[11];
    scanf("%d",&t);
    while(t--)
    {
        scanf("%s",arr);
        printf("%d\n",findAnswer(arr));
    }
    return 0;
}
Ejemplo n.º 6
0
//--------------------------------------------------------------
void testApp::update() {
  if (origin.y > 0) {
    unsigned char *data = pixelsBelowWindow(origin.x, origin.y, 400, 400);
    cv::Mat argb(400, 400, CV_8UC4, data);
    cv::Mat rgb(400, 400, CV_8UC3);
    int fromTo[] = {1,0, 2,1, 3,2};
    mixChannels(&argb, 1, &rgb, 1, fromTo, 3);
    ofxCv::toOf(rgb, image);
    image.reloadTexture();
    
    getStateFromImage();
    findAnswer();
    
    if (selected.size()) {
      mouseThread.move(origin.x + (selected[0] + (ofRandom(1) < 0.5 ? -1 : 1)) * 50 + 23,
                       origin.y + selected[1] * 50 + 23);
      return;
    }
    
    if (wildcard.size()) {
        mouseThread.click(origin.x + wildcard[0] * 50 + 23, origin.y + wildcard[1] * 50 + 23);
        return;
//      int max_count = 0;
//      unsigned int max_id = 0;
//      for (map<unsigned int, int>::iterator it = count.begin(); it != count.end(); it++) {
//        if (it->second > max_count) {
//          max_count = it->second;
//          max_id = it->first;
//        }
//      }
//      if (max_count > 0) {
//        cout << "max_id: " << max_id << ", count: " << max_count << endl;
//        for (int i = 0; i < wildcard.size(); i += 2) {
//          int x = wildcard[i];
//          int y = wildcard[i + 1];
//          if (state[x][y].id == max_id) {
//            mouseThread.click(origin.x + x * 50 + 23, origin.y + y * 50 + 23);
//            return;
//          }
//        }
//      }
    }
    
    if (answers.size() > 0) {
      Answer ans = answers.at(ofRandom(MIN(answers.size(), 3)));
      mouseThread.drag(origin.x + ans.x1 * 50 + 23,
                       origin.y + ans.y1 * 50 + 23,
                       origin.x + ans.x2 * 50 + 23,
                       origin.y + ans.y2 * 50 + 23);
    }
  }
}
Ejemplo n.º 7
0
  void Matching::deserializeAnswer(JSONValue const &document) {
    QuizQuestion::deserializeAnswer(document);

    if (document["answer"].isArray()) {
      for (auto pairDocument : document["answer"]) {
        ID matchId = ResourceParser::parseId(pairDocument, "match_id");
        ID answerId = ResourceParser::parseId(pairDocument, "answer_id");

        if (matchId && answerId) {
          matchPair(findAnswer(answerId), matchId);
        }
      }
    }
  }
Ejemplo n.º 8
0
int main()
{
	int t;
	ll n,m;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%lld%lld",&n,&m);
		if(findAnswer(n,m))
			printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}
Ejemplo n.º 9
0
int main()
{
	int l,r,q,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",arr+i);
	scanf("%d",&q);
	while(q--)
	{
		scanf("%d%d",&l,&r);
		l--;r--;
		for(i=l;i<=r;i++)
			temp[i-l]=arr[i];
		printf("%d\n",findAnswer(0,r-l));
	}
	return 0;
}
Ejemplo n.º 10
0
void findAnswer(int row, int *before) {
    int i, j, next[14];
    if (row > n) {
        if (cnt++ < 3) {
            for (i=1; i<=n; i++) printf("%d ", before[i]);
            printf("\n");
        }
        return;
    }
    for (i=1; i<=n; i++) {
        for (j=1; j<row; j++) {
            if(checkImpossible(j, before[j], row, i)) break;
        }
        if (j == row) {
            copyHard(before, next);
            next[row] = i;
            findAnswer(row + 1, next);
        }
    }
}
Ejemplo n.º 11
0
//==========================================
int main(void)
{
	int testCase;
	number = 1;

	input = fopen("path.inp", "r");
	output = fopen("path.out", "w");

	fscanf(input, "%d", &testCase);

	while (testCase--){
		fscanf(input, "%d %d %d", &M, &N, &K);
		inputData();
		
		findAnswer();
		printAnswer();
		initData();		
	}

	fclose(input);
	fclose(output);
	return 0;
}
Ejemplo n.º 12
0
 void MultipleChoice::choose(ID answerId) {
   return choose( findAnswer(answerId) );
 }
Ejemplo n.º 13
0
 bool Esp8266<T>::wasCommandSuccessful(unsigned long timeout) const
 {
   return findAnswer("OK", timeout);
 }