|
|
вернуться в форум#include <iostream> #include <cstdio> #include <cmath> using namespace std; const int MIN = 1, MAX = 8; int free(int x0, int y0) { int c = 0; double r0 = sqrt(5), r; for (int x = x0 - 2; x <= x0 + 2; x++) for (int y = y0 - 2; y <= y0+2; y++) { r = sqrt(pow(x - x0, 2) + pow(y - y0, 2)); if (r == r0 && x >= MIN && x <= MAX && y >= MIN && y <= MAX) c++; }
return c; } int main() { int T; // kolichestvo testovyx blokov cin >> T; cin.ignore();
int x, y; for (int t = 0; t < T; t++) { x = cin.get() - 'a' + 1; y = cin.get() - '0'; cout << free(x, y) << endl; cin.ignore(); } } Edited by author 20.11.2016 00:44 if (x >= MIN && x <= MAX && y >= MIN && y <= MAX) r = sqrt(pow(x - x0, 2) + pow(y - y0, 2)); if (r == r0) c++; Edited by author 20.11.2016 15:06 А в чем суть изменения, которое вы предлагаете? Тот же самый код в итоге, который дает ошибку в первом тесте, как и исходный. You shouldn't compare floats via strict "==". You should better do integer valuations only: int r0 = 25; int r = (x-x0)*(x-x0) + (y-y0)*(y-y0); if (r == r0...) |
|
|