Nutcha0751 / filemix

0 stars 0 forks source link

Problem15 #10

Open Nutcha0751 opened 8 months ago

Nutcha0751 commented 8 months ago

[Challenge Problem Set 15.3]

image

include

include

include

using namespace std;

int main(){ int N, M; cin >> M >> N; int* V = new int[N + M -1]; V[0] = 1; for(int i = 1; i < M + N - 1; i++){ if(i < max(N, M)) V[i] = V[i - 1] + min(i + 1, min(N, M)); else V[i] = V[i - 1] + min(N, M) - (i - max(N, M) + 1); if(i % 2 == 0) V[i-1] = V[i - 2] + 1; } for(int i = 0; i < M; i++){ for(int j = 0; j < N; j ++){ if((i+j) % 2) cout<< setw(8) << V[i + j]++; else cout<< setw(8) << V[i + j]-- ; } cout << "\n"; } delete [] V; }

[Challenge Problem Set 15.4]

image

include

include

using namespace std; map<int, int> stars;

int main() { int A, B; int i = 1; int group = 1; int count = 0; cout << "Input link [" << i++ << "]: "; cin >> A >> B; while (A > 0 && B > 0) { if (stars[A] && stars[B]) { if (stars[A] != stars[B]) { int mergeToGroup = min(stars[A], stars[B]); int mergeGroup = max(stars[A], stars[B]); for (auto &star : stars) { if (star.second == mergeGroup) { star.second = mergeToGroup; } } count--; } } else if (stars[A] || stars[B]) { int toGroup = max(stars[A], stars[B]); stars[A] = toGroup; stars[B] = toGroup; } else { stars[A] = group; stars[B] = group; group++; count++; } cout << "Input link [" << i++ << "]: "; cin >> A >> B; }

cout << "#Constellation = " << count;

}