Created
September 21, 2023 13:54
-
-
Save barron9/8ca395006a8cf452422130a14f2b3171 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <cmath> | |
#include <string> | |
int main(){ | |
std::vector<std::pair<int, int>> vec; | |
std::vector<std::pair<int, int>> vecquen; | |
int count,tablesize,_q_y,_q_x; | |
std::cin>>tablesize; | |
std::cin>>count; | |
std::cin>>_q_y; | |
std::cin>>_q_x; | |
vecquen.push_back(std::make_pair(_q_y, _q_x)); | |
std::vector<std::pair<int, int>> vecquenPerpendbottomforXequality ; | |
std::vector<std::pair<int, int>> vecquenPerpendtopforXequality ; | |
std::vector<std::pair<int, int>> vecquenPerpendleftforYequality ; | |
std::vector<std::pair<int, int>> vecquenPerpendrightforYequality ; | |
std::vector<std::pair<int, int>> firstcros ; | |
std::vector<std::pair<int, int>> secondcros ; | |
std::vector<std::pair<int, int>> thirdcros ; | |
std::vector<std::pair<int, int>> fortcros ; | |
while(count--){ | |
int blockx,blocky; | |
std::cin>>blocky; | |
std::cin>>blockx; | |
vec.push_back(std::make_pair(blocky, blockx)); | |
//find min distance blocks available(max 8 blocks). | |
//perpend. | |
if(blockx == _q_x){ | |
if(blocky - _q_y < 0){ | |
vecquenPerpendbottomforXequality.push_back(std::make_pair(blocky, blockx)); | |
if(vecquenPerpendbottomforXequality.size()<2){continue;} | |
if(vecquenPerpendbottomforXequality.at(0).first < vecquenPerpendbottomforXequality.at(1).first){ | |
vecquenPerpendbottomforXequality.erase(vecquenPerpendbottomforXequality.begin()); | |
}else { | |
vecquenPerpendbottomforXequality.erase(vecquenPerpendbottomforXequality.begin()+1); | |
} | |
}else{ | |
vecquenPerpendtopforXequality.push_back(std::make_pair(blocky, blockx)); | |
if(vecquenPerpendtopforXequality.size()<2){continue;} | |
if(vecquenPerpendtopforXequality.at(0).first > vecquenPerpendtopforXequality.at(1).first ){ | |
vecquenPerpendtopforXequality.erase(vecquenPerpendtopforXequality.begin()); | |
}else { | |
vecquenPerpendtopforXequality.erase(vecquenPerpendtopforXequality.begin()+1); | |
} | |
} | |
}else if(blocky == _q_y){ | |
if(blockx - _q_x < 0){ | |
//left side of the queen | |
vecquenPerpendleftforYequality.push_back(std::make_pair(blocky, blockx)); | |
if(vecquenPerpendleftforYequality.size()<2){continue;} | |
if(vecquenPerpendleftforYequality.at(0).first < vecquenPerpendleftforYequality.at(1).first ){ | |
vecquenPerpendleftforYequality.erase(vecquenPerpendleftforYequality.begin()); | |
}else { | |
vecquenPerpendleftforYequality.erase(vecquenPerpendleftforYequality.begin()+1); | |
} | |
}else{ | |
//rgiht side of the queen | |
vecquenPerpendrightforYequality.push_back(std::make_pair(blocky, blockx)); | |
if(vecquenPerpendrightforYequality.size()<2){continue;} | |
if(vecquenPerpendrightforYequality.at(0).first > vecquenPerpendrightforYequality.at(1).first ){ | |
vecquenPerpendrightforYequality.erase(vecquenPerpendrightforYequality.begin()); | |
}else { | |
vecquenPerpendrightforYequality.erase(vecquenPerpendrightforYequality.begin()+1); | |
} | |
} | |
} | |
//cross | |
if(blockx - _q_x < 0 && blocky - _q_y > 0 && std::abs(blocky - _q_y) == std::abs(blockx - _q_x)){ //1. | |
firstcros.push_back(std::make_pair(blocky, blockx)); | |
if(firstcros.size()<2){continue;} | |
if(firstcros.at(0).first > firstcros.at(1).first){ | |
firstcros.erase(firstcros.begin()); | |
}else { | |
firstcros.erase(firstcros.begin()+1); | |
} | |
}else if(blockx - _q_x > 0 && blocky - _q_y > 0 && blocky - _q_y == blockx - _q_x){ //2. | |
secondcros.push_back(std::make_pair(blocky, blockx)); | |
if(secondcros.size()<2){continue;} | |
if(secondcros.at(0).first > secondcros.at(1).first){ | |
secondcros.erase(secondcros.begin()); | |
}else { | |
secondcros.erase(secondcros.begin()+1); | |
} | |
}else if(blockx - _q_x < 0 && blocky - _q_y < 0 && blocky - _q_y == blockx - _q_x){ //3. | |
thirdcros.push_back(std::make_pair(blocky, blockx)); | |
if(thirdcros.size()<2){continue;} | |
if(thirdcros.at(0).first < thirdcros.at(1).first){ | |
thirdcros.erase(thirdcros.begin()); | |
}else { | |
thirdcros.erase(thirdcros.begin()+1); | |
} | |
}else if(blockx - _q_x > 0 && blocky - _q_y < 0 && std::abs(blocky - _q_y) == std::abs(blockx - _q_x)){ //4. | |
fortcros.push_back(std::make_pair(blocky, blockx)); | |
if(fortcros.size()<2){continue;} | |
if(fortcros.at(0).first < fortcros.at(1).first){ | |
fortcros.erase(fortcros.begin()); | |
}else { | |
fortcros.erase(fortcros.begin()+1); | |
} | |
} | |
} | |
///print ... | |
//std::cout<<"(tabel size)"<<std::endl; | |
//std::cout<<"("<< tablesize << "x" <<tablesize <<")"<<std::endl; | |
//std::cout<<"(quen position)"<<std::endl; | |
for (const std::pair<int, int>& a : vecquen) { | |
//std::cout<<"("<<a.first<<","<<a.second<<")"<<std::endl; | |
} | |
int score = 0; | |
//std::cout<<"(blocks position)"<<std::endl; | |
for (const std::pair<int, int>& a : vec) { | |
//std::cout<<"("<<a.first<<","<<a.second<<")"<<std::endl; | |
} | |
//std::cout<<"(blocks position:vecquenPerpendbottomforXequality)"<<std::endl; | |
for (const std::pair<int, int>& a : vecquenPerpendbottomforXequality) { | |
//std::cout<<"("<<a.first<<","<<a.second<<")"<<std::endl; | |
} | |
if(vecquenPerpendbottomforXequality.size()==0){ | |
score += _q_y - 1; | |
}else { | |
score += std::abs(vecquenPerpendbottomforXequality.at(0).first - _q_y)-1; | |
} | |
//std::cout<<"(blocks position:vecquenPerpendtopforXequality)"<<std::endl; | |
for (const std::pair<int, int>& a : vecquenPerpendtopforXequality) { | |
//std::cout<<"("<<a.first<<","<<a.second<<")"<<std::endl; | |
} | |
if(vecquenPerpendtopforXequality.size()==0){ | |
score += tablesize - _q_y; | |
}else { | |
score += std::abs(vecquenPerpendtopforXequality.at(0).first - _q_y)-1; | |
} | |
//std::cout<<"(blocks position:vecquenPerpendleftforYequality)"<<std::endl; | |
for (const std::pair<int, int>& a : vecquenPerpendleftforYequality) { | |
//std::cout<<"("<<a.first<<","<<a.second<<")"<<std::endl; | |
} | |
if(vecquenPerpendleftforYequality.size()==0){ | |
score += _q_x - 1; | |
}else { | |
score += std::abs(vecquenPerpendleftforYequality.at(0).second - _q_x)-1; | |
} | |
//std::cout<<"(blocks position:vecquenPerpendrightforYequality)"<<std::endl; | |
for (const std::pair<int, int>& a : vecquenPerpendrightforYequality) { | |
//std::cout<<"("<<a.first<<","<<a.second<<")"<<std::endl; | |
} | |
if(vecquenPerpendrightforYequality.size()==0){ | |
score += tablesize - _q_x; | |
} | |
else { | |
score += std::abs(vecquenPerpendrightforYequality.at(0).second - _q_x)-1; | |
} | |
//std::cout<<"(blocks position:firstcros)"<<std::endl; | |
for (const std::pair<int, int>& a :firstcros) { | |
//std::cout<<"("<<a.first<<","<<a.second<<")"<<std::endl; | |
} | |
if(firstcros.size() == 0){ | |
//score += tablesize - _q_y; | |
int tempx = _q_x; | |
int tempy = _q_y; | |
while(tempy<tablesize && tempx<tablesize){ | |
score++; | |
tempx++; | |
tempy++; | |
} | |
} | |
else { | |
score += std::abs(firstcros.at(0).first - _q_y)-1; | |
} | |
//std::cout<<"(blocks position:secondcros)"<<std::endl; | |
for (const std::pair<int, int>& a : secondcros) { | |
//std::cout<<"("<<a.first<<","<<a.second<<")"<<std::endl; | |
} | |
if(secondcros.size() == 0){ | |
int tempx = _q_x; | |
int tempy = _q_y; | |
while(tempy<tablesize && tempx>1){ | |
score++; | |
tempx--; | |
tempy++; | |
} | |
} | |
else { | |
score += std::abs(secondcros.at(0).first - _q_y)-1; | |
} | |
//std::cout<<"(blocks position:thirdcros)"<<std::endl; | |
for (const std::pair<int, int>& a : thirdcros) { | |
//std::cout<<"("<<a.first<<","<<a.second<<")"<<std::endl; | |
} | |
if(thirdcros.size() == 0){ | |
int tempx = _q_x; | |
int tempy = _q_y; | |
while(tempy>1 && tempx>1){ | |
score++; | |
tempx--; | |
tempy--; | |
} | |
// score += std::min(_q_x, _q_y) - 1; | |
}else { | |
score += std::abs(thirdcros.at(0).first - _q_y)-1; | |
} | |
//std::cout<<"(blocks position:fortcros)"<<std::endl; | |
for (const std::pair<int, int>& a : fortcros) { | |
//std::cout<<"("<<a.first<<","<<a.second<<")"<<std::endl; | |
} | |
if(fortcros.size() == 0){ | |
int tempx = _q_x; | |
int tempy = _q_y; | |
while(tempy>1 && tempx<tablesize){ | |
score++; | |
tempx++; | |
tempy--; | |
} | |
}else { | |
score += std::abs(fortcros.at(0).first - _q_y)-1; | |
} | |
std::cout<< score <<std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment