Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <set>
- #include <string>
- #include <algorithm>
- using namespace std;
- using ll = long long;
- void co(vector <int> v){
- for (auto x: v) cout<<x<<' ';
- cout<<'\n';
- }
- struct p{
- int x, y, clr;
- };
- int x_hlp(int x1, int y1, int x2, int y2){
- int xh1, xh2, yh; //help
- yh = y2;
- //cout<<"yh = "<<yh<<'\n';
- int dif = abs(y1 - yh);
- //cout<<"dif = "<<dif<<'\n';
- xh1 = x1 - dif;
- xh2 = x1 + dif;
- return xh1;
- }
- //color = {0, 1} = { white, black}
- int col(int x, int y){//color
- int xh = x_hlp(x, y, 0, 0);
- //cout<<"xh = "<<xh<<'\n';
- if (abs(xh) % 2 == 0) {
- //white
- return 0;
- }else{
- return 1;
- }
- }
- void cp(p P, string nm){
- cout<<"point = "<<nm<<'\n';
- cout<<"x = "<<P.x<<" y = "<<P.y<<" color = "<<P.clr<<'\n';
- }
- int y_ln(int x2, int y2, int x_md){//y in line with some (x, y)
- int dif = abs(x2 - x_md);
- int y_ln1, y_ln2;
- y_ln1 = y2 - dif;
- y_ln2 = y2 + dif;
- //они равносильны!
- return y_ln1;
- }
- int main()
- {
- int x1,x2, y1,y2;
- cin>>x1>>y1>>x2>>y2;
- p p1 = {x1, y1};
- p1.clr = col(x1, y1);
- p p2 = {x2, y2};
- p2.clr = col(x2, y2);
- //cp(p1, "p1");
- //cp(p2, "p2");
- bool can;
- if (p1.clr == 0 && p2.clr == 1){
- //cout<<"ONE\n";
- can = 1;
- vector <pair<int,int>> go(8);
- go[0] = {x1 - 1, y1 + 2};
- go[1] = {x1 + 1, y1 + 2};
- go[2] = {x1 + 2, y1 + 1};
- go[3] = {x1 + 2, y1 - 1};
- go[4] = {x1 + 1, y1 - 2};
- go[5] = {x1 - 1, y1 - 2};
- go[6] = {x1 - 2, y1 - 1};
- go[7] = {x1 - 2, y1 + 1};
- bool fast = 0;
- int fast_x, fast_y;
- int X,Y;
- //первый вопрос - супер_fast
- //второй вопрос - fast
- for (auto pnt: go){
- X = pnt.first;
- Y = pnt.second;
- //cout<<"X = "<<X<<" Y = "<<Y<<'\n';
- if (abs(X - x2) == abs(Y - y2)){
- fast = 1;
- if (X == x2 && Y == y2){
- cout<<1<<'\n';
- cout<<x2<<' '<<y2<<'\n';
- exit(0);
- }
- fast_x = X;
- fast_y = Y;
- }
- }
- if (fast){
- cout<<2<<'\n';
- cout<<fast_x<<' '<<fast_y<<'\n';
- cout<<x2<<' '<<y2<<'\n';
- }else{
- X = go[0].first;
- Y = go[0].second;
- int xH = x_hlp(X, Y, x2, y2);
- int x_mid = abs( max(xH,x2) - min(xH, x2)) / 2 + min(xH, x2);
- //cout<<"x_mid = "<<x_mid<<'\n';
- int y_mid = y_ln(x2, y2, x_mid);
- //cout<<"y_mid = "<<y_mid<<'\n';
- cout<<3<<'\n';
- cout<<X<<' '<<Y<<'\n';
- cout<<x_mid<<' '<<y_mid<<'\n';
- cout<<x2<< ' '<<y2<<'\n';
- }
- }
- else if (p1.clr == 1 && p2.clr == 1){
- can = 1;
- //cout<<"TWO\n";
- if (abs(x1 - x2) == abs(y1 - y2)){
- cout<<1<<'\n';
- cout<<x2<<' '<<y2<<'\n';
- }
- else{
- int xh;//проекция точки (x1, y1) на ось y = y2
- xh = x_hlp(x1, y1, x2, y2);
- int x_md;//middle = between min(x1,x2) and max(x1,x2)
- x_md = abs( max(xh,x2) - min(xh, x2)) / 2 + min(xh, x2);
- //cout<<"x_md = "<<x_md<<'\n';
- int y_md = y_ln(x2, y2, x_md);
- //cout<<"y_md = "<<y_md<<'\n';
- cout<<2<<'\n';
- cout<<x_md<<' '<<y_md<<'\n';
- cout<<x2<<' '<<y2<<'\n';
- }
- }
- else can = 0;
- //cout<<"can = "<<can<<'\n';
- if (!can){
- cout<<-1;
- exit(0);
- }
- }
- //4 2 -8 -1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement