473,602 Members | 2,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Closest pair problem

2 New Member
Hello;

The code below is one of solving the closest pair problem but some parts missing can any one help me out.



#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>

#define MAXPOINTS 30
#define NMAX 400
struct point_t {
double x, y;
} points[MAXPOINTS];

#define SQR(x) ((x)*(x))
#define DIST(p1,p2) sqrt(SQR((p1).x-(p2).x) + SQR((p1).y-(p2).y))


/* Generate a random set of points. */
void generate_random _points(void)
{
int i;

srandom(time(NU LL)); /* Seed the random number generator */

for (i = 0; i < MAXPOINTS; i++) {
points[i].x = random() % NMAX;
points[i].y = random() % NMAX;
}
}


void print_points(in t l, int r);

int main(void)
{
generate_random _points();

/* Find the closest pair, then call print points to print the points */

return 0;
}

/* Draws the points and a line between the closest pair.
* parameters: l,r are indexes of the closest points in our array.
*/
void print_points(in t l, int r)
{
int i;
FILE *f = fopen("shortest .svg", "w");
fprintf(f,"<?xm l version='1.0'?> \n");
fprintf(f,"<svg xmlns='http://www.w3.org/2000/svg'>\n");


fprintf(f, "<g id=\"x\">\n");

for (i = 0; i < MAXPOINTS; i++) {
struct point_t p = points[i];
/* Print the point as a circle of radius 2. */
fprintf(f, "<circle cx=\"%.2f\" cy=\"%.2f\" r=\"2\"/>\n",
p.x, p.y);
}

/* Now print a line between the rtwo closest points. */
fprintf(f, "<path d=\"M %.2f %.2f ",
points[l].x, points[l].y); /* SVG move to. */

fprintf(f, "L %.2f %.2f ", points[r].x, points[r].y);
fprintf(f, "\" fill=\"none\" stroke=\"red\"/>\n");

fprintf(f, "</g>\n</svg>\n");
fclose(f);

fprintf(stderr, "Output saved to 'shortest.svg'\ n");
}
Nov 2 '06 #1
0 5691

Sign in to post your reply or Sign up for a free account.

Similar topics

13
12303
by: mike | last post by:
I have ListArray with number in Eg: 1, 1.456, 2.43, 4, 6.78 next i have a decimal variable containing one number EG: 1.786 Could someone please tell me how i find the "closest match" number below the decimal variable from the arraylist. Thanks ever so much in advance
4
3446
by: Florent Garcin | last post by:
Hello! I would like to use the map structure with a key of Pair<string, string> and an int as the value. Pair is defined as: template <class T1, class T2> class Pair {
11
9104
by: kietzi | last post by:
Hello world, I was wondering whether it would be possible to create a map which uses a pair of ints as key and a float as value. I have used maps with const char* as key, but have so far not been successful to use a version which uses pairs as keys. For instance, I would like to set up the map as follows: struct eqstr { bool operator()(pair<int,int> s1, pair<int,int> s2) const{
2
1622
by: razael1 | last post by:
#include <utility> #include <vector> using namespace std; vector< pair<int,int v; Generates an error: ISO C++ forbids declaration of 'vector' with no type
18
2037
by: desktop | last post by:
I have made this little test with std::pair: test<intt1(1); test<intt2(2); std::pair<test<int>,test<int mypair = std::make_pair(t1,t2); where test is a template class I wrote. It seems a bit cumbersome to make a pair are there any better way to do it than the above procedure?
1
1696
by: yakitori | last post by:
I'm very sorry because I suspect that this is the same-old-same-old to some of you. I did search first. With MySQL 5.0.27, I have the query shown below. It *almost* does what I want. In fact it does exactly what I want if there is only one row in p_ferritin table. However, I am trying to limit the number of rows available to one of the tables - specifically p_ferritin. I want that table only to make available a single row (to the entire join...
22
4705
by: Steve Richter | last post by:
Does the .NET framework provide a class which will find the item in the collection with a key which is closest ( greater than or equal, less than or equal ) to the keys of the collection? ex: collection keys are 20, 30, 40, 50, 60, 70, 80 find key which is >= 35. would return the 30 key.
3
2948
by: eiji.anonremail | last post by:
Hi folks, I have a compile problem on linux, and maybe someone has an idea: #include <map> #include <iostream>
5
2843
by: p309444 | last post by:
Hi. I have an application in which the user can select a location and view it's distance from several Points Of Interests (POIs). When I retrieve these distances, I would also like to retrieve the ID's of the locations that are the next closest and the next furthest away from each POI. eg. If we have 10 locations, each of them a mile further away from a certain POI the I would like to return: The name of the POI, The distance from that...
0
7920
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8404
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8268
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6730
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5440
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
1510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1254
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.