#include <iostream>
#include <sstream>
using namespace std;
void porownaj(int nowa, int & stara) {
if (nowa < stara)
stara = nowa;
}
int main() {
int wysokosc;
int zasieg;
//fstream cin;
//cin.open("Input.txt");
cin >> wysokosc;
cin >> zasieg;
//int * piramida = (int*)malloc(wysokosc * sizeof(int));
int najstarszy;
if (zasieg >= 1) {
cin >> najstarszy;
string linia;
getline(cin, linia);
for (int i = 2; i <= wysokosc; i++) {
getline(cin, linia);
stringstream strumien(linia);
int koszt = i;
int glebokosc = 0;
int nowa;
for (int j = 1; j <= ((i / 2) + i % 2); j++) {
if (koszt <= zasieg) {
glebokosc++;
//int nowa;
//strumien >> nowa;
//porownaj(nowa, najstarszy);
koszt += i - 2 * j;
}
else
break;
}
if (glebokosc == 0)
break;
else {
for (int j = 1; j <= glebokosc; j++) {
strumien >> nowa;
porownaj(nowa, najstarszy);
}
for (int j = 1; j <= i-(2*glebokosc); j++) {
strumien >> nowa;
}
for (int j = 1; j <= glebokosc - (i - (2 * glebokosc) < 0); j++) {
strumien >> nowa;
porownaj(nowa, najstarszy);
}
}
}
}
cout << najstarszy;
//cin.close();
return 0;
//free(piramida);
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #include <iostream> #include <sstream> using namespace std; void porownaj(int nowa, int & stara) { if (nowa < stara) stara = nowa; } int main() { int wysokosc; int zasieg; //fstream cin; //cin.open("Input.txt"); cin >> wysokosc; cin >> zasieg; //int * piramida = (int*)malloc(wysokosc * sizeof(int)); int najstarszy; if (zasieg >= 1) { cin >> najstarszy; string linia; getline(cin, linia); for (int i = 2; i <= wysokosc; i++) { getline(cin, linia); stringstream strumien(linia); int koszt = i; int glebokosc = 0; int nowa; for (int j = 1; j <= ((i / 2) + i % 2); j++) { if (koszt <= zasieg) { glebokosc++; //int nowa; //strumien >> nowa; //porownaj(nowa, najstarszy); koszt += i - 2 * j; } else break; } if (glebokosc == 0) break; else { for (int j = 1; j <= glebokosc; j++) { strumien >> nowa; porownaj(nowa, najstarszy); } for (int j = 1; j <= i-(2*glebokosc); j++) { strumien >> nowa; } for (int j = 1; j <= glebokosc - (i - (2 * glebokosc) < 0); j++) { strumien >> nowa; porownaj(nowa, najstarszy); } } } } cout << najstarszy; //cin.close(); return 0; //free(piramida); } |
English