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;
- void cv(vector <int> v){
- for (auto x: v) cout<<x<<' ';
- cout<<'\n';
- }
- struct pnt{
- int x,y;
- char mr = 'Z';
- };
- vector <pnt> way;
- void cp(pnt x){
- //cout<<"xy= "<<x.x<<" "<<x.y<<"\n";
- //cout<<"mr= "<<x.mr<<"\n";
- cout<<x.x<<' '<<x.y<<' '<<x.mr<<"\n";
- }
- bool cn(pnt a, pnt b){
- return (abs(a.x-b.x) == abs(a.y - b.y));
- }
- bool pos = 1;
- int sgn(int a, int b){
- if (a - b < 0) return -1;
- else return 1;
- }
- char mir(pnt fr, pnt to, pnt br){
- /*cout<<"sgn(br.x, fr.x)= "<<sgn(br.x, fr.x)<<"\n";
- cout<<"sgn(br.x, to.x)= "<<sgn(br.x, to.x)<<"\n";
- cout<<"sgn(br.y, fr.y)= "<<sgn(br.y, fr.y)<<"\n";
- cout<<"sgn(br.y, to.y)= "<<sgn(br.y, to.y)<<"\n";*/
- if (sgn(br.x, fr.x) == sgn(br.x, to.x)){
- //cout<<"return 'V';\n";
- return 'V';
- }
- else {
- //cout<<"return 'H';\n";
- return 'H';
- }
- }
- void brg(pnt fr, pnt to){
- if (cn(fr, to)){
- // cout<<"cn(fr, to\n";
- return;
- }
- pnt thr;
- thr.y = to.y;
- thr.x = fr.x + (-fr.y + thr.y);
- /*cout<<"thr\n";
- cp(thr);*/
- pnt br;
- br.x = (thr.x + to.x) / 2;
- //cout<<"(thr.x + to.x) / 2 = "<<(thr.x + to.x) / 2<<"\n";
- br.y = to.y + (to.x - br.x);
- br.mr = mir(fr, to, br);
- /*cout<<"to\n";
- cp(to);
- cout<<"br\n";
- cp(br);
- cout<<"can???\n";
- cout<<"abs(br.x-to.x) "<<abs(br.x-to.x)<<"\n";
- cout<<"abs(br.y - to.y)= "<<abs(br.y - to.y)<<"\n";*/
- if (!cn(br, to) || !cn(br, fr)){
- //cout<<"CANNOT\n";
- pos = 0;
- }
- way.push_back(br);
- }
- int main()
- {
- /*ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);*/
- pnt a,b;
- int x2,y2;
- cin>>x2>>y2;//why?
- a = {0, 0};
- b = {x2, y2};
- brg(a, b);
- //cout<<"pos= "<<pos<<"\n";
- if (!pos){
- cout<<-1<<"\n";
- }else{
- if (way.empty()){
- cout<<0<<"\n";
- }else{
- cout<<way.size()<<"\n";
- cp(way[0]);
- }
- }
- }
- /*
- -10 -10 10 -8
- 0 0 5 1
- 0 0 -1 2
- 0 0 3 5
- 0 0 9 -1
- */
Add Comment
Please, Sign In to add comment