Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

P3122 Луговской Дмитрий Сергеевич task 7 #594

Open
wants to merge 2 commits into
base: task-7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/main/cpp/t01_min.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@

using namespace std;

//function min
int min(int a,int b) {
if (a > b) return b;
else return a;
}

//function min4
int min4(int a, int b, int c, int d) {
return min(min(a, b), min(c, d));
}

int t01_min() {
int a, b, c, d;
cin >> a >> b >> c >> d;
cout <<min4(a, b, c, d);

return 0;
}
8 changes: 7 additions & 1 deletion src/main/cpp/t02_dist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@

using namespace std;

//function distance
double distance(double x1,double y1,double x2,double y2) {
return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}

int t02_dist() {
int x1=0,x2=0,y1=0,y2=0;
cin >> x1 >> x2 >> y1>>y2;
cout << distance(x1,x2,y1,y2);


return 0;
}
8 changes: 7 additions & 1 deletion src/main/cpp/t03_circle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@

using namespace std;

//function IsPointInCircle
bool IsPointInCircle(double x, double y, double xc, double yc, double r) {
return (sqrt(pow(x - xc, 2) + pow(y - yc, 2)) <= r);
}

int t03_circle() {
double x=0, y=0, xc=0, yc=0, r=0;
cin >> x >> y >> xc>>yc>>r;
if (IsPointInCircle(x,y,xc,yc,r)) cout << "YES";
else cout << "NO";

return 0;
}
8 changes: 7 additions & 1 deletion src/main/cpp/t04_area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@

using namespace std;

//function IsPointInArea
int IsPointInArea(double x,double y) {
return ((sqrt((x+1)*(x+1)+(y-1)*(y-1)) <= 2.0) and (y>=-x)&&(y>=2*x+2)) or ((sqrt((x+1)*(x+1)+(y-1)*(y-1)) >= 2.0) and (y<=-x) and (y<=2*x+2));
}

int t04_area() {
double x=0,y=0;
cin >> x >> y;
if (IsPointInArea(x, y)) cout << "YES";
else cout << "NO";

return 0;
}
16 changes: 14 additions & 2 deletions src/main/cpp/t05_power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,21 @@

using namespace std;

//function power
double power(double a, double n){
if(n>0) {
return power(a, n-1)*a;
}
else if(n<0) {
n = -n;
return ((power((1/a), n-1))/a);
}
else if (n==0)
return 1;
}

int t05_power() {

double a=0, n=0;
cin >> a >> n;
cout << power(a,n);
return 0;
}
10 changes: 9 additions & 1 deletion src/main/cpp/t06_sum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@

using namespace std;

int t06_sum() {
double sum (){
double a;
cin >> a;
if (a!=0)
return a+sum();
else return 0;
};

int t06_sum() {
cout<<sum();
return 0;
}
14 changes: 11 additions & 3 deletions src/main/cpp/t07_fib.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//Напишите функцию fib(n), которая по данному целому положительному n возвращает n-e число Фибоначчи.
//Напишите функцию fib(n), которая по данному целому положительному n возвращает n-e число Фибоначчи.
// В этой задаче нельзя использовать циклы - используйте рекурсию.
//Первое и второе числа Фибоначчи равны 1, а каждое следующее равно сумме двух предыдущих.
//Формат входных данных
Expand All @@ -17,9 +17,17 @@

using namespace std;

// function fib

double fib(double n) {
if ((2==n) or (n==1))
return 1;
else
return (fib(n-1)+fib(n-2));
}
int t07_fib()
{
double n;
cin>>n;
cout<<fib(n);

return 0;
}
39 changes: 36 additions & 3 deletions src/main/cpp/t08_queen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,40 @@

using namespace std;

int t08_queen(){

return 0;
}
int coord_x[10], coord_y[10];
int final=0;
int check(int x=0, int y=0, int d=0)
{
if (x==d)
final=1;
else
final=((coord_y[d] != y) and (abs(x - coord_x[d]) != abs(y - coord_y[d]))) and check(x, y, d + 1);

return final;
}
int attack(int n=0, int x=0, int y=0)
{
if ((y < n) and n>0)
{
int count = 0;
if (check(x, y))
{
coord_y[x] = y;
if (((x + 1) == n) and final)
count = 1;
else
count = attack(n, x+1);
}
return count + attack(n, x, y+1);
}
return 0;
}

int t08_queen() {
int z;
cin >> z;
for (int i = 0; i < z; i++)
coord_x[i] = i;
cout << attack(z)<<endl;
}