Skip to content

Commit ec7f723

Browse files
committed
add 1101-1104, 1106-1110
1 parent ce2f187 commit ec7f723

10 files changed

+223
-1
lines changed

.vscode/build.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@echo off
22
pushd %cd%
3-
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
3+
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
44
popd
55
echo %cd%
66
set compilerflags=/Od /EHsc /Zi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
a, d = input().split()
2+
d = int(d)
3+
b = int(a[-d:] + a[:-d])
4+
print("%.2f" % (b/int(a)))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
n = int(input())
2+
tot = [0, 0]
3+
ans = [None, None]
4+
for i in range(n):
5+
id, price, count = input().split()
6+
price, count = int(price), int(count)
7+
if count >= tot[0]:
8+
tot[0] = count
9+
ans[0] = id
10+
11+
if count * price >= tot[1]:
12+
tot[1] = count * price
13+
ans[1] = id
14+
15+
print("%s %d" % (ans[0], tot[0]))
16+
print("%s %d" % (ans[1], tot[1]))
17+
18+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
def is_square(x):
2+
lo, hi = 1, x
3+
while lo <= hi:
4+
mid = (lo + hi) // 2
5+
if mid * mid == x: return True
6+
elif mid * mid > x: hi = mid - 1
7+
else: lo = mid + 1
8+
return False
9+
10+
11+
m, n = map(int, input().split())
12+
13+
ans = []
14+
for a in range(m, n+1):
15+
c_2 = a*a*a - (a-1)*(a-1)*(a-1)
16+
if not is_square(c_2): continue
17+
c = int(c_2**0.5)
18+
19+
t = 2*c-1
20+
if not is_square(t): continue
21+
t_0_5 = int(t**0.5)
22+
if t_0_5 % 2 == 0: continue
23+
b = (1+t_0_5) // 2
24+
if b <= 0 or b == 1: continue # (1, 1) is not a valid result ????
25+
ans.append("%d %d" % (a, b))
26+
if not ans:
27+
print("No Solution")
28+
else:
29+
print('\n'.join(ans))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# search pruning for below conditions
2+
# 1. search set size greater than k
3+
# 2. sum of search set greater than m
4+
# 3. sum of current search set plus remaining all '9' numbers still less than m
5+
6+
def search(s, k, m, results):
7+
sum_s = sum(s)
8+
if (len(s) > k or sum_s > m or sum_s + (k - len(s)) * 9 < m): return
9+
if len(s) == k and sum_s == m:
10+
results.append(int("".join(map(str, s))))
11+
return
12+
13+
start = 1 if len(s) == 0 else 0
14+
for i in range(start, 10):
15+
s.append(i)
16+
search(s, k, m, results)
17+
s.pop(-1)
18+
19+
def gcd(a, b):
20+
if b == 0: return a
21+
else: return b if a % b == 0 else gcd(b, a%b)
22+
23+
def is_prime(n):
24+
lo = 2
25+
hi = int(n**0.5)+1
26+
for i in range(lo, hi):
27+
if n % i == 0: return False
28+
return True
29+
30+
n = int(input())
31+
for i in range(n):
32+
k, m = map(int, input().split())
33+
results = []
34+
search([], k, m, results)
35+
print("Case %d" % (i+1))
36+
ans = []
37+
is_ok = False
38+
for r in results:
39+
m1 = sum(map(int, list(str(r+1))))
40+
g = gcd(m, m1)
41+
if g > 2 and is_prime(g):
42+
is_ok = True
43+
ans.append((m1, r))
44+
45+
if not is_ok:
46+
print("No Solution")
47+
else:
48+
ans.sort(key=lambda x:(x[0], x[1]))
49+
print("\n".join(map(lambda x: "%d %d" % (x[0], x[1]), ans)))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
f = [2, 0, 1, 9]
2+
ans = ""
3+
n = int(input())
4+
for i in range(n):
5+
if i >= 4:
6+
f[i%4] = sum(f) % 10
7+
ans += str(f[i%4])
8+
print(ans)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
n, m = map(int, input().split())
2+
ans = []
3+
for i in range(n):
4+
g = map(int, input().split())
5+
ans.append(max(g))
6+
7+
print(" ".join(map(str, ans)))
8+
print(max(ans))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
s = input()
2+
count = {}
3+
for ch in s:
4+
if ch in "String":
5+
count[ch] = count.get(ch, 0) + 1
6+
7+
ans = []
8+
while sum(count.values()) != 0:
9+
for ch in "String":
10+
if count.get(ch, 0) > 0:
11+
ans += ch
12+
count[ch] -= 1
13+
14+
print("".join(ans))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import string
2+
alphabet = {}
3+
for ch in string.ascii_uppercase:
4+
alphabet[ch] = []
5+
for i in range(7):
6+
alphabet[ch].append(input())
7+
8+
word = ""
9+
words = []
10+
sentence = input()
11+
for idx, ch in enumerate(sentence):
12+
if ch in string.ascii_uppercase:
13+
word += ch
14+
else:
15+
if word:
16+
words.append(word)
17+
word = ""
18+
19+
if word:
20+
words.append(word)
21+
22+
is_first_word = True
23+
for w in words:
24+
# deal with blank line
25+
if is_first_word:
26+
is_first_word = False
27+
else:
28+
print()
29+
30+
# row scan from top to bottom
31+
# in each row, characters of word scan
32+
# record the charcacter pattern of word in current row.
33+
for i in range(7):
34+
ans = []
35+
for ch in w:
36+
ans.append(alphabet[ch][i])
37+
print(" ".join(ans))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include <cstdio>
2+
#include <string>
3+
#include <iostream>
4+
#include <unordered_map>
5+
#include <vector>
6+
using namespace std;
7+
8+
struct Node {
9+
string address;
10+
string data;
11+
string next;
12+
};
13+
14+
unordered_map<string, Node> L;
15+
16+
int main() {
17+
ios::sync_with_stdio(false);
18+
string root;
19+
int n, k;
20+
cin >> root >> n >> k;
21+
for (int i = 0; i < n; i++) {
22+
Node node;
23+
cin >> node.address >> node.data >> node.next;
24+
L[node.address] = node;
25+
}
26+
27+
vector<pair<string, string>> blocks; // record every blocks, then reverse based on this
28+
int count = 0;
29+
string p = root, begin = root, last;
30+
while (p != "-1") {
31+
count++;
32+
if (count == k) {
33+
blocks.push_back(make_pair(begin, p));
34+
begin = L[p].next;
35+
count = 0;
36+
}
37+
38+
last = p;
39+
p = L[p].next;
40+
}
41+
42+
if (begin != "-1") blocks.push_back(make_pair(begin, last));
43+
for (int i = blocks.size() - 1; i > 0; i--) {
44+
L[blocks[i].second].next = blocks[i-1].first;
45+
}
46+
L[blocks[0].second].next = "-1";
47+
48+
p = blocks[blocks.size() - 1].first;
49+
while (p != "-1"){
50+
cout << p << " " << L[p].data << " " << L[p].next << endl;
51+
p = L[p].next;
52+
}
53+
54+
return 0;
55+
}

0 commit comments

Comments
 (0)