forked from TavenDo/XCPC-Math-Finder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMath.html
More file actions
485 lines (432 loc) · 17.7 KB
/
Copy pathMath.html
File metadata and controls
485 lines (432 loc) · 17.7 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>数学题单 - XCPC-Math-Finder</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
<style>
body {
margin: 0;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f4f7f6;
color: #333;
scroll-behavior: smooth;
min-height: 100vh;
position: relative;
}
/* 自适应、居中、降低亮度的全屏背景图 */
body::before {
content: "";
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url('BG.png');
background-position: center;
background-repeat: no-repeat;
background-size: cover;
filter: brightness(0.75);
z-index: -1;
}
/* 规范顶端栏 */
header {
width: 100%;
background-color: #f39c12;
color: white;
padding: 10px 40px;
box-sizing: border-box;
display: flex;
justify-content: space-between;
align-items: center;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
position: fixed;
top: 0;
z-index: 1000;
}
.header-left { display: flex; align-items: baseline; gap: 15px; }
.header-left h1 { margin: 0; font-size: 1.8em; letter-spacing: 1px; }
.header-left .author { font-size: 1em; opacity: 0.9; }
.header-right-nav { display: flex; align-items: center; }
.back-btn {
background-color: rgba(255, 255, 255, 0.2);
color: white;
text-decoration: none;
padding: 8px 18px;
border-radius: 50px;
font-weight: bold;
transition: all 0.3s ease;
border: 1px solid rgba(255, 255, 255, 0.4);
font-size: 0.9em;
display: flex;
align-items: center;
gap: 6px;
}
.back-btn:hover {
background-color: rgba(255, 255, 255, 0.35);
transform: scale(1.05);
}
/* 顶部工具栏 (搜索框定位) */
.toolbar {
max-width: 1100px;
width: 100%;
margin: 90px auto 10px auto;
padding: 0 20px;
box-sizing: border-box;
display: flex;
justify-content: flex-start;
}
.search-box {
background-color: rgba(255, 255, 255, 0.65);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.4);
border-radius: 50px;
padding: 10px 20px;
display: flex;
align-items: center;
gap: 10px;
width: 350px;
box-shadow: 0 4px 15px rgba(0,0,0,0.05);
transition: all 0.3s ease;
}
.search-box:focus-within {
background-color: rgba(255, 255, 255, 0.85);
box-shadow: 0 6px 20px rgba(0,0,0,0.1);
transform: translateY(-2px);
}
.search-box i { color: #7f8c8d; }
.search-box input {
border: none;
background: transparent;
outline: none;
width: 100%;
font-size: 1em;
color: #2c3e50;
font-weight: 500;
}
.search-box input::placeholder { color: #95a5a6; }
/* 右侧胶囊导航 */
.floating-nav {
position: fixed;
bottom: 40px;
right: 40px;
display: flex;
flex-direction: column;
gap: 12px;
z-index: 1000;
}
.btn-jump {
background-color: rgba(52, 152, 219, 0.7);
backdrop-filter: blur(5px);
color: white;
text-decoration: none;
padding: 10px 20px;
border-radius: 50px;
font-weight: bold;
font-size: 0.9em;
box-shadow: 0 8px 20px rgba(0,0,0,0.15);
transition: all 0.3s;
text-align: center;
border: 1px solid rgba(255,255,255,0.2);
}
.btn-jump:hover {
background-color: rgba(41, 128, 185, 0.95);
transform: translateX(-5px);
}
/* 主体容器 */
.container {
max-width: 1100px;
width: 100%;
margin: 0 auto;
padding: 10px 20px 100px 20px;
box-sizing: border-box;
}
/* 大板块标题 */
.category-section { margin-bottom: 50px; }
.category-title {
color: #fff;
font-size: 2em;
margin-bottom: 20px;
text-shadow: 0 2px 4px rgba(0,0,0,0.4);
display: flex;
align-items: center;
gap: 12px;
padding-top: 20px;
}
.category-title i { color: #f39c12; }
.section-divider { border: 0; height: 3px; background: linear-gradient(to right, #f39c12, transparent); margin-bottom: 25px; }
/* 表格与毛玻璃设计 */
table {
width: 100%;
border-collapse: collapse;
background-color: rgba(255, 255, 255, 0.7);
backdrop-filter: blur(10px);
box-shadow: 0 10px 25px rgba(0,0,0,0.06);
border-radius: 12px;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.4);
}
th, td { padding: 14px 15px; text-align: left; border-bottom: 1px solid rgba(238, 238, 238, 0.5); }
th { background-color: rgba(44, 62, 80, 0.9); color: white; font-weight: 600; font-size: 0.95em; }
td { color: #2c3e50; font-weight: 500; font-size: 0.95em; transition: opacity 0.3s; }
tr:hover td { background-color: rgba(255, 255, 255, 0.5); }
/* 细分小类分组头 */
.subcat-header {
background-color: rgba(236, 240, 241, 0.85) !important;
color: #2980b9 !important;
font-weight: bold !important;
font-size: 1.05em !important;
text-align: center;
}
/* 徽章与标签 */
.badge { padding: 4px 10px; border-radius: 6px; font-size: 0.85em; font-weight: bold; color: white; display: inline-block; text-align: center; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.badge-cf { background-color: #2980b9; }
.badge-qoj { background-color: #e67e22; }
/* 难度标签 */
.diff-easy { background-color: #27ae60; }
.diff-medium { background-color: #f39c12; }
.diff-hard { background-color: #c0392b; }
a.link-btn { color: #2980b9; text-decoration: none; font-weight: bold; }
a.link-btn:hover { text-decoration: underline; color: #1f618d; }
input[type="checkbox"] { transform: scale(1.4); cursor: pointer; }
/* 已做题目的视觉置灰效果 */
tr.done-row td { opacity: 0.5; }
tr.done-row td:first-child { opacity: 1; /* 保持 checkbox 清晰可见 */ }
/* 空状态提示 */
.empty-state { text-align: center; padding: 30px; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.5); font-weight: bold; font-size: 1.1em; background: rgba(0,0,0,0.2); border-radius: 10px; }
@media (max-width: 768px) {
/* 1. 顶端导航栏:压缩边距,缩小字号 */
header {
padding: 10px 15px;
}
.header-left h1 {
font-size: 1.2em;
}
.header-left .author {
display: none; /* 手机端空间有限,隐藏副标题/作者,保持头部干净 */
}
.header-right {
font-size: 1.2em;
gap: 15px;
}
.back-btn {
padding: 6px 12px;
font-size: 0.8em;
}
/* 2. 主页/公共头部布局:转为纵向排列 */
.sub-header {
margin-top: 70px;
flex-direction: column;
text-align: center;
gap: 10px;
}
.sub-header h2 {
font-size: 1.5em;
}
/* 3. 主页卡片网格:降维至单列 */
.main-grid {
grid-template-columns: 1fr;
gap: 30px;
}
.nav-card {
width: 100%;
height: 160px; /* 稍微压低卡片高度 */
font-size: 1.3em;
}
.capsule-group {
height: auto;
flex-direction: row; /* 数据气泡改为横向并排 */
justify-content: center;
gap: 10px;
margin-bottom: -10px;
}
/* 4. 搜索框工具栏:占满屏幕宽度 */
.search-box {
width: 100%;
}
/* 5. 数据表格降级方案:启用内部横向滚动 */
.container {
padding-left: 10px;
padding-right: 10px;
margin-top: 70px; /* 防止被顶栏遮挡 */
}
/* 将表格外层容器(如果需要)或表格本身设为块级并允许横向滚动 */
table {
display: block;
overflow-x: auto;
white-space: nowrap; /* 强制内容不换行,保障表格结构 */
-webkit-overflow-scrolling: touch; /* 提升 iOS 上的滚动顺滑度 */
}
th, td {
padding: 12px 10px;
}
/* 6. 右下角悬浮按钮:缩小并靠边,防止挡住底层表格内容 */
.floating-nav {
bottom: 20px;
right: 15px;
gap: 10px;
}
.btn-jump {
padding: 8px 16px;
font-size: 0.85em;
}
}
</style>
</head>
<body>
<header>
<div class="header-left">
<h1>XCPC-Math-Finder</h1>
<span class="author">🧮 专项数学训练</span>
</div>
<div class="header-right-nav">
<a href="index.html" class="back-btn"><i class="fa-solid fa-house"></i> 返回主页</a>
</div>
</header>
<div class="toolbar">
<div class="search-box">
<i class="fa-solid fa-magnifying-glass"></i>
<input type="text" id="search-input" placeholder="搜索细分小类、比赛名称或题号..." oninput="handleSearch()">
</div>
</div>
<div class="floating-nav" id="nav-container">
</div>
<div class="container" id="main-container">
</div>
<script>
const CATEGORIES = ["计数问题", "纯数论", "线性代数", "概率与期望"];
const DIFF_WEIGHT = { "Easy": 1, "Medium": 2, "Hard": 3 };
let globalMathData = [];
let doneMap = JSON.parse(localStorage.getItem('math_done_records')) || {};
const navContainer = document.getElementById('nav-container');
const mainContainer = document.getElementById('main-container');
// 初始化导航锚点
function initNav() {
navContainer.innerHTML = CATEGORIES.map((cat, index) =>
`<a href="#cat-${index}" class="btn-jump"><i class="fa-solid fa-tag"></i> ${cat}</a>`
).join('');
}
function getPlatformBadge(platform) {
if (platform === 'Codeforces') return '<span class="badge badge-cf">Codeforces</span>';
if (platform === 'QOJ') return '<span class="badge badge-qoj">QOJ</span>';
return `<span class="badge" style="background:#7f8c8d;">${platform}</span>`;
}
function getDiffBadge(diff) {
let cls = 'diff-easy';
if (diff === 'Medium') cls = 'diff-medium';
if (diff === 'Hard') cls = 'diff-hard';
return `<span class="badge ${cls}">${diff}</span>`;
}
function toggleMathDone(id, currentState) {
doneMap[id] = !currentState;
localStorage.setItem('math_done_records', JSON.stringify(doneMap));
renderMathView(document.getElementById('search-input').value.trim());
}
function handleSearch() {
const keyword = document.getElementById('search-input').value.trim();
renderMathView(keyword);
}
function renderMathView(filterKeyword = '') {
mainContainer.innerHTML = '';
const keyword = filterKeyword.toLowerCase();
// 1. 过滤数据
let filteredData = globalMathData;
if (keyword) {
filteredData = globalMathData.filter(item => {
const matchName = (item.contest_name || '').toLowerCase().includes(keyword);
const matchSub = (item.subcategory || '').toLowerCase().includes(keyword);
const matchId = (item.problem_id || '').toLowerCase().includes(keyword);
return matchName || matchSub || matchId;
});
}
// 2. 按四大类循环渲染
CATEGORIES.forEach((cat, index) => {
const section = document.createElement('div');
section.className = 'category-section';
section.id = `cat-${index}`;
// 标题
section.innerHTML = `
<h2 class="category-title"><i class="fa-solid fa-cube"></i> ${cat}</h2>
<hr class="section-divider">
`;
// 提取该大类下的数据
const catData = filteredData.filter(item => item.category === cat);
if (catData.length === 0) {
section.innerHTML += `<div class="empty-state">暂无符合条件的题目</div>`;
mainContainer.appendChild(section);
return;
}
// 3. 按小类 (subcategory) 聚合分组
const subcatMap = {};
catData.forEach(item => {
const sub = item.subcategory || '其他';
if (!subcatMap[sub]) subcatMap[sub] = [];
subcatMap[sub].push(item);
});
// 4. 构建表格
const table = document.createElement('table');
let tbodyHTML = `
<thead>
<tr>
<th width="60px">状态</th>
<th width="100px">难度</th>
<th width="100px">平台</th>
<th>比赛名称 & 题号</th>
<th width="120px">操作</th>
</tr>
</thead>
<tbody>
`;
// 遍历每个小类
for (const [subcat, problems] of Object.entries(subcatMap)) {
// 小类标题行
tbodyHTML += `<tr><td colspan="5" class="subcat-header">🏷️ ${subcat}</td></tr>`;
// 排序核心逻辑:未做在前(0),已做沉底(1)。同状态下按照 Easy->Medium->Hard 排序
problems.sort((a, b) => {
const doneA = doneMap[a.id] ? 1 : 0;
const doneB = doneMap[b.id] ? 1 : 0;
if (doneA !== doneB) return doneA - doneB; // 状态不同,未做在前
const weightA = DIFF_WEIGHT[a.difficulty] || 0;
const weightB = DIFF_WEIGHT[b.difficulty] || 0;
return weightA - weightB; // 难度升序
});
// 生成题目行
problems.forEach(p => {
const isDone = doneMap[p.id] || false;
const rowClass = isDone ? 'done-row' : '';
tbodyHTML += `
<tr class="${rowClass}">
<td>
<input type="checkbox" ${isDone ? 'checked' : ''}
onchange="toggleMathDone('${p.id}', ${isDone})">
</td>
<td>${getDiffBadge(p.difficulty)}</td>
<td>${getPlatformBadge(p.platform)}</td>
<td><strong>${p.contest_name}</strong> - Problem ${p.problem_id}</td>
<td><a href="${p.contest_url}" target="_blank" class="link-btn">去切题 🚀</a></td>
</tr>
`;
});
}
tbodyHTML += `</tbody>`;
table.innerHTML = tbodyHTML;
section.appendChild(table);
mainContainer.appendChild(section);
});
}
// 入口
initNav();
fetch('math_problems.json')
.then(res => res.json())
.then(data => {
globalMathData = data;
renderMathView();
})
.catch(err => {
console.error("加载数学题库失败", err);
mainContainer.innerHTML = `<div class="empty-state" style="color:#e74c3c; background:rgba(255,255,255,0.8);">⚠️ 无法读取题库数据。请确保已通过 Python 脚本录入了题目,并在本地 Server 环境下运行。</div>`;
});
</script>
</body>
</html>