Initial Commit
This commit is contained in:
73
.idea/misc.xml
generated
Normal file
73
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="MarkdownProjectSettings">
|
||||
<PreviewSettings splitEditorLayout="SPLIT" splitEditorPreview="PREVIEW" useGrayscaleRendering="false" zoomFactor="2.0" maxImageWidth="0" showGitHubPageIfSynced="false" allowBrowsingInPreview="false" synchronizePreviewPosition="true" highlightPreviewType="NONE" highlightFadeOut="5" highlightOnTyping="true" synchronizeSourcePosition="true" verticallyAlignSourceAndPreviewSyncPosition="true" showSearchHighlightsInPreview="false" showSelectionInPreview="true" openRemoteLinks="true">
|
||||
<PanelProvider>
|
||||
<provider providerId="com.vladsch.idea.multimarkdown.editor.swing.html.panel" providerName="Default - Swing" />
|
||||
</PanelProvider>
|
||||
</PreviewSettings>
|
||||
<ParserSettings gitHubSyntaxChange="false">
|
||||
<PegdownExtensions>
|
||||
<option name="ABBREVIATIONS" value="false" />
|
||||
<option name="ANCHORLINKS" value="true" />
|
||||
<option name="ASIDE" value="false" />
|
||||
<option name="ATXHEADERSPACE" value="true" />
|
||||
<option name="AUTOLINKS" value="true" />
|
||||
<option name="DEFINITIONS" value="false" />
|
||||
<option name="DEFINITION_BREAK_DOUBLE_BLANK_LINE" value="false" />
|
||||
<option name="FENCED_CODE_BLOCKS" value="true" />
|
||||
<option name="FOOTNOTES" value="false" />
|
||||
<option name="HARDWRAPS" value="false" />
|
||||
<option name="HTML_DEEP_PARSER" value="false" />
|
||||
<option name="INSERTED" value="false" />
|
||||
<option name="QUOTES" value="false" />
|
||||
<option name="RELAXEDHRULES" value="true" />
|
||||
<option name="SMARTS" value="false" />
|
||||
<option name="STRIKETHROUGH" value="true" />
|
||||
<option name="SUBSCRIPT" value="false" />
|
||||
<option name="SUPERSCRIPT" value="false" />
|
||||
<option name="SUPPRESS_HTML_BLOCKS" value="false" />
|
||||
<option name="SUPPRESS_INLINE_HTML" value="false" />
|
||||
<option name="TABLES" value="true" />
|
||||
<option name="TASKLISTITEMS" value="true" />
|
||||
<option name="TOC" value="false" />
|
||||
<option name="WIKILINKS" value="true" />
|
||||
</PegdownExtensions>
|
||||
<ParserOptions>
|
||||
<option name="COMMONMARK_LISTS" value="true" />
|
||||
<option name="DUMMY" value="false" />
|
||||
<option name="EMOJI_SHORTCUTS" value="true" />
|
||||
<option name="FLEXMARK_FRONT_MATTER" value="false" />
|
||||
<option name="GFM_LOOSE_BLANK_LINE_AFTER_ITEM_PARA" value="false" />
|
||||
<option name="GFM_TABLE_RENDERING" value="true" />
|
||||
<option name="GITBOOK_URL_ENCODING" value="false" />
|
||||
<option name="GITHUB_EMOJI_URL" value="false" />
|
||||
<option name="GITHUB_LISTS" value="false" />
|
||||
<option name="GITHUB_WIKI_LINKS" value="true" />
|
||||
<option name="JEKYLL_FRONT_MATTER" value="false" />
|
||||
<option name="SIM_TOC_BLANK_LINE_SPACER" value="true" />
|
||||
</ParserOptions>
|
||||
</ParserSettings>
|
||||
<HtmlSettings headerTopEnabled="false" headerBottomEnabled="false" bodyTopEnabled="false" bodyBottomEnabled="false" embedUrlContent="false" addPageHeader="true" embedImages="false" embedHttpImages="false">
|
||||
<GeneratorProvider>
|
||||
<provider providerId="com.vladsch.idea.multimarkdown.editor.swing.html.generator" providerName="Default Swing HTML Generator" />
|
||||
</GeneratorProvider>
|
||||
<headerTop />
|
||||
<headerBottom />
|
||||
<bodyTop />
|
||||
<bodyBottom />
|
||||
</HtmlSettings>
|
||||
<CssSettings previewScheme="UI_SCHEME" cssUri="" isCssUriEnabled="false" isCssTextEnabled="false" isDynamicPageWidth="true">
|
||||
<StylesheetProvider>
|
||||
<provider providerId="com.vladsch.idea.multimarkdown.editor.swing.html.css" providerName="Default Swing Stylesheet" />
|
||||
</StylesheetProvider>
|
||||
<ScriptProviders />
|
||||
<cssText />
|
||||
</CssSettings>
|
||||
<HtmlExportSettings updateOnSave="false" parentDir="$ProjectFileDir$" targetDir="$ProjectFileDir$" cssDir="" scriptDir="" plainHtml="false" imageDir="" copyLinkedImages="false" imageUniquifyType="0" targetExt="" useTargetExt="false" noCssNoScripts="false" linkToExportedHtml="true" exportOnSettingsChange="true" regenerateOnProjectOpen="false" linkFormatType="HTTP_ABSOLUTE" />
|
||||
<LinkMapSettings>
|
||||
<textMaps />
|
||||
</LinkMapSettings>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6 (naipc)" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/naipc.iml" filepath="$PROJECT_DIR$/.idea/naipc.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
13
.idea/naipc.iml
generated
Normal file
13
.idea/naipc.iml
generated
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="TestRunnerService">
|
||||
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
|
||||
</component>
|
||||
</module>
|
||||
8
facts.py
Normal file
8
facts.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import json
|
||||
|
||||
MOD = 10 ** 9 + 7
|
||||
lst = [1]
|
||||
for x in range(1, 100_000):
|
||||
lst.append((lst[-1] * x) % MOD)
|
||||
with open('mod.json','w') as f:
|
||||
json.dump(lst, f)
|
||||
19
genwords.py
Normal file
19
genwords.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import random
|
||||
from itertools import *
|
||||
from math import factorial
|
||||
|
||||
alph = 'pyfgcrlaoeuidhtnsqjkxbmwvz'
|
||||
|
||||
L = 200
|
||||
K = 5
|
||||
|
||||
combos = [''.join(x) for x in combinations(alph, r=K)]
|
||||
|
||||
with open('test/prefix/mytest.in', 'w') as f:
|
||||
f.write(f'{len(combos)} {K}\n')
|
||||
for w in combos:
|
||||
f.write(w)
|
||||
f.write('\n')
|
||||
|
||||
# f.write(''.join(random.choice(combos) for _ in range(10)))
|
||||
f.write(''.join(combos[:4]))
|
||||
26
gnomes.py
Normal file
26
gnomes.py
Normal file
@@ -0,0 +1,26 @@
|
||||
n, m = map(int, input().split())
|
||||
|
||||
dat = [int(input()) for _ in range(m)]
|
||||
|
||||
sdat = set(dat)
|
||||
missing = [x for x in range(1, n + 1) if x not in sdat]
|
||||
|
||||
res = []
|
||||
i = 0
|
||||
j = 0
|
||||
while i < len(dat) and j < len(missing):
|
||||
if dat[i] < missing[j]:
|
||||
res.append(dat[i])
|
||||
i += 1
|
||||
else:
|
||||
res.append(missing[j])
|
||||
j += 1
|
||||
while i < len(dat):
|
||||
res.append(dat[i])
|
||||
i += 1
|
||||
while j < len(missing):
|
||||
res.append(missing[j])
|
||||
j += 1
|
||||
|
||||
for x in res:
|
||||
print(x)
|
||||
61
prefixfree.py
Normal file
61
prefixfree.py
Normal file
@@ -0,0 +1,61 @@
|
||||
MOD = 10 ** 9 + 7
|
||||
|
||||
|
||||
def factorials(n, c):
|
||||
l = [1]
|
||||
for x in range(c + 1, n):
|
||||
l.append((l[-1] * x) % MOD)
|
||||
return l
|
||||
|
||||
|
||||
N, K = map(int, input().split())
|
||||
|
||||
alph = []
|
||||
for _ in range(N):
|
||||
inp = input().strip()
|
||||
alph.append(inp)
|
||||
alph = sorted(alph)
|
||||
|
||||
fac = factorials(len(alph), N - K)
|
||||
|
||||
TREE = {}
|
||||
for ind, init in enumerate(alph):
|
||||
tree_ = TREE
|
||||
i = 0
|
||||
while init[i] in tree_ and isinstance(tree_[init[i]], dict):
|
||||
tree_ = tree_[init[i]]
|
||||
i += 1
|
||||
substr = init[i + 1:-1]
|
||||
subtree = {}
|
||||
if substr:
|
||||
st_ = subtree
|
||||
for c in substr:
|
||||
st_[c] = {}
|
||||
st_ = st_[c]
|
||||
st_[init[-1]] = ind
|
||||
else:
|
||||
subtree = ind
|
||||
tree_[init[i]] = subtree
|
||||
|
||||
|
||||
def get_blocks(s):
|
||||
tree_ = TREE
|
||||
for c in s:
|
||||
if isinstance(tree_, dict):
|
||||
tree_ = tree_[c]
|
||||
else:
|
||||
yield tree_
|
||||
tree_ = TREE[c]
|
||||
yield tree_
|
||||
|
||||
|
||||
inds = list(get_blocks(input().strip()))
|
||||
|
||||
index = 0
|
||||
indexes = list(range(len(alph)))
|
||||
for j, i in enumerate(inds):
|
||||
k = indexes.index(i)
|
||||
del indexes[k]
|
||||
index += (fac[K - j - 1] * k) % MOD
|
||||
|
||||
print(index + 1)
|
||||
36
probedroids.py
Normal file
36
probedroids.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import operator
|
||||
from pprint import pprint
|
||||
|
||||
n, m, q = map(int, input().split())
|
||||
|
||||
nums = {}
|
||||
for x in range(n):
|
||||
for y in range(m):
|
||||
if x == 0 and y == 0:
|
||||
continue
|
||||
s = (x / y) if y != 0 else float('inf')
|
||||
nums.setdefault(s, []).append((x, y))
|
||||
|
||||
buckets = sorted(nums)
|
||||
buckets = [nums[b] for b in buckets]
|
||||
blens = []
|
||||
blen = 0
|
||||
for b in buckets:
|
||||
blen += len(b)
|
||||
blens.append(blen)
|
||||
|
||||
|
||||
def find_bucket(i):
|
||||
x = 0
|
||||
while x < len(blens) - 1 and blens[x] <= i:
|
||||
x += 1
|
||||
|
||||
return x, i - blens[x]
|
||||
|
||||
|
||||
for _ in range(q):
|
||||
i = int(input())-1
|
||||
x, i = find_bucket(i)
|
||||
buckets[x].sort()
|
||||
a, b = buckets[x][i]
|
||||
print(a + 1, b + 1)
|
||||
66
probedroids2.py
Normal file
66
probedroids2.py
Normal file
@@ -0,0 +1,66 @@
|
||||
import operator
|
||||
from math import *
|
||||
from pprint import pprint
|
||||
|
||||
n, m, q = map(int, input().split())
|
||||
|
||||
|
||||
def f(s):
|
||||
if s == 0:
|
||||
return 0
|
||||
if s == float('inf'):
|
||||
return m * n - 1
|
||||
return m - 1 + sum(m - y // s - 1 for y in range(1, n + 1))
|
||||
|
||||
|
||||
def g(s1, s2):
|
||||
print(f"g({s1},{s2})")
|
||||
lst = []
|
||||
if s2 == float('inf'):
|
||||
for x in range(0, m):
|
||||
for y in range(int(ceil(x * s1)), n):
|
||||
if (x, y) != (0,0):
|
||||
lst.append((x, y))
|
||||
else:
|
||||
for x in range(0, m):
|
||||
for y in range(int(ceil(x * s1)), int(floor(x * s2) + 1)):
|
||||
if (x, y) != (0,0):
|
||||
lst.append((x, y))
|
||||
|
||||
|
||||
return lst
|
||||
|
||||
|
||||
def search(i, bound):
|
||||
lowerS = 0
|
||||
lowerC = 0
|
||||
upperS = float('inf')
|
||||
upperC = m * n - 1
|
||||
|
||||
while (upperC - lowerC > bound):
|
||||
tempS = (lowerS + upperS) / 2
|
||||
tempC = f(tempS)
|
||||
|
||||
if (tempC > i):
|
||||
upperC = tempC
|
||||
upperS = tempS
|
||||
else:
|
||||
lowerC = tempC
|
||||
lowerS = tempS
|
||||
|
||||
return g(lowerS, upperS), lowerC
|
||||
|
||||
|
||||
def get(i):
|
||||
print('case i=', i)
|
||||
pts, lowc = search(i, 1000)
|
||||
pts = sorted(((y / x if x != 0 else float('inf')), x, y) for x, y in pts)
|
||||
print(i, lowc)
|
||||
pprint(pts)
|
||||
_, x, y = pts[i - lowc]
|
||||
return y + 1, x + 1
|
||||
|
||||
|
||||
for _ in range(q):
|
||||
i = int(input()) - 1
|
||||
print(*get(i))
|
||||
3
readme.md
Normal file
3
readme.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# UNCC Gold NAIPC solution
|
||||
|
||||
Solution attempts by UNCC Gold team at NAIPC.
|
||||
0
test/prefix/mytest.ans
Normal file
0
test/prefix/mytest.ans
Normal file
65782
test/prefix/mytest.in
Normal file
65782
test/prefix/mytest.in
Normal file
File diff suppressed because it is too large
Load Diff
1
test/prefix/prefix-0000.ans
Normal file
1
test/prefix/prefix-0000.ans
Normal file
@@ -0,0 +1 @@
|
||||
26
|
||||
7
test/prefix/prefix-0000.in
Normal file
7
test/prefix/prefix-0000.in
Normal file
@@ -0,0 +1,7 @@
|
||||
5 3
|
||||
a
|
||||
b
|
||||
c
|
||||
d
|
||||
e
|
||||
cad
|
||||
1
test/prefix/prefix-0001.ans
Normal file
1
test/prefix/prefix-0001.ans
Normal file
@@ -0,0 +1 @@
|
||||
12451
|
||||
10
test/prefix/prefix-0001.in
Normal file
10
test/prefix/prefix-0001.in
Normal file
@@ -0,0 +1,10 @@
|
||||
8 8
|
||||
font
|
||||
lewin
|
||||
darko
|
||||
deon
|
||||
vanb
|
||||
johnb
|
||||
chuckr
|
||||
tgr
|
||||
deonjohnbdarkotgrvanbchuckrfontlewin
|
||||
1
test/probedroids/mytest.ans--
Normal file
1
test/probedroids/mytest.ans--
Normal file
@@ -0,0 +1 @@
|
||||
like 20 or something
|
||||
2
test/probedroids/mytest.in--
Normal file
2
test/probedroids/mytest.in--
Normal file
@@ -0,0 +1,2 @@
|
||||
1000000 1000000 1
|
||||
47
|
||||
3
test/probedroids/probedroids-0000.ans
Normal file
3
test/probedroids/probedroids-0000.ans
Normal file
@@ -0,0 +1,3 @@
|
||||
1 2
|
||||
3 1
|
||||
3 5
|
||||
4
test/probedroids/probedroids-0000.in
Normal file
4
test/probedroids/probedroids-0000.in
Normal file
@@ -0,0 +1,4 @@
|
||||
3 5 3
|
||||
1
|
||||
14
|
||||
8
|
||||
2
test/zoninghouses/zoninghouses-0000.ans
Normal file
2
test/zoninghouses/zoninghouses-0000.ans
Normal file
@@ -0,0 +1,2 @@
|
||||
1
|
||||
0
|
||||
6
test/zoninghouses/zoninghouses-0000.in
Normal file
6
test/zoninghouses/zoninghouses-0000.in
Normal file
@@ -0,0 +1,6 @@
|
||||
3 2
|
||||
1 0
|
||||
0 1
|
||||
1000 1
|
||||
1 3
|
||||
2 3
|
||||
2
test/zoninghouses/zoninghouses-0001.ans
Normal file
2
test/zoninghouses/zoninghouses-0001.ans
Normal file
@@ -0,0 +1,2 @@
|
||||
300
|
||||
299
|
||||
7
test/zoninghouses/zoninghouses-0001.in
Normal file
7
test/zoninghouses/zoninghouses-0001.in
Normal file
@@ -0,0 +1,7 @@
|
||||
4 2
|
||||
0 0
|
||||
1000 1000
|
||||
300 300
|
||||
1 1
|
||||
1 3
|
||||
2 4
|
||||
25
testing.py
Normal file
25
testing.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import glob, sys, subprocess
|
||||
|
||||
_, src, test, t = sys.argv
|
||||
|
||||
ig = glob.glob(f'test/{test}/*.in')
|
||||
og = glob.glob(f'test/{test}/*.ans')
|
||||
|
||||
print(test, len(ig), 'tests')
|
||||
|
||||
for ifn, ofn in zip(ig, og):
|
||||
with open(ifn) as fi, open(ofn) as fx:
|
||||
try:
|
||||
o = subprocess.check_output(['python', src],
|
||||
stdin=fi, stderr=subprocess.STDOUT,
|
||||
timeout=float(t))
|
||||
except subprocess.CalledProcessError as e:
|
||||
o = e.output
|
||||
except subprocess.TimeoutExpired:
|
||||
o = b'TIMED OUT'
|
||||
|
||||
o = o.decode().strip().replace('\r\n', '\n')
|
||||
x = fx.read().strip().replace('\r\n', '\n')
|
||||
|
||||
if o != x:
|
||||
print(ifn, 'expected:', x, 'got:', o, '=' * 50, sep='\n')
|
||||
103
zoninghouses.py
Normal file
103
zoninghouses.py
Normal file
@@ -0,0 +1,103 @@
|
||||
n, q = map(int, input().split())
|
||||
|
||||
coords = []
|
||||
for _ in range(n):
|
||||
x, y = map(int, input().split())
|
||||
coords.append((x, y))
|
||||
|
||||
zone = []
|
||||
for _ in range(q):
|
||||
a, b = map(int, input().split())
|
||||
zone.append((a, b))
|
||||
|
||||
|
||||
def f(a, b, lst):
|
||||
if b - a <= 1:
|
||||
return 0
|
||||
|
||||
# minimum of the first 3
|
||||
aXmin = min(lst[a][0], lst[a+1][0])
|
||||
aXmax = max(lst[a][0], lst[a+1][0])
|
||||
aYmin = min(lst[a][1], lst[a+1][1])
|
||||
aYmax = max(lst[a][1], lst[a+1][1])
|
||||
aLen = max(abs(aXmax-aXmin), abs(aYmax-aYmin))
|
||||
|
||||
bXmin = min(lst[a + 2][0], lst[a + 1][0])
|
||||
bXmax = max(lst[a + 2][0], lst[a + 1][0])
|
||||
bYmin = min(lst[a + 2][1], lst[a + 1][1])
|
||||
bYmax = max(lst[a + 2][1], lst[a + 1][1])
|
||||
bLen = max(abs(bXmax - bXmin), abs(bYmax - bYmin))
|
||||
|
||||
cXmin = min(lst[a][0], lst[a + 2][0])
|
||||
cXmax = max(lst[a][0], lst[a + 2][0])
|
||||
cYmin = min(lst[a][1], lst[a + 2][1])
|
||||
cYmax = max(lst[a][1], lst[a + 2][1])
|
||||
cLen = max(abs(cXmax - cXmin), abs(cYmax - cYmin))
|
||||
|
||||
if(aLen < bLen):
|
||||
if(aLen < cLen):
|
||||
osXmin = aXmin
|
||||
osXmax = aXmax
|
||||
osYmin = aYmin
|
||||
osYmax = aYmax
|
||||
osLen = aLen
|
||||
else:
|
||||
osXmin = cXmin
|
||||
osXmax = cXmax
|
||||
osYmin = cYmin
|
||||
osYmax = cYmax
|
||||
osLen = cLen
|
||||
else:
|
||||
if (bLen < cLen):
|
||||
osXmin = bXmin
|
||||
osXmax = bXmax
|
||||
osYmin = bYmin
|
||||
osYmax = bYmax
|
||||
osLen = bLen
|
||||
else:
|
||||
osXmin = cXmin
|
||||
osXmax = cXmax
|
||||
osYmin = cYmin
|
||||
osYmax = cYmax
|
||||
osLen = cLen
|
||||
|
||||
nsLen = osLen
|
||||
allXmin = min(aXmin, lst[a+2][0])
|
||||
allXmax = max(aXmax, lst[a+2][0])
|
||||
allYmin = min(aYmin, lst[a+2][1])
|
||||
allYmax = max(aYmax, lst[a+2][1])
|
||||
allLen = max(abs(allXmax-allXmin), abs(allYmax-allYmin))
|
||||
# print(f"nsLen={nsLen}, osLen={osLen}, allLen={allLen}")
|
||||
|
||||
for i in lst[a + 3:b + 1]:
|
||||
osXmin = min(osXmin, i[0])
|
||||
osXmax = max(osXmax, i[0])
|
||||
osYmin = min(osYmin, i[1])
|
||||
osYmax = max(osYmax, i[1])
|
||||
osLen = max(abs(osXmax - osXmin), abs(osYmax - osYmin))
|
||||
|
||||
nsXmin = allXmin
|
||||
nsXmax = allXmax
|
||||
nsYmin = allYmin
|
||||
nsYmax = allYmax
|
||||
nsLen = allLen
|
||||
# print(f"nsLen={nsLen}, osLen={osLen}, allLen={allLen}")
|
||||
|
||||
allXmin = min(allXmin, i[0])
|
||||
allXmax = max(allXmax, i[0])
|
||||
allYmin = min(allYmin, i[0])
|
||||
allYmax = max(allYmax, i[0])
|
||||
allLen = max(abs(allXmax - allXmin), abs(allYmax - allYmin))
|
||||
|
||||
# print(f"nsLen={nsLen}, osLen={osLen}, allLen={allLen}")
|
||||
if (nsLen < osLen):
|
||||
osXmin = nsXmin
|
||||
osXmax = nsXmax
|
||||
osYmin = nsYmin
|
||||
osYmax = nsYmax
|
||||
|
||||
return nsLen
|
||||
|
||||
|
||||
for a, b in zone:
|
||||
print(f(a-1, b-1, coords))
|
||||
Reference in New Issue
Block a user