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");
}
0 5691 Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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
{
|
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{
|
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
|
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?
| |
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...
|
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.
|
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>
|
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...
|
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,...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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();...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |