Postingan lainnya
tlx toki subprogram
berikut adalah kode saya...sya check sudah bener tpi di web masih merah...mohon dikoreksi kesalahan sya dimana.
berikut website: https://tlx.toki.id/courses/basic/chapters/10/problems/F
berikut kode sya:
#include <iostream>
#include <stdio.h>
#include <iomanip>
#include <string>
#include <cstdio>
#include <cmath>
using namespace std;
void td(int d, int arr[100][2], int n)
{
int arrmax[100];
arrmax[0] = 0;
int max = arrmax[0];
for (int i = 0; i < n; i++)
{
for (int next = 0; next < n; next++)
{
if (arr[i][0] != arr[next][0])
{
arrmax[i] = arr[i][0] - arr[next][0];
}
if (arrmax[i] < 0)
{
arrmax[i] = -1 * arrmax[n];
}
if (max < arrmax[i])
{
max = arrmax[i];
}
}
}
int arr1[100];
int max1 = 0;
arr1[0] = 0;
max1 = arr1[0];
for (int i = 0; i < n; i++)
{
for (int next = 0; next < n; next++)
{
if (arr[i][1] != arr[next][1])
{
arr1[i] = arr[i][1] - arr[next][1];
}
if (arr1[i] < 0)
{
arr1[i] = -1 * arr1[i];
}
if (max1 < arr1[i])
{
max1 = arr1[i];
}
}
}
int pangkat1 = 1;
int pangkat2 = 1;
for (int i = 0; i < d; i++)
{
pangkat1 = pangkat1 * max;
}
for (int i = 0; i < d; i++)
{
pangkat2 = pangkat2 * max1;
}
int arrmin[100];
arrmin[0] = 100;
int min = arrmin[0];
for (int i = 0; i < n; i++)
{
for (int next = 0; next < n; next++)
{
if (arr[i][0] != arr[next][0])
{
arrmin[i] = arr[i][0] - arr[next][0];
}
if (arrmin[i] < 0)
{
arrmin[i] = -1 * arrmin[i];
}
if (arrmin[i] < min)
{
min = arrmin[i];
}
}
}
int min1;
int arr2[100];
arr2[0] = 100;
min1 = arr2[0];
for (int i = 0; i < n; i++)
{
for (int next = 0; next < n; next++)
{
if (arr[i][1] != arr[next][1])
{
arr2[i] = arr[i][1] - arr[next][1];
}
if (arr2[i] < 0)
{
arr2[i] = -1 * arr2[i];
}
if (arr2[i] < min1)
{
min1 = arr2[i];
}
}
}
int pangkat0 = 1;
int pangkat3 = 1;
for (int i = 0; i < d; i++)
{
pangkat0 = pangkat0 * min;
}
for (int i = 0; i < d; i++)
{
pangkat3 = pangkat3 * min1;
}
cout << pangkat0 + pangkat3 << " " << pangkat1 + pangkat2;
}
int main()
{
int N, D;
cin >> N >> D;
int arr[1000][2];
for (int i = 0; i < N; i++)
{
for (int j = 0; j < 2; j++)
{
cin >> arr[i][j];
}
}
td(D, arr, N);
return 0;
}
0
Belum ada Jawaban. Jadi yang pertama Jawaban
Login untuk ikut Jawaban