質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
C++11

C++11は2011年に容認されたC++のISO標準です。以前のC++03に代わるもので、中枢の言語の変更・修正、標準ライブラリの拡張・改善を加えたものです。

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

Q&A

解決済

1回答

1207閲覧

イテレータについての初歩的な質問

Magolors

総合スコア21

C++11

C++11は2011年に容認されたC++のISO標準です。以前のC++03に代わるもので、中枢の言語の変更・修正、標準ライブラリの拡張・改善を加えたものです。

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

0グッド

0クリップ

投稿2020/03/03 05:16

前提・実現したいこと

こちらの問題を解いていたのですが、問題とあまり関係ない点で質問があります。該当箇所(ソースコード参照)の加算がうまく行われずに困っています。どなたか解決策を教えていただきたいです。よろしくお願いいたします。

該当のソースコード

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してどの点から計算が違っているか確認しました。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

>> itr2.first+d.second

あなたが意図しているのは、itr2.second+d.second ではありませんか?

投稿2020/03/03 05:27

izmktr

総合スコア2856

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Magolors

2020/03/03 05:29

ありがとうございます。本当に初歩的なミスで申し訳ありませんでした。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問