In order to solve and optimize the task and virtual machine allocation strategy in cloud computing environment, firstly allocation strategy mathematical model, the target of which is the total running time, is established, then a simulated annealing and genetic hybrid algorithm is proposed to solve the mathematical model. The integer coding, a crossover operator, two kinds of mutation operators and the selection mechanism based on simulated annealing strategy are applied in the hybrid algorithm. In the experiments, three sets of data are used to verify the performance of the hybrid algorithm in the Cloudsim software. And the experimental results show that the series of cloud tasks can effectively be assigned to the virtual machine by the hybrid algorithm and the total running time is also minimized by the algorithm.