Skip to content

Commit 793cf28

Browse files
Add problems (#71)
* new problems * file name upd
1 parent f5767f2 commit 793cf28

72 files changed

Lines changed: 3175999 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include "testlib.h"
2+
#include <vector>
3+
4+
using namespace std;
5+
6+
int main(int argc, char* argv[]) {
7+
// 初始化 testlib
8+
registerTestlibCmd(argc, argv);
9+
10+
// 1. 读取输入数据 (Input)
11+
int N = inf.readInt();
12+
int M = inf.readInt();
13+
14+
// 存储边列表,用于验证覆盖
15+
vector<pair<int, int>> edges;
16+
edges.reserve(M);
17+
for (int i = 0; i < M; i++) {
18+
int u = inf.readInt();
19+
int v = inf.readInt();
20+
edges.push_back({u, v});
21+
}
22+
23+
// 2. 读取标准答案 (Answer)
24+
// 修改处:ans 文件中只包含一个整数 K* (最优/参考解的大小)
25+
int K_optimal = ans.readInt();
26+
27+
// 3. 读取选手输出 (Output) 并统计 K
28+
vector<int> user_sol(N + 1); // 1-based indexing
29+
int K_user = 0;
30+
31+
for (int i = 1; i <= N; i++) {
32+
// 读取 0 或 1
33+
int val = ouf.readInt(0, 1, format("x_%d", i));
34+
user_sol[i] = val;
35+
if (val == 1) {
36+
K_user++;
37+
}
38+
}
39+
40+
// 4. 验证选手的解是否有效 (Validity Check)
41+
for (int i = 0; i < M; i++) {
42+
int u = edges[i].first;
43+
int v = edges[i].second;
44+
45+
// 如果一条边的两个端点都没被选中
46+
if (user_sol[u] == 0 && user_sol[v] == 0) {
47+
quitf(_wa, "Edge %d-%d is not covered (vertices %d and %d are both 0).", u, v, u, v);
48+
}
49+
}
50+
51+
// 5. 计算得分 (Scoring)
52+
if (K_user == 0) {
53+
if (M == 0) {
54+
quitf(_ok, "Ratio: 1");
55+
} else {
56+
quitf(_wa, "Logic error: Valid solution found with size 0 for non-empty graph.");
57+
}
58+
}
59+
60+
double score = (double)K_optimal / K_user * 100.0;
61+
double Ratio = (double)K_optimal / K_user;
62+
63+
// 6. 输出结果
64+
quitf(_ok, "Valid Vertex Cover. K_user=%d, K_jury=%d, Ratio: %.4f", K_user, K_optimal, Ratio);
65+
66+
return 0;
67+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
type: default
2+
time: 2s
3+
memory: 512m
4+
subtasks:
5+
- score: 100
6+
n_cases: 3
7+
checker: checker.cc
8+
checker_type: testlib
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Vertex Cover Challenge
2+
3+
## Context
4+
5+
You are given an undirected graph G = (V, E) with |V| = N vertices and |E| = M edges.
6+
You must select a subset of vertices S ⊆ V to form a Vertex Cover.
7+
8+
A subset S is a valid vertex cover if and only if:
9+
for every edge {u, v} ∈ E, at least one of its endpoints is in S.
10+
(i.e., u ∈ S or v ∈ S or both).
11+
12+
This is a heuristic optimization problem.
13+
You are NOT required to find the theoretically optimal solution.
14+
Instead, you should try to minimize the size of the set S (denoted as |S|).
15+
16+
Let:
17+
K* = the minimum vertex cover size (optimal solution).
18+
K = the size of the vertex cover found by your solution.
19+
20+
The score is defined as:
21+
Score = K* / K * 100
22+
23+
Thus:
24+
- Score = 100.0 means you found an optimal vertex cover.
25+
- Larger K yields a smaller score.
26+
- Invalid solutions (where some edges are not covered) receive score = 0.
27+
28+
The value K* is known to the judge but not to the contestant.
29+
30+
## Input Format
31+
32+
The first line contains two integers:
33+
N M
34+
where:
35+
2 ≤ N ≤ 10,000
36+
1 ≤ M ≤ 500,000
37+
38+
The next M lines each contain two integers:
39+
u v
40+
representing an undirected edge {u, v},
41+
with 1 ≤ u, v ≤ N and u ≠ v.
42+
43+
Multiple edges between the same pair of vertices may appear but imply the same constraint.
44+
45+
## Output Format
46+
47+
Output exactly N lines.
48+
49+
The i-th line must contain one integer x_i ∈ {0, 1}:
50+
- 1 indicates that vertex i is included in the vertex cover (i ∈ S).
51+
- 0 indicates that vertex i is excluded from the vertex cover (i ∉ S).
52+
53+
Requirements:
54+
- For any edge {u, v} ∈ E, it must be true that x_u = 1 OR x_v = 1.
55+
56+
## Scoring
57+
58+
Let:
59+
K = Σ x_i (Total number of vertices selected, i.e., sum of 1s in output)
60+
K* = Optimal minimum vertex cover size (hidden)
61+
62+
If the solution is invalid (i.e., there exists an edge {u, v} where x_u=0 and x_v=0):
63+
Score = 0
64+
65+
Otherwise:
66+
Score = K* / K * 100
67+
68+
Higher score is better.
69+
70+
## Example
71+
72+
Input:
73+
4 3
74+
1 2
75+
2 3
76+
3 4
77+
78+
Output:
79+
0
80+
1
81+
1
82+
0
83+
84+
Explanation:
85+
The edges are {1,2}, {2,3}, {3,4}.
86+
The output selects vertices 2 and 3 (S={2, 3}).
87+
- Edge {1,2} is covered by 2.
88+
- Edge {2,3} is covered by 2 (and 3).
89+
- Edge {3,4} is covered by 3.
90+
All edges are covered.
91+
Total size K = 2.
92+
Assuming the optimal K* = 2, the Score = 2 / 2 * 100 = 100.0.
93+
94+
## Constraints
95+
96+
- 2 ≤ N ≤ 10,000
97+
- 1 ≤ M ≤ 500,000
98+
- Time Limit: 2.0s
99+
- Memory Limit: 512MB
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5800

0 commit comments

Comments
 (0)