E D R S I H C RSS
ID
Password
Join
Your mode of life will be changed for the better because of good news soon.

FrontPage 10000개의겹치지않는좌표생성

#include <iostream>
#include <fstream>
#include <ctime>
#include <cstdlib>
#include <set>
using namespace std;

typedef pair<int, int> Point2D;

class IsSame {
public:
       bool operator()(const Point2D &left, const Point2D &right) {
       	       return ((left.first < right.first) || ( (left.first == right.first) && (left.second < right.second)));
       }
};

void process();

int main() {
    process();
    return 0;
}

void process() {
    fstream target_fp;
    set<Point2D, IsSame> set_points;
    
    target_fp.open("input2.txt",ios::out);
    
    srand(time(NULL));
    
    int count = 10000; //rand()%10 + 1;
    int x = 0, y = 0;
  
    Point2D tempPoint;
   
    target_fp << count << endl;
 
    while ( set_points.size() < count) {
    	x = rand()%10000;
    	y = rand()%10000;
    	tempPoint.first = x;
    	tempPoint.second = y;
    	set_points.insert(tempPoint);
    }
    set<Point2D, IsSame>::iterator it;
    for ( it = set_points.begin(); it != set_points.end(); it++ ) {
          if ( it != set_points.begin() ) {
            target_fp << endl;
          }
    	    target_fp << it->first << " " << it->second;
    }
    
    
    target_fp.close();
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2013-05-23 01:29:35
Processing time 0.0284 sec