Notepad

Word1

学生端:ntsd /pn studentmain.exe

Word2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Sub button1_Click()
Dim a As Integer
Randomize
a = Int(Rnd() * 49 + 1)
Range("a14") = a
End Sub
Sub button2_Click()
Dim x, y As Integer
Randomize
x = Int(Rnd() * 8 + 1)
y = Int(Rnd() * 6 + 1)
Range("a1:f8").Interior.ColorIndex = xlNone
Cells(x, y).Interior.ColorIndex = 3
End Sub

Word3

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
//https://vijos.org/p/1755
//https://www.luogu.org/problemnew/solution/P1074
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int s[10][10];
//分值我们打标
const int score[10][10]={
{0,0,0,0,0,0,0,0,0,0},
{0,6,6,6,6,6,6,6,6,6},
{0,6,7,7,7,7,7,7,7,6},
{0,6,7,8,8,8,8,8,7,6},
{0,6,7,8,9,9,9,8,7,6},
{0,6,7,8,9,10,9,8,7,6},
{0,6,7,8,9,9,9,8,7,6},
{0,6,7,8,8,8,8,8,7,6},
{0,6,7,7,7,7,7,7,7,6},
{0,6,6,6,6,6,6,6,6,6}
};
//计算分值
inline int calc(){
int t=0;
for(int i=1;i<=9;++i)
for(int j=1;j<=9;++j)
t += score[i][j]*s[i][j];
return t;
}
//是否满足行列不相等
int check(){
return 1;
}
//search
void dfs(){
return ;
}
//main
int main(){
for(int i = 1; i <= 9; i++)
for(int j = 1; j <= 9; j++)
cin>>s[i][j];
dfs();
//cout<<cacl()<<"\n";
return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
int getint(){
int x=0,f=1; char ch=getchar();
while(ch>'9'||ch<'0'){if(ch=='-')f=-f; ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
return f*x;
}
const int MAXN=12;
const int score[10][10]=
{{0,0,0,0,0,0,0,0,0,0},
{0,6,6,6,6,6,6,6,6,6},
{0,6,7,7,7,7,7,7,7,6},
{0,6,7,8,8,8,8,8,7,6},
{0,6,7,8,9,9,9,8,7,6},
{0,6,7,8,9,10,9,8,7,6},
{0,6,7,8,9,9,9,8,7,6},
{0,6,7,8,8,8,8,8,7,6},
{0,6,7,7,7,7,7,7,7,6},
{0,6,6,6,6,6,6,6,6,6}};
int row[MAXN][MAXN],col[MAXN][MAXN],area[MAXN][MAXN],sdk[MAXN][MAXN];
int row_cnt[MAXN],col_cnt[MAXN],cnt,ans=-1;
inline int id(int i,int j){return (i-1)/3*3+1+(j-1)/3;}
inline int calc(){
int tmp=0;
for(int i=1;i<=9;++i)
for(int j=1;j<=9;++j)
tmp+=score[i][j]*sdk[i][j];
return tmp;
}
void dfs(int r,int c,int cpl){
if(cpl==81){
ans=max(ans,calc());
return ;
}
for(int k=1;k<=9;++k){
if(row[r][k]||col[c][k]||area[id(r,c)][k]) continue;
row[r][k]=true;
col[c][k]=true;
area[id(r,c)][k]=true;
row_cnt[r]++,col_cnt[c]++;
sdk[r][c]=k;
int tmpr=-1,nxt_r=0,tmpc=-1,nxt_c=0;
for(int i=1;i<=9;++i)
if(row_cnt[i]>tmpr&&row_cnt[i]<9)
tmpr=row_cnt[i],nxt_r=i;
for(int j=1;j<=9;++j)
if(col_cnt[j]>tmpc&&(!sdk[nxt_r][j]))
tmpc=col_cnt[j],nxt_c=j;
dfs(nxt_r,nxt_c,cpl+1);
row[r][k]=false;
col[c][k]=false;
area[id(r,c)][k]=false;
row_cnt[r]--,col_cnt[c]--;
sdk[r][c]=0;
}
}
int main(){
for(int i=1;i<=9;++i){
for(int j=1;j<=9;++j){
sdk[i][j]=getint();
if(sdk[i][j]!=0){
row[i][sdk[i][j]]=true;
col[j][sdk[i][j]]=true;
area[id(i,j)][sdk[i][j]]=true;
row_cnt[i]++,col_cnt[j]++;
cnt++;
}
}
}
int tmpr=-1,r,tmpc=-1,c;
for(int i=1;i<=9;++i)
if(row_cnt[i]>tmpr&&row_cnt[i]<9)
tmpr=row_cnt[i],r=i;
for(int j=1;j<=9;++j)
if(col_cnt[j]>tmpc&&(!sdk[r][j]))
tmpc=col_cnt[j],c=j;
dfs(r,c,cnt);
cout<<ans<<endl;
}
//八数码
/*
作者:gwj233
题目:p1225 八数码难题
*/
#include<iostream>
#include<string>
#include<set>
#include<cstring>
using namespace std;
const int maxn = 1000000;
typedef int State[9];
State st[maxn], goal = {1,2,3,8,0,4,7,6,5};
int dist[maxn];
set<int>vis;
void init(){ vis.clear();}
bool insert(int x){
int t = 0;
for(int i = 0; i < 9; i++)t = t*10+st[x][i];
if(vis.count(t))return false;
vis.insert(t);
return true;
}
bool vis2[362880]; int fact[9];
void init2(){
fact[0] = 1;
for(int i = 1; i < 9; i++)fact[i] = fact[i-1]*i;
}
bool insert2(int x){
int code = 0;
for(int i = 0; i < 9; i++){
int cnt = 0;
for(int j = i+1; j < 9; j++)if(st[x][j] < st[x][i])cnt++;
code += fact[8-i]*cnt;
}
if(vis2[code])return false;
return vis2[code]=true;
}
const int MAXHASHSIZE = 1000003;
int head[MAXHASHSIZE], next[MAXHASHSIZE];
void init3(){ memset(head, 0, sizeof(head));}
int hash(State& s){
int v = 0;
for(int i = 0; i < 9; i++)v = v*10+s[i];
return v % MAXHASHSIZE;
}
bool insert3(int x){
int h = hash(st[x]);
int u = head[h];
while(u){
bool ok = true;
for(int i = 0; i < 9; i++)
if(st[u][i] != st[x][i])ok = false;
if(ok) return false;
u = next[u];
}
next[x] = head[h];
next[h] = x;
return true;
}
const int dx[] = {0,0,1,-1};
const int dy[] = {-1,1,0,0};
int bfs(){
init2();
int front = 1, rear = 2;
while(front < rear){
bool ok = true;
for(int i = 0; i < 9; i++)
if(st[front][i] != goal[i])ok = false;
if(ok) return front;
int z;
for(z = 0; z < 9; z++)if(!st[front][z])break;
int x = z/3, y = z%3;
for(int i = 0; i < 4; i++){
int newx=x+dx[i], newy=y+dy[i], newz=newx*3+newy;
if(newx>=0 && newx<3 && newy>=0 && newy<3){
for(int j = 0; j < 9; j++)st[rear][j] = st[front][j];
st[rear][newz] = st[front][z];
st[rear][z] = st[front][newz];
dist[rear] = dist[front]+1;
if(insert2(rear))rear++;
}
}
front++;
}
return 0;
}
int main(){
string str;
cin>>str;
for(int i = 0; i < 9; i++)st[1][i] = str[i]-'0';
cout<<dist[bfs()];
return 0;
}
// 八数码,使用哈希表(竞赛中最常用)
// Rujia Liu
#include<cstdio>
#include<cstring>
#include<set>
#include<iostream>
using namespace std;
typedef int State[9];
const int MAXSTATE = 1000000;
State st[MAXSTATE], goal = {1,2,3,8,0,4,7,6,5};
int dist[MAXSTATE];
const int MAXHASHSIZE = 1000003;
int head[MAXHASHSIZE], next[MAXSTATE];
void init_lookup_table() { memset(head, 0, sizeof(head)); }
int hash(State& s) {
int v = 0;
for(int i = 0; i < 9; i++) v = v * 10 + s[i];
return v % MAXHASHSIZE;
}
int try_to_insert(int s) {
int h = hash(st[s]);
int u = head[h];
while(u) {
if(memcmp(st[u], st[s], sizeof(st[s])) == 0) return 0;
u = next[u];
}
next[s] = head[h];
head[h] = s;
return 1;
}
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
int bfs() {
init_lookup_table();
int front = 1, rear = 2;
while(front < rear) {
State& s = st[front];
if(memcmp(goal, s, sizeof(s)) == 0) return front;
int z;
for(z = 0; z < 9; z++) if(!s[z]) break;
int x = z/3, y = z%3;
for(int d = 0; d < 4; d++) {
int newx = x + dx[d];
int newy = y + dy[d];
int newz = newx * 3 + newy;
if(newx >= 0 && newx < 3 && newy >= 0 && newy < 3) {
State& t = st[rear];
memcpy(&t, &s, sizeof(s));
t[newz] = s[z];
t[z] = s[newz];
dist[rear] = dist[front] + 1;
if(try_to_insert(rear)) rear++;
}
}
front++;
}
return 0;
}
int main() {
string str;
cin>>str;
for(int i = 0; i < 9; i++)st[1][i] = str[i]-'0';
int ans = bfs();
if(ans > 0) printf("%d\n", dist[ans]);
else printf("-1\n");
return 0;
}
/*
作者:gwj1139177410
题目:p1225 八数码难题
*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<set>
using namespace std;
typedef int State[9];
const int maxn = 1000000;
State st[maxn], goal = {1,2,3,8,0,4,7,6,5};
int dist[maxn];
set<int>vis;
void init(){ vis.clear();}
bool insert(int s){
int t = 0;
for(int i = 0; i < 9; i++)t = t*10+st[s][i];
if(vis.count(t))return false;
vis.insert(t);
return true;
}
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
int bfs(){
init();
int front = 1, rear = 2;
while(front < rear){
State& t = st[front];
if(memcmp(goal, t, sizeof(t)) == 0)return front;
int z;
for(z = 0; z < 9; z++)if(!t[z])break;
int x = z/3, y = z%3;
for(int i = 0; i < 4; i++){
int newx = x+dx[i], newy = y+dy[i], newz = newx*3+newy;
if(newx>=0 && newx<3 && newy>=0 && newy<3){
State& tt = st[rear];
memcpy(&tt, &t, sizeof(t));
swap(tt[z], tt[newz]);
dist[rear] = dist[front]+1;
if(insert(rear)) rear++;
}
}
front++;
}
return 0;
}
int main(){
string str;
cin>>str;
for(int i = 0; i < 9; i++)st[1][i] = str[i]-'0';
cout<<dist[bfs()];
return 0;
}

参考资料

极域九法