Afişează mesaje
Pagini: [1]
1  infoarena - concursuri, probleme, evaluator, articole / Arhiva de probleme / Răspuns: 1480 Traseu3 : Martie 18, 2016, 12:57:31
Cod:
[#include <fstream>
#include <queue>
#include <cstring>
#define nmax 105
using namespace std;
ifstream fin("traseu3.in");
ofstream fout("traseu3.out");
 
struct rooms {
    short storey, line, column;
};
 
queue < rooms > tail;
 
int building[nmax][nmax][nmax], n, m;
 
bool was_here[nmax][nmax][nmax], sec_was_here[nmax][nmax][nmax];
 
int d_f[6] = {-1, 0, 0, 0, 0, 1};
int d_l[6] = {0, -1, 0, 0, 1, 0};
int d_c[6] = {0, 0, -1, 1, 0, 0};
 
bool is_ok(int x, int y, int z) {
    if (x < 1 or y < 1 or z < 1 or x > n or y > n or z > n or building[x][y][z] == -1 or was_here[x][y][z] == true)
        return false;
    return true;
}
 
void main_program() {
    while (!tail.empty()) {
        short storey = tail.front().storey;
        short line = tail.front().line;
        short column = tail.front().column;
        tail.pop();
        for (int k = 0; k < 6; ++k)
            if (is_ok(storey + d_f[k], line + d_l[k], column + d_c[k])) {
                building[storey + d_f[k]][line + d_l[k]][column + d_c[k]] = building[storey][line][column] + 1;
                was_here[storey + d_f[k]][line + d_l[k]][column + d_c[k]] = true;
                rooms stuff = {storey + d_f[k], line + d_l[k], column + d_c[k]};
                tail.push(stuff);
            }
    }
}
 
bool is_good(int x, int y, int z) {
    if (x < 1 or y < 1 or z < 1 or x > n or y > n or z > n or was_here[x][y][z] == false or sec_was_here[x][y][z] == true)
        return false;
    return true;
}
 
void second_main_program(int x, int y, int z, int stop_x, int stop_y, int stop_z) {
    while (!tail.empty()) {
        short storey = tail.front().storey;
        short line = tail.front().line;
        short column = tail.front().column;
        tail.pop();
        for (int k = 0; k < 6; ++k)
            if (is_ok(storey + d_f[k], line + d_l[k], column + d_c[k]))
                if (building[storey + d_f[k]][line + d_l[k]][column + d_c[k]] = building[storey][line][column] - 1) {
                    was_here[storey + d_f[k]][line + d_l[k]][column + d_c[k]] = true;
                    rooms stuff = {storey + d_f[k], line + d_l[k], column + d_c[k]};
                    tail.push(stuff);
                }
    }
    rooms stuff = {x, y, z};
    tail.push(stuff);
    fout << x << " " << y << " " << z << "\n";
    sec_was_here[x][y][z] = true;
    while (!tail.empty()) {
        short storey = tail.front().storey;
        short line = tail.front().line;
        short column = tail.front().column;
        tail.pop();
        for (int k = 0; k < 6; ++k)
            if (is_good(storey + d_f[k], line + d_l[k], column + d_c[k]))
                if (building[storey + d_f[k]][line + d_l[k]][column + d_c[k]] == building[storey][line][column] + 1) {
                    sec_was_here[storey + d_f[k]][line + d_l[k]][column + d_c[k]] = true;
                    rooms stuff = {storey + d_f[k], line + d_l[k], column + d_c[k]};
                    tail.push(stuff);
                    fout << storey + d_f[k] << " " << line + d_l[k] << " " << column + d_c[k] << "\n";
                    if (storey + d_f[k] == stop_x and line + d_l[k] == stop_y and column + d_c[k] == stop_z)
                        return;
                    break;
                }
    }
}
 
void read_input() {
    fin >> n >> m;
    int floor_m, line_m, column_m, floor_c, line_c, column_c;
    fin >> floor_m >> line_m >> column_m >> floor_c >> line_c >> column_c;
    rooms stuff = {floor_m, line_m, column_m};
    tail.push(stuff);
    was_here[floor_m][line_m][column_m] = true;
    building[floor_m][line_m][column_m] = 1;
    for (int i = 1; i <= m; ++i) {
        int x, y, z;
        fin >> x >> y >> z;
        building[x][y][z] = -1;
    }
    main_program();
    fout << building[floor_c][line_c][column_c] << "\n";
    stuff = {floor_c, line_c, column_c};
    tail.push(stuff);
    memset(was_here, false, sizeof(was_here));
    was_here[floor_c][line_c][column_c] = true;
    second_main_program(floor_m, line_m, column_m, floor_c, line_c, column_c);
}
 
int main()
{
    read_input();
    return 0;
}]

Iau 90 cu TLE pe celelalte.
2  infoarena - concursuri, probleme, evaluator, articole / Arhiva de probleme / Răspuns: 137 Reuniune : Februarie 08, 2016, 23:57:02
Iau 90 de puncte si wa pe testu 4. Ce cazuri sa tratez? Annoyed
3  Comunitate - feedback, proiecte si distractie / Off topic / Am Bitdefender Total Security licen si nu mai pornesc progr. pe CB 13.12 : Martie 29, 2015, 21:53:36
 Brick wall     mi le baga in carantina cand dau build & run cu toate ca i-am dat excludere la CB..... am nationala peste 1 sapt va rog ajutor !!!
4  infoarena - concursuri, probleme, evaluator, articole / Arhiva de probleme / Ce nu e bine ? : Februarie 25, 2015, 19:54:22
 Am studiat vreo 20-30 de cazuri si pentru toate codul de mai jos era bun, eu am gasit trei cazuri (cand e patrat perfect, cand nu e patrat perfect si e impar, cand e patrat perfect si e par):

#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;
ifstream f("chiftea.in");
ofstream g("chiftea.out");
int t,x,i;
int main()
{
    f>>t;
    for (i=1;i<=t;i++)
    {f>>x;
    if (sqrt(x)==(int)(sqrt(x)))
        g<<x-(pow(sqrt(x)-2,2))+4<<"\n";

    if (sqrt(x)!=(int)(sqrt(x))&&x%2==0)
        g<<x+4<<"\n";

    if (sqrt(x)!=(int)(sqrt(x))&&x%2==1)
        g<<x+5<<"\n";
    }
    return 0;
}
  Brick wall
Pagini: [1]
Powered by SMF 1.1.19 | SMF © 2006-2013, Simple Machines