前提・実現したいこと
こちらの問題を解いていたのですが、問題とあまり関係ない点で質問があります。該当箇所(ソースコード参照)の加算がうまく行われずに困っています。どなたか解決策を教えていただきたいです。よろしくお願いいたします。
該当のソースコード
C++
1#include <bits/stdc++.h> 2#define REP(i, n) for(int i = 0; i < n; i++) 3#define REPR(i, n) for(int i = n; i >= 0; i--) 4#define FOR(i, m, n) for(int i = m; i < n; i++) 5#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i) 6#define ALL(v) v.begin(), v.end() 7using namespace std; 8typedef long long LL; 9typedef vector<int> VI; 10typedef vector<LL> VLL; 11typedef vector<vector<int> > VVI; 12typedef vector<string> VS; 13typedef pair<int, int> PII; 14const LL MOD=1000000007ll; 15const LL INF=2000000000ll; 16 17int main(){ 18 int n, m, max_x = -1*INF, max_y = -1*INF, min_x = INF, min_y = INF; 19 cin >> m; 20 set<PII> a; 21 vector<PII> e(4); 22 PII temp; 23 REP(i,m) { 24 cin >> temp.first >> temp.second; 25 a.insert(temp); 26 if (temp.first > max_x) { 27 max_x = temp.first; 28 e[0] = temp; 29 } 30 if (temp.second > max_y) { 31 max_y = temp.second; 32 e[1] = temp; 33 } 34 if (temp.first < min_x) { 35 min_x = temp.first; 36 e[2] = temp; 37 } 38 if (temp.second < min_y) { 39 min_y = temp.second; 40 e[3] = temp; 41 } 42 } 43 PII dx = make_pair(e[0].first-e[2].first, e[0].second-e[2].second); 44 PII dy = make_pair(e[1].first-e[3].first, e[1].second-e[3].second); 45 46 cin >> n; 47 set<PII> b; 48 REP(i,n){ 49 cin >> temp.first >> temp.second; 50 b.insert(temp); 51 } 52 53 int chk = 1; 54 PII d; 55 56//該当箇所 57 for (auto itr1 : b){ 58 temp = make_pair(itr1.first+dx.first, itr1.second+dx.second); 59 if (b.find(temp) != b.end()){ 60 cout << "YES" << endl; 61 d = make_pair(itr1.first-e[2].first, itr1.second-e[2].second); 62 cout << d.first << " " << d.second << endl; //a 63 chk = 1; 64 for (auto itr2 : a){ 65 cout << itr2.first << " " << itr2.second << endl; //b 66 cout << itr2.first+d.first << " " << itr2.first+d.second << endl; //a+bの値にならない 67 temp = make_pair(itr2.first+d.first, itr2.first+d.second); 68 cout << temp.first << " " << temp.second << endl; 69 if (b.find(temp) == b.end()){ //加算がうまく行われればif文がtrueになることはない 70 chk = 0; 71 break; 72 } 73 } 74 if (chk) break; 75 } 76 } 77 78 cout << d.first << " " << d.second << endl; 79}
標準入力
5 8 5 6 4 4 3 7 10 0 10 10 10 5 2 7 9 7 8 10 10 2 1 2 8 1 6 7 6 0 0 9
標準出力
YES 2 -3 //a 0 10 //b 2 -3 //a+bにならない 2 -3 2 -3
試したこと
coutしてどの点から計算が違っているか確認しました。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/03/03 05:29