Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <ctime>
- #include <string>
- using namespace std;
- const long double pi = 3.14159265;
- struct Point
- {
- int number;
- float x;
- float y;
- double radius;
- string status;
- };
- int main()
- {
- float A;
- int K;
- srand(time(0));
- cout << "Введите A, K" << endl;
- cin >> A >> K;
- Point* array = new Point [K];
- int strike_count = 0;
- float max_r = 0, min_r = 4*A;
- int minr_index = -1, maxr_index = -1;
- for (int i = 0; i < K; i++) {
- array[i].number = i;
- do {
- array[i].x = (float)rand() / RAND_MAX * 8 * A - 4 * A;
- array[i].y = (float)rand() / RAND_MAX * 8 * A - 4 * A;
- } while (array[i].x*array[i].x + array[i].y*array[i].y >= 16*A*A);
- array[i].radius = sqrt(array[i].x*array[i].x+array[i].y*array[i].y);
- if (array[i].radius > max_r) {
- maxr_index = i;
- max_r = array[i].radius;
- }
- if (array[i].radius < min_r) {
- minr_index = i;
- min_r = array[i].radius;
- }
- if (array[i].x*array[i].x+array[i].y*array[i].y <= 4*A*A) {
- if (0.5*abs(array[i].x)+abs(array[i].y) > A) {
- array[i].status = "Норма";
- strike_count++;
- }
- else {
- array[i].status = "Брак";
- }
- }
- else {
- array[i].status = "Брак";
- }
- }
- cout << "Таблица попавших" << endl << endl;
- int counter = 0;
- for (int i = 0; i < K; i++) {
- if (array[i].status == "Норма") {
- counter++;
- cout << array[i].number + 1 << " " <<
- "(" << array[i].x << ", " << array[i].y << ")" << " " <<
- array[i].radius << " "
- << array[i].status << endl;
- }
- }
- cout << "Процент точек: " << 100.0*counter/K << endl;
- cout << endl;
- cout << "Таблица не попавших" << endl << endl;
- counter = 0;
- for (int i = 0; i < K; i++) {
- if (array[i].status == "Брак") {
- counter++;
- cout << array[i].number + 1 << " " <<
- "(" << array[i].x << ", " << array[i].y << ")" << " " <<
- sqrt(array[i].x*array[i].x+array[i].y*array[i].y) << " "
- << array[i].status << endl;
- }
- }
- cout << "Процент точек: " << 100.0*counter/K << endl;
- cout << endl << "Процент попадания точек в область: " << 100.0*strike_count/K << "%" << endl;
- cout << "Отношение площади мишени к площади круга: " << (pi*4*A*A-4*A*A)/(16*A*A*pi) << endl;
- cout << "Максимально удаленная точка: " << "(" << array[maxr_index].x << ", " << array[maxr_index].y << ")" << " " <<
- "Расстояние: " << array[maxr_index].radius << endl;
- cout << "Минимально удаленная точка: " << "(" << array[minr_index].x << ", " << array[minr_index].y << ")" << " " <<
- "Расстояние: " << array[minr_index].radius << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement