알고리즘 공부
백준 스위치 켜고 끄기
컴퓨터과학
2023. 8. 1. 23:54
https://www.acmicpc.net/problem/1244
1244번: 스위치 켜고 끄기
첫째 줄에는 스위치 개수가 주어진다. 스위치 개수는 100 이하인 양의 정수이다. 둘째 줄에는 각 스위치의 상태가 주어진다. 켜져 있으면 1, 꺼져있으면 0이라고 표시하고 사이에 빈칸이 하나씩
www.acmicpc.net
아 ㅋㅋ 출력문 방법이 조금 특이하네요 ㅎ
#include <iostream>
#include <vector>
#include <queue>
#include<string>
#include<algorithm>
#include<cmath>
#include<unordered_map>
#include<map>
#include<stack>
using namespace std;
struct Point {
int i, j, t, cnt, power;
char c;
};
void Prints(vector<vector<int>>maps, int n, int m) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << maps[i][j] << " ";
}
cout << endl;
}
cout << endl;
}
void Prints(vector<vector<bool>>maps, int n, int m) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << maps[i][j] << " ";
}
cout << endl;
}
cout << endl;
}
void Prints(vector<vector<char>>maps, int n, int m) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << maps[i][j];
}
cout << endl;
}
cout << endl;
}
void Prints(vector<vector<vector<char>>>maps, int n, int m, int k) {
for (int t = 0; t < k; t++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << maps[t][i][j];
}
cout << endl;
}
cout << endl;
}
cout << endl;
}
void Prints(vector<vector<vector<bool>>>maps, int n, int m, int k) {
for (int t = 0; t < k; t++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << maps[t][i][j];
}
cout << endl;
}
cout << endl;
}
cout << endl;
}
void Prints(vector<int>line, int n) {
for (int i = 0; i < n; i++) {
cout << line[i] << ",";
}
cout << endl;
}
void Prints(string str, int n) {
for (int i = 0; i < n; i++) {
cout << str[i] << ",";
}
cout << endl;
}
bool cmp(const pair<int, int>& a, const pair<int, int>& b) {
return a.second < b.second;
}
struct Data {
int nw;
int num;
};
int main() {
int n;
cin >> n;
vector<int>lists;
lists.push_back(-1);
for (int i = 0; i < n; i++) {
int tmp;
cin >> tmp;
lists.push_back(tmp);
}
int s;
cin >> s;
vector<Data>d;
for (int i = 0; i < s; i++) {
int tmpMW,tmpNum;
cin >> tmpMW;
cin >> tmpNum;
Data tmpD;
tmpD.nw = tmpMW;
tmpD.num = tmpNum;
d.push_back(tmpD);
}
for (int t = 0; t < d.size(); t++) {
if (d[t].nw==1) {
int tmp = d[t].num;
//tmp의 배수를 구하기
//n 의 tmp의 배수 나열
for (int i = 1; i < n+1; i++) {
if (i % tmp == 0) {
if (lists[i] == 0) {
lists[i] = 1;
}
else {
lists[i] = 0;
}
}
}
}
else if (d[t].nw == 2) {
int tmp2 = d[t].num;
int pre = tmp2 - 1;
int post = tmp2 + 1;
bool bCheck = false;
while (pre >= 0 && post < n+1) {
if (lists[pre] == lists[post]) {
bCheck = true;
if (lists[pre] == 0) {
lists[pre] = 1;
}
else if (lists[pre] == 1) {
lists[pre] = 0;
}
if (lists[post] == 0) {
lists[post] = 1;
}
else if (lists[post] == 1) {
lists[post] = 0;
}
}
else {
break;
}
pre = pre - 1;
post = post + 1;
}
if (lists[d[t].num] == 0) {
lists[d[t].num] = 1;
}
else if (lists[d[t].num] == 1) {
lists[d[t].num] = 0;
}
}
}
for (int i = 1; i < n+1; i++) {
cout << lists[i] << " ";
if (i%20==0) {
cout << '\n';
}
}
return 0;
}