Skip to content

Commit 0f4eea7

Browse files
committed
[#5] Add AtCoder Beginner Contest 180 codes
1 parent d36130e commit 0f4eea7

File tree

5 files changed

+186
-0
lines changed

5 files changed

+186
-0
lines changed

ABC_180_A.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <map>
4+
#include <vector>
5+
#include <algorithm>
6+
using namespace std;
7+
8+
int main() {
9+
int n, a, b;
10+
cin >> n >> a >> b;
11+
12+
cout << n - a + b << endl;
13+
}

ABC_180_B.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <map>
4+
#include <vector>
5+
#include <iomanip>
6+
#include <algorithm>
7+
#include <cmath>
8+
using namespace std;
9+
10+
int main() {
11+
int n;
12+
long double a = 0, b = 0, c = 0;
13+
14+
cin >> n;
15+
16+
while (n--)
17+
{
18+
long double x;
19+
cin >> x;
20+
21+
a += abs(x);
22+
b += x * x;
23+
c = max(c, abs(x));
24+
}
25+
26+
cout << setprecision(12) << a << '\n' << sqrt(b) << '\n' << c << endl;
27+
}

ABC_180_C.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <map>
4+
#include <vector>
5+
#include <algorithm>
6+
using namespace std;
7+
8+
int main() {
9+
long long n;
10+
vector<long long > d;
11+
12+
cin >> n;
13+
14+
for (long long i = 1; i * i <= n; i++)
15+
{
16+
if (n % i == 0)
17+
{
18+
if (i == n / i)
19+
{
20+
d.push_back(i);
21+
22+
}
23+
else
24+
{
25+
d.push_back(i);
26+
d.push_back(n / i);
27+
28+
}
29+
}
30+
}
31+
32+
sort(d.begin(), d.end());
33+
34+
for (int i = 0; i < d.size(); i++)
35+
{
36+
cout << d[i] << endl;
37+
}
38+
}

ABC_180_D.cpp

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
#include <climits>
4+
#include <queue>
5+
using namespace std;
6+
7+
int main()
8+
{
9+
unsigned long long x, y, a, b;
10+
unsigned long long ans = 0;
11+
12+
cin >> x >> y >> a >> b;
13+
14+
queue< pair<unsigned long long, unsigned long long> >que;
15+
16+
que.push(make_pair(x, 0));
17+
18+
while (!que.empty())
19+
{
20+
unsigned long long str = que.front().first;
21+
unsigned long long exp = que.front().second;
22+
que.pop();
23+
24+
//cout << str << ' ' << exp << endl;
25+
26+
if (str >= y)
27+
{
28+
continue;
29+
}
30+
31+
ans = max(ans, exp);
32+
33+
// overflow
34+
if (!(ULLONG_MAX / a < str))
35+
{
36+
// multiple
37+
que.push(make_pair(str * a, exp + 1));
38+
}
39+
40+
// add....
41+
unsigned long long c = (y - str) / b;
42+
if (c == 0)
43+
{
44+
que.push(make_pair(str + b, exp + 1));
45+
}
46+
else if ((y - str) % b == 0 && c > 1) {
47+
c--;
48+
que.push(make_pair(str + b * c, exp + c));
49+
}
50+
else
51+
{
52+
que.push(make_pair(str + b * c, exp + c));
53+
}
54+
}
55+
56+
cout << ans << endl;
57+
}

ABC_180_E.cpp

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// source code based on https://www.acmicpc.net/problem/2098
2+
3+
#include <iostream>
4+
#include <algorithm>
5+
#include <cmath>
6+
using namespace std;
7+
8+
int dp[17][1 << 18];
9+
int N;
10+
int x[17];
11+
int y[17];
12+
int z[17];
13+
14+
int TSP(int start, int path)
15+
{
16+
if (dp[start][path] != 0)
17+
{
18+
return dp[start][path];
19+
}
20+
21+
if (path == 0)
22+
{
23+
return abs(x[start] - x[0]) + abs(y[start] - y[0]) + max(0, z[0] - z[start]);
24+
}
25+
26+
int ret = 987654321;
27+
28+
for (int i = 0; i < N; ++i)
29+
{
30+
if (((1 << i) & path) == 0 || (path ^ (1 << i)) == path)
31+
{
32+
continue;
33+
}
34+
35+
ret = min(ret, TSP(i, path ^ (1 << i)) + abs(x[start] - x[i]) + abs(y[start] - y[i]) + max(0, z[i] - z[start]));
36+
}
37+
38+
return dp[start][path] = ret;
39+
}
40+
41+
int main()
42+
{
43+
cin >> N;
44+
45+
for (int i = 0; i < N; ++i)
46+
{
47+
cin >> x[i] >> y[i] >> z[i];
48+
}
49+
50+
cout << TSP(0, (1 << N) - 2) << endl;
51+
}

0 commit comments

Comments
 (0)