#include <cstdio>
#include <cstring>#include <iostream>#include <vector>#include <cstdlib>#include <algorithm>using namespace std;int sample(int * array, int N){
int sum=0; for(int i=0;i<N;i++) { sum=sum+array[i]; } vector<int> a; // int k=0; for(int i=0;i<N;i++) { for(int j=0;j<array[i];j++) { a.push_back(i); // a[k++]=i; } } int key = 1.0 * rand() / RAND_MAX * sum; return a[key];}//array[3]={3,2,5}//a[]={0,0,0,1,1,2,2,2,2,2}int array[3] = {3,2,5};
int main(){ // for (int i = 0; i < 1000000; i++){ // array[i] = rand();//} srand(time(NULL)); int t0=0,t1=0,t2=0; for(int i=0;i<10000;i++) { int t=sample(array,3); if(t==0) t0++; else if(t==1) t1++; else t2++; } cout<<t0<<" "<<t1<<" "<<t2<<" "<<endl; return 0;}