コード例 #1
0
ファイル: PhiTiny.hpp プロジェクト: kimwalisch/primecount
    static int64_t get_c(int64_t y)
    {
        assert(y >= 0);

        if (y >= primes[max_a()])
            return max_a();
        else
            return pi[y];
    }
コード例 #2
0
ファイル: maxa.c プロジェクト: pawbhard/Algorithms
int max_a ( int N , int current,int clipboard,int select)
{
    if ( N == 0 )
        return current;;

    //ans for various keys
    int key1 = max_a(N-1,current+1,clipboard,0);                          //A
    int key2 = max_a(N-1,current,(select == 1 ? current: 0),0);       //ctrl + c
    int key3 = max_a(N-1,current+clipboard,clipboard,0);            //ctrl + v
    int key4 = max_a(N-1,current,clipboard,1);                      //ctrl + a

    return maximum(key1,key2,key3,key4);
}
コード例 #3
0
ファイル: maxa.c プロジェクト: pawbhard/Algorithms
void main(int argc, char *argv[])
{
    int N = atoi(argv[1]);
    printf("\nTesting max with 14 2 17 11 = %d\n",maximum(14,2,17,11));
    printf("Maximum A for N = %d is %d\n",N,max_a(N,0,0,0));
    //printf("Maximum A for N = %d is %d\n",N,max_a_dp(N));
}
コード例 #4
0
ファイル: 7-10.c プロジェクト: unnamed42/code_learning
int main(){
	int i;
	printf("Please input 10 integers:\n");
	for(i=0;i<10;i++)
		scanf("%d",&a[i]);
	printf("max=%d,min=%d,average=%.2f\n",max_a(a),min_a(a),ave_a(a));
	return 0;
}
コード例 #5
0
ファイル: PhiTiny.hpp プロジェクト: kimwalisch/primecount
 static bool is_tiny(int64_t a) {
     return a <= max_a();
 }
コード例 #6
0
ファイル: alphabeta.cpp プロジェクト: hdl/CS561-reversi
Board_info Alphabeta::run_alphabeta(Board_info &current_board, int depth, int a, int b, char tile)
{
	Board_info best_child, temp_child;
	vector<Board_info> children;
	vector<Board_info>::iterator child;
	int break_flag=0;

	if (depth == 0){
		current_board.visited = 1;
		if(tile == your_tile){
			current_board.a=a;
			current_board.b=current_board.weight;
		}
		else{
			current_board.a=current_board.weight;
			current_board.b=b;
		}
		(DEBUG?cout:log) << xy2(current_board.x, current_board.y)<<","<<this->depth - depth<<","<< current_board.weight<<",";
		(DEBUG?cout:log) << ab2(a, b)<<endl;
	}else{
		if(current_board.visited==0){
			current_board.visited = 1;
			(DEBUG?cout:log) << xy2(current_board.x, current_board.y)<<","<<this->depth - depth<<",";
			(DEBUG?cout:log) << (tile == your_tile ?"-":"")<<"Infinity,";
			(DEBUG?cout:log) <<ab2(a,b) <<endl;
		}
	}

	if(depth == 0){
		return current_board;
	}

	children = get_new_boards_vector(your_tile, current_board, tile);
	// it's pocoutible get 0 child
	if(children.size() == 0){
		cout<<"no children"<<endl;
		current_board.print();
		exit(0);
	}else{
		sort(children.begin(), children.end(), compare_order);
	}

	best_child.a = a;
	best_child.b = b;
	if(tile == your_tile){
		for(child=children.begin(); child != children.end(); ++child){
			temp_child = run_alphabeta(*child, depth -1, best_child.a, best_child.b, other_tile);
			best_child = max_a(best_child, temp_child);
			(DEBUG?cout:log) << xy2(current_board.x, current_board.y)<<","<<this->depth - depth<<","<< best_child.weight<<",";
			if(best_child.b<=best_child.a){
				cout<<"prune form:"<<xy2(best_child.x, best_child.y)<<endl;
				break_flag = 1;
				(DEBUG?cout:log) <<ab2(current_board.a,best_child.b)<<endl;
				break;
			}else{
				(DEBUG?cout:log) <<ab2(best_child.a,best_child.b)<<endl;
			}
		}		
	}else{
		for(child=children.begin(); child != children.end(); ++child){
			temp_child = run_alphabeta(*child, depth -1, best_child.a, best_child.b, your_tile);	
			best_child = min_b(best_child, temp_child);
			(DEBUG?cout:log) << xy2(current_board.x, current_board.y)<<","<<this->depth - depth<<","<< best_child.weight<<",";
			if(best_child.b<=best_child.a){
				cout<<"prune form:"<<xy2(best_child.x, best_child.y)<<endl;
				break_flag = 1;
				(DEBUG?cout:log) <<ab2(best_child.a,current_board.b)<<endl;
				break;
			}else{
				(DEBUG?cout:log) <<ab2(best_child.a,best_child.b)<<endl;
			}
		}
	}
	free_boards(children);
	//weight is the only var to save/to callee 
	current_board.weight = best_child.weight;
	current_board.best_child_x = best_child.x;	
	current_board.best_child_y = best_child.y;
	if(break_flag==0){
		if(tile == your_tile)
			current_board.b = best_child.a;
		else
			current_board.a = best_child.b;
	}
	cout << xy2(current_board.x, current_board.y) <<":"<< xy2(current_board.best_child_x, current_board.best_child_y)<<endl;	
	return current_board;
}