Beispiel #1
0
std::pair<int, long long> recursion(long long n)
{
	if (n == 0 || cf[n].first != 0)
	{
		return cf[n];
	}
	long long a = (long long)cbrt(n);
	long long b = a-1;
	std::pair<int, long long> ap = recursion(n - a*a*a), bp = recursion(a*a*a - b*b*b - 1);
	if (ap.first >= bp.first)
	{
		cf[n] = std::make_pair(ap.first+1, ap.second + a*a*a);
	}
	else
	{
		cf[n] = std::make_pair(bp.first+1, bp.second + b*b*b);
	}
	return cf[n];
}
Beispiel #2
0
void
program_resource_visitor::process(const glsl_type *type, const char *name)
{
   assert(type->without_array()->is_record()
          || type->without_array()->is_interface());

   char *name_copy = ralloc_strdup(NULL, name);
   recursion(type, &name_copy, strlen(name), false, NULL, false);
   ralloc_free(name_copy);
}
    vector<TreeNode *> generateTrees(int n) 
	{
		vector<TreeNode *> result;
		if (n <= 0) {
			result.push_back(NULL);
			return result;
		}
        result = recursion(n, 1);
		return result;
    }
Beispiel #4
0
void angreifer(char* zper)
{
    int i;
    char key[17]="";
    for (i=0;i<16;i++)
    {
        z[i]=zper[i];
    }
    recursion(0, key);
}
Beispiel #5
0
int
main(void)
{
	char cmd[sizeof(RMDIR) + PATH_MAX];
	int serrno;
	pid_t pid;

	strlcpy(dpath, "/tmp/unpgc.XXXXXXXX", sizeof(dpath));
	if (mkdtemp(dpath) == NULL)
		err(-1, "mkdtemp");

	/*
	 * Set up a parent process to GC temporary storage when we're done.
	 */
	pid = fork();
	if (pid < 0) {
		serrno = errno;
		(void)rmdir(dpath);
		errno = serrno;
		err(-1, "fork");
	}
	if (pid > 0) {
		signal(SIGINT, SIG_IGN);
		while (waitpid(pid, NULL, 0) != pid);
		snprintf(cmd, sizeof(cmd), "%s %s", RMDIR, dpath);
		(void)system(cmd);
		exit(0);
	}

	printf("Start: inflight %d open %d\n", getinflight(),
	    getopenfiles());

	twosome_nothing();
	twosome_drop();

	threesome_nothing();
	threesome_drop();

	fivesome_nothing();
	fivesome_drop();

	complex_cycles();

	listen_nothing();
	listen_drop();

	listen_connect_nothing();
	listen_connect_drop();

	recursion();

	printf("Finish: inflight %d open %d\n", getinflight(),
	    getopenfiles());
	return (0);
}
Beispiel #6
0
void recursion(node* current)
{
   for (int i = 0; i < 27; i++)
   {
       if (current->children[i] != NULL)
       {
           recursion(current->children[i]);
       }
   }
   free(current);
}
Beispiel #7
0
void* func(void* ignored=0)
{
   DBG(WTF,"IMPOSSIBLE HAPPENED %d=%d",3,2);
   DBG(ERR,"not enough free mem=%d bytes",7);
   DBG(WARN,"program went to sleep for %d seconds",1000000);
   DBG(INFO,"thread execution continues %s %s %s","happily","ever","after");   
   DBG(DUMP,"just calculated '+' for arguments %d and %d",42,69);

   recursion(7);
   return NULL;
}
 void recursion(vector<vector<int>> &res, vector<int>& v, int begin, int n, int k){
     if(v.size() == k){
         res.push_back(v);
         return;
     }
     for(int i = begin; i <= n; i++){
         v.push_back(i);
         recursion(res, v, i+1, n, k);
         v.pop_back();
     }
 }
Beispiel #9
0
 void recursion(vector<int> num, int i, int j, vector<vector<int> > &res) {
     if (i == j-1) {
         res.push_back(num);
         return;
     }
     for (int k = i; k < j; k++) {
         if (i != k && num[i] == num[k]) continue;
         swap(num[i], num[k]);
         recursion(num, i+1, j, res);
     }
 }
  vector<string> generateParenthesis(int n){
    vector<string> results;
    
    if(n <= 0){
      return results;
    }

    recursion("", n, n, results);

    return results;
  }
Beispiel #11
0
void recursion(int lowerValue, int upperValue) {
    // increment the call counter by one
    counter++;
    printf("Recursion call counter: %d\n", counter);
    
    printf("Current Lower Value: %d\n", lowerValue);
    
    if (lowerValue < upperValue) {
        lowerValue++;
        recursion(lowerValue, upperValue);
    }
}
void test6(void) {
  auto void recursion(int a) {
    if(a == 5) {
      printf("V");
    } else {
      throw(a * 10);
      recursion(a + 1);
    };
    throw(recursion);
  };
  try {
    recursion(0);
  } catch(40) {
    printf("U\n");
    comeback;
  } catch(recursion) {
    comeback;
  } rescue {
    comeback;
  };
};
 ListNode* recursion(ListNode* head, ListNode*& newHead){ //pass the pointer
     if(head->next == NULL){                              //as reference
         newHead = head;
         return head;
     }
     else{
     ListNode* temp = recursion(head->next, newHead);
     temp->next = head;
     return head;
         
     }
 }
Beispiel #14
0
int input()
{
    int num = 0 ;
    int tempnum = 0;
    int i = 0 ;
    int xyz[3];
    int flag = 3;
    int casetag=1;
   
//    struct Cell cell[10];
    for(i=0;;i++)
    {
        scanf("%d",&tempnum);
        if(tempnum == 0)
            return 1;
        if(num == 0)
        {
            num = tempnum;
            celllength = tempnum;
            continue;
        }
        if(num > 0)
        {
            if(flag>0)
            {
                flag--;
                xyz[flag] = tempnum;
                if(flag == 0)
                {
                    num--;
                    flag = 3;
                    cell[num][2]= xyz[2];
                    cell[num][1] = xyz[1];
                    cell[num][0] = xyz[0];

                    if(num == 0)
                    {
                        recursion(celllength-1);
                        printf("Case %d: %d\n",casetag,max);
                        casetag++;
                        max = 0;
                         celllength = 0;
                    }
                    ///    cell[num]
                }
            }

        }
            
    };
    return 1;
}
Beispiel #15
0
void
program_resource_visitor::process(ir_variable *var)
{
   unsigned record_array_count = 1;
   const bool row_major =
      var->data.matrix_layout == GLSL_MATRIX_LAYOUT_ROW_MAJOR;

   const unsigned packing = var->get_interface_type() ?
      var->get_interface_type()->interface_packing :
      var->type->interface_packing;

   const glsl_type *t =
      var->data.from_named_ifc_block ? var->get_interface_type() : var->type;
   const glsl_type *t_without_array = t->without_array();

   /* false is always passed for the row_major parameter to the other
    * processing functions because no information is available to do
    * otherwise.  See the warning in linker.h.
    */
   if (t_without_array->is_record() ||
              (t->is_array() && t->fields.array->is_array())) {
      char *name = ralloc_strdup(NULL, var->name);
      recursion(var->type, &name, strlen(name), row_major, NULL, packing,
                false, record_array_count, NULL);
      ralloc_free(name);
   } else if (t_without_array->is_interface()) {
      char *name = ralloc_strdup(NULL, t_without_array->name);
      const glsl_struct_field *ifc_member = var->data.from_named_ifc_block ?
         &t_without_array->
            fields.structure[t_without_array->field_index(var->name)] : NULL;

      recursion(t, &name, strlen(name), row_major, NULL, packing,
                false, record_array_count, ifc_member);
      ralloc_free(name);
   } else {
      this->set_record_array_count(record_array_count);
      this->visit_field(t, var->name, row_major, NULL, packing, false);
   }
}
Beispiel #16
0
    /**
     * @param n n pairs
     * @return All combinations of well-formed parentheses
     */
    vector<string> generateParenthesis(int n) {
        // Write your code here
        string a,b,s;
        for(int i=0;i<n;i++){
            a.push_back('(');
            b.push_back(')');
        }
        s = a+b;
        save_str.push_back(s);

        recursion(s);
        return save_str;
    }
Beispiel #17
0
 void recursion(vector<int> nums, int idx, vector<vector<int>>& result) {
     if (idx >= nums.size() - 1) {
         result.push_back(nums);
     }
     else {
         for (int i = idx; i < nums.size(); i++) {
             if (i == idx || nums[idx] != nums[i]) {
                 swap(nums[idx], nums[i]);
                 recursion(nums, idx + 1, result);
             }
         }
     }
 }
void main() {
	int x;
	int y;
	int *foo;
	int i;
	char p;
	char arr[4];
	int z;
	
	foo = (int *) malloc(sizeof(int));

	z=0;
	x=1;
	y=3;
	add(x,y,foo);
	printf("%d + %d is %d\n", x, y, *foo);
	mult(6,4,foo);
	printf("%d * %d is %d\n", 6,4,*foo);
	doNothingAndStallTime();
	doNothingAndStallTime();
	doNothingAndStallTime();
	doNothingAndStallTime();
	doNothingAndStallTime();
	doNothingAndStallTime();
	recursion(10);
	divide(6,0,foo);
	printf("%d / %d is %d\n", 6,0,*foo);
	divide(6,2,foo);
	printf("%d / %d is %d\n", 6,2,*foo);
	
	
	p = 52;
	printf("p before the change was %d\n", p);
	incr_in_ptr(&p);
	printf("p after the change is %d\n", p);
	
	printf("now enter your nickname\n");
	scanf("%s", arr);
	
	printf("hello %s! from now your name shall be ", arr);
	for(i=0; i<3; i++){
		incr_in_ptr(arr+i);
	}
	printf("%s. goodbye for now!\n", arr);
	printf("WAIT! z should be 0, and it's %d!\n", z);

	// if we free foo there is a segmentation fault :(
	//free(foo);
	return;

}
Beispiel #19
0
bool recursion(int x, int y) {
	if (x == 10) {
		return true;
	}
	if (!map[x][y]) {
		for (int i = 1; i <= 9; i++) {
			if (sero(x, y, i) && garo(x, y, i) && squ(x, y, i)) {
				map[x][y] = i;
				if (y == 9) {
					if (recursion(x + 1, 1)) {
						return true;
					}
				}
				else {
					if (recursion(x, y + 1)) {
						return true;
					}
				}
			}
		}
		map[x][y] = 0;
		return false;
	}
	else {
		if (y == 9) {
			if (recursion(x + 1, 1)) {
				return true;
			}
		}
		else {
			if (recursion(x, y + 1)) {
				return true;
			}
		}

		return false;
	}
}
Beispiel #20
0
void
uniform_field_visitor::process(ir_variable *var)
{
   const glsl_type *t = var->type;

   /* Only strdup the name if we actually will need to modify it. */
   if (t->is_record() || (t->is_array() && t->fields.array->is_record())) {
      char *name = ralloc_strdup(NULL, var->name);
      recursion(var->type, &name, strlen(name));
      ralloc_free(name);
   } else {
      this->visit_field(t, var->name);
   }
}
Beispiel #21
0
void
program_resource_visitor::process(const glsl_type *type, const char *name)
{
   assert(type->without_array()->is_record()
          || type->without_array()->is_interface());

   unsigned record_array_count = 1;
   char *name_copy = ralloc_strdup(NULL, name);
   unsigned packing = type->interface_packing;

   recursion(type, &name_copy, strlen(name), false, NULL, packing, false,
             record_array_count, NULL);
   ralloc_free(name_copy);
}
Beispiel #22
0
void recursion(int x)
{   
   DBG_BLOCK("%d levels to go",x);
   usleep((random()%300)*1000);
   if(x>0)
   {
      x--;
      DBG(DUMP,"about go invoke recursion with %d",x);
      DBG(INFO,"recursion continues");   
      recursion(x);
   }
   else
      DBG(INFO,"recursion reached end");   
}
Beispiel #23
0
void recursion(int number, char* key){
    int k,j;
    char byte, temp;
/*
 * Backtracking - prüfen, ob z[i]=(a[i]+a[i+3])%256;
 */
    if (number > 3)
    {
        if (((key[number] + key[number-3]) % 256) != z[number-3])
            return;
    }
/*
 * Backtracking - prüfen, ob a[i+10]=(a[i]^a[i+5]);
 */
    if (number > 10)
    {
        byte=key[number-5]^key[number-10];
        //Rotation >>> 5
        temp = byte;                                    // a = temp = 87654321
        byte = temp % 20;                 //32 = 2^5       a = 54321
        byte = byte * 8;                  // 8 = 2^3       a = 54321000
        temp = temp / 20;                 // 32 = 2^5      temp = 876
        byte = byte ^ temp;                             // a = 54321876
        
        if (byte!=key[number])
            return;
    }
/*
 * Schlüssel ist komplett geprüft, 
 */
    if (number==16) 
    {
        printf("\nLösung     : ");
        for (j=0;j<10;j++)
        {
            printf("%d ", key[j]);
        }
        printf("\n");
        return;
    }
/*    
 * Rekursion fortsetzen 
 */ 
    number++;
    for(k=0;k<256;k++)
    {
        key[number]=k;
        recursion(number,key);
    }
}
int main(void) {
	int i, j;

	a[1][1] = 1;
	a[2][1] = 3, a[2][2] = 2;
	a[3][1] = 4, a[3][2] = 10, a[3][3] = 1;
	a[4][1] = 4, a[4][2] = 3, a[4][3] = 2, a[4][4] = 20;

	memset(d, -1, sizeof(d));	
	
	printf("%d\n", recursion(1,1));	

	return 0;
}
Beispiel #25
0
int main (int argc, char *argv[])
{
	QApplication app(argc, argv);

	QMap<QString, QString> p;
	p["name"]         = "Zysch";
	p["version"]      = "1.0.1";
	p["report-url"]   = "http://localhost/cgi-bin/cgi-collector/collector.py";
	p["report-email"] = "*****@*****.**";
	Breakpad::install(app.applicationDirPath(), p);

	recursion(10);

	// return app.exec();
}
Beispiel #26
0
int main(int argc, const char * argv[]) {
    // insert code here...

    int lower, upper;
    
    printf("Please enter the lower boundary value: ");
    scanf("%d", &lower);
    printf("Please enter the upper boundary value: ");
    scanf("%d", &upper);
    
    printf("Calling the recursion function!\n\n");
    
    recursion(lower, upper);
    
    return 0;
}
Beispiel #27
0
int main()
{
    int i;
    while (gets(arr))
    {
        if (arr[0]>='0' && arr[0]<='9')
        {
            for (f=0;arr[i]!='\0';++i)
            {
                number=
            }
        }

        else
            recursion(0);
    }
Beispiel #28
0
void msort(void *arry, int num, int size
    , int (*cmp)(const void *, const void *))
{
    void *ptmp = malloc(num * size);

    if(ptmp == NULL)
    {
        fprintf(stderr, "%s:%s:%s\n", __FILE__, __LINE__, strerror(errno));
        return;
    }

    recursion(arry, 0, num, size, ptmp, cmp);

    free(ptmp);
    return;
}
Beispiel #29
0
void recursion(int i)
{
    int number;
    if (arr[i]!='\0')
        recursion(i+1);
    else
        return ;
    number=(int)arr[i];
    //printf("%d\n",number);
    while(number)
    {
        printf("%d",number%10);
        number/=10;
    }

    return ;
}
Beispiel #30
0
void recursion(int left, int prev, int n, int** comb, int* combSize, int*** ret, int* returnSize, int** columnSizes)
{
    if (left == 0) {
        (*returnSize)++;
        *ret = realloc(*ret, sizeof(int*) * (*returnSize));
        (*ret)[(*returnSize) - 1] = malloc(sizeof(int) * (*combSize));
        *columnSizes = realloc(*columnSizes, sizeof(int) * (*returnSize));
        (*columnSizes)[(*returnSize) - 1] = *combSize;
        memcpy((*ret)[(*returnSize) - 1], *comb, (*combSize) * sizeof(int));
        return;
    }
    for (int i = prev + 1; i <= n; i++) {
        (*comb)[(*combSize)++] = i;
        recursion(left - 1, i, n, comb, combSize, ret, returnSize, columnSizes);
        (*combSize)--;
    }
}