int rand300000() { int x = 0; do { x = 65536 * rand16() + rand16(); } while (x > 14316 * 300000);//14316*300000时最接近65536*65536 return x % 300000; } std::set<int> solution(int targetNum)//target这里取100k { std::set<int> result; while (result.size() != targetNum) { int selectNum = rand300000(); while (result.find(selectNum) != result.end()) { selectNum = rand300000(); } result.insert(selectNum); } }
点赞 2

相关推荐

牛客网
牛客企业服务