"Algorithmic Learning Notes" 68. Enumerating SJTU OJ 1272 writing games

Source: Internet
Author: User

It's easy not to worry too much about efficiency, although we have to reorder each time

Note the use of vectors is very convenient.

Another trick is to use an existing bool array to record whether or not it exists.

#include <iostream>#include<vector>#include<algorithm>using namespacestd;BOOLhave[ +] = {0};vector<int> v;//using vectors to realize the simplicity of dynamic arraysBOOLCmp_int (Const int& A,Const int&b) {    returna<b;}intMainintargcChar Const*argv[]) {        intN; CIN>>N;  for(inti =0; I < n; ++i) {intK; CIN>>K;        V.push_back (k); HAVE[K]=true; }         while(1){        BOOLHave_new =false;//set temporary check variables to see if this scan has new elements .//reorder after each updatesort (V.begin (), V.end (), cmp_int); N= V.size ();//use N to determine the scope of this scan if the loop is directly using size to produce an iterative effect.         for(inti =1; I < n; ++i) {             for(intj=0; J < I; ++J) {//Enumerate two numbers                intres = V[i]/V[j]; if(!have[res]) {//Judging if it's already in the vector.V.push_back (RES); Have[res]=true; Have_new=true; }            }        }        if(!have_new) {             Break; }} cout<<v.size () <<Endl; return 0;}

"Algorithmic Learning Notes" 68. Enumerating SJTU OJ 1272 writing games

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.