传送门
一道卡时爆搜好题(正解想不出来)
注意:以下代码不保证能通过此题,交之前请先洗把脸谢谢
code:
复制代码
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#include<bits/stdc++.h> using namespace std; const int MAXN = 20; const int INF = 2000000000; int n, f[MAXN][4]; // friends int b[MAXN], pos[MAXN]; bitset<MAXN> used; int min1; int read() { int res = 0; int get = getchar(); while(!isdigit(get)) get = getchar(); while(isdigit(get)) { res = res * 10 + get - '0'; get = getchar(); } return res; } inline void generate() { used.reset(); int a = rand() % n + 1; for(int i = 1; i <= n; i ++) { while(used[a]) { a = rand() % n + 1; } used[a] = 1; b[i] = a; pos[a] = i; } } int ans; inline void check() { ans = 0; for(int i = 1; i <= n; i ++) { for(int j = 1; j <= 3; j ++) { ans += abs(pos[f[b[i]][j]] - i); } } min1 = min(min1, ans); } int main() { srand(time(0)); min1 = INF; n = read(); for(int i = 1; i <= n; i ++) { f[i][1] = read(); f[i][2] = read(); f[i][3] = read(); } int c = clock(); while(clock() - c <= 0.995 * CLOCKS_PER_SEC) { generate(); check(); } cout<<min1 / 2<<endl; return 0; }
最后
以上就是粗心天空最近收集整理的关于P2210 Haywire(乱搞)的全部内容,更多相关P2210内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复