ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1369. Cockroach Race

почему невернЬІй ответ?
Posted by Andriy_Zhyvchyn 6 Jul 2011 18:32
#include <iostream>
#include <math.h>
using namespace std;

float tar[100000][2];
float slad[10000][2];
float ooo[100000][2];

int prov (float a[100000][2], int n) {
    int i=0; int j=0;
    for (i=0; i<n; i++)
    for (j=i+1; j<n; j++)
    if (a[i][0]==a[j][0] || a[i][1]==a[i][1]) return 0;
    return 1; }

void obch (float x, float y, float tarr[100000][2], int mm, float oooo[100000][2]) {
    int ii=0;
    for (ii=0; ii<mm; ii++) {
        oooo[ii][0]=sqrt(((x-tarr[ii][0])*(x-tarr[ii][0]))+((y-tarr[ii][1])*(y-tarr[ii][1])));
        oooo[ii][1]=ii+1; } }

float min_n (float oooo[100000][2], int mm) {
    float nomm=oooo[0][1]; float znn=oooo[0][0]; int ii=0;
    for (ii=0; ii<mm; ii++) {
        if (oooo[ii][0]<znn) { nomm=oooo[ii][1]; znn=oooo[ii][0]; } }
    return nomm; }

int main () {
    int i=0; int m; int n;
    float min;
    cin>>m;
    for (i=0; i<m; i++) {
        cin>>tar[i][0];
        cin>>tar[i][1]; }
    cin>>n;
    if(m<=n || m<=0) return 0;
    for (i=0; i<n; i++) {
        cin>>slad[i][0];
        cin>>slad[i][1]; }
    if (!prov(tar,m) && !prov(slad,n)) return 0;
    for (i=0; i<n; i++) {
        obch (slad[i][0], slad[i][1], tar, m, ooo);
        min=min_n(ooo,m);
        for (float j=min-1; j<m; j++)
        if (ooo[(int)(min-1)][0]==ooo[(int)(j)][0]) cout<<ooo[(int)(j)][1]<<' ';
        cout<<endl; }
    system ("pause");
    return 0; }