-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodeforces_petrandcombo.cpp
More file actions
173 lines (142 loc) · 3.5 KB
/
codeforces_petrandcombo.cpp
File metadata and controls
173 lines (142 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include <bits/stdc++.h>
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
//input.txt
freopen("input1.txt", "r", stdin);
//output.txt
freopen("output1.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
// int t;
// cin >> t;
// while (t--) {
// int n;
// cin >> n;
// int a[n];
// for (int i = 0; i < n; i++) {
// cin >> a[i];
// }
// int XORR = 0;
// for (int i = 0; i < n; i++) {
// XORR = XORR ^ a[i];
// }
// cout << XORR;
// }
// swap without using third variable
// a = a ^ b;
// b = a ^ b;
// a = a ^ b;
// cout << a << " " << b << endl;
// given N print XOR if the number is between (1 - N)
// int n;
// cin >> n;
// int XORR = 0;
// for (int i = 1; i <= n; i++) {
// XORR = XORR ^ i;
// }
// cout << XORR << '\n';
/*The above code will give O(N)*/
//better solution ----> with tc of O(1)
// int n;
// cin >> n;
// if (n % 4 == 0) {
// cout << n << '\n';
// }
// if (n % 4 == 1) {
// cout << 1 << '\n';
// }
// if (n % 4 == 2) {
// cout << n + 1 << '\n';
// }
// if (n % 4 == 3) {
// cout << 0 << '\n';
// }
// given a range (L - R) , print the XOR.
// int n;
// cin >> n;
// vector<int> a(n);
// int l, r;
// cin >> l >> r;
// for (int i = 0; i < n; i++) {
// cin >> a[i];
// }
// int XORR = 0;
// for (int i = l; i <= r; i++) {
// XORR = XORR ^ a[i];
// }
// cout << XORR << '\n';
// return 0;
// check if the ith bit is set or not
// we will be using mask --> mask = (1 << i) , bool set = (mask & n)
// int n;
// cin >> n;
// int i ;
// cin >> i;
// bool bitSet = ((n >> i) & 1) != 0;
// if (bitSet) {
// cout << "The " << i << "-th bit is set (1)." << endl;
// } else {
// cout << "The " << i << "-th bit is not set (0)." << endl;
// }
// return 0;
/*------------------Day 2 Bit Manipulation------------------*/
// N int -> every integer twice and two integer appears onces..print that two int.
// below code will have tc -> O(n2)
// int n;
// cin >> n;
// int a[n];
// for (int i = 0; i < n; i++) {
// cin >> a[i];
// }
// for (int i = 0; i < n; i++) {
// int cnt = 0;
// for (int j = 0; j < n; j++) {
// if (a[i] == a[j]) cnt++;
// }
// if (cnt == 1)
// cout << a[i] << '\n';
// }
// this will go tc -> O(nlogn) as map tc is O(logn)
// int n;
// cin >> n;
// int a[n];
// for (int i = 0; i < n; i++) {
// cin >> a[i];
// }
// map<int, int> mpp;
// for (int i = 0; i < n; i++) {
// mpp[a[i]]++; // fill data in the map
// }
// // iterate in the map
// for (auto it : mpp) {
// if (it.second == 1)
// cout << it.first; // print the key
// }
int n;
cin >> n;
int sum = 0;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
// Loop to iterate through all possible subsets of a
for (int i = 0; i < (1 << n); i++) {
sum = 0;
for (int j = 0; j < n; j++) {
if ((i >> j) & 1) { // Check if the j-th element is included in the subset
sum += a[j];
} else {
sum -= a[j];
}
}
if (sum % 360 == 0) {
cout << "Yes" << endl;
return 0; // Exit the program as we found a valid subset
}
}
// If no subset was found
cout << "No" << endl;
return 0;
}