Skip to content

Commit b55c218

Browse files
committed
Update 19-3
1 parent 47f5bc1 commit b55c218

9 files changed

+509
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.exe
2+
*.in
3+
*.out

ccf1312-5.cpp

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#include<iostream>
2+
#include<cstring>
3+
#include<cstdio>
4+
#include<cassert>
5+
using namespace::std;
6+
7+
const int max_rc = 50;
8+
char area[max_rc+5][max_rc+5], reach[max_rc+5][max_rc+5], stuck[max_rc+5][max_rc+5];
9+
int start_x, start_y, end_x, end_y;
10+
int r, c;
11+
12+
void dfs_forward(int x, int y)
13+
{
14+
reach[x][y] = 1;
15+
// printf("Reach at x = %d, y = %d\n", x, y);
16+
if(area[x][y] == '+' || area[x][y] == 'S' || area[x][y] == 'T'){
17+
if(x > 0 && !reach[x-1][y] && area[x-1][y] != '#')
18+
dfs_forward(x-1, y);
19+
if(x < r-1 && !reach[x+1][y] && area[x+1][y] != '#')
20+
dfs_forward(x+1, y);
21+
if(y > 0 && !reach[x][y-1] && area[x][y-1] != '#')
22+
dfs_forward(x, y-1);
23+
if(y < c-1 && !reach[x][y+1] && area[x][y+1] != '#')
24+
dfs_forward(x, y+1);
25+
}
26+
else if(area[x][y] == '-'){
27+
if(y > 0 && !reach[x][y-1] && area[x][y-1] != '#')
28+
dfs_forward(x, y-1);
29+
if(y < c-1 && !reach[x][y+1] && area[x][y+1] != '#')
30+
dfs_forward(x, y+1);
31+
}
32+
else if(area[x][y] == '|'){
33+
if(x > 0 && !reach[x-1][y] && area[x-1][y] != '#')
34+
dfs_forward(x-1, y);
35+
if(x < r-1 && !reach[x+1][y] && area[x+1][y] != '#')
36+
dfs_forward(x+1, y);
37+
}
38+
else if(area[x][y] == '.'){
39+
if(x < r-1 && !reach[x+1][y] && area[x+1][y] != '#')
40+
dfs_forward(x+1, y);
41+
}
42+
else{
43+
cout << "Error!" << endl;
44+
printf("Error at x = %d, y = %d\n", x, y);
45+
}
46+
return;
47+
}
48+
49+
void dfs_back(int x, int y)
50+
{
51+
assert(y < c);
52+
// printf("Reach at x = %d, y = %d\n", x, y);
53+
stuck[x][y] = 1; //1±íʾÕâÀïÄܹ»µ½´ït
54+
if(x > 0 && !stuck[x-1][y] && area[x-1][y] != '-' && area[x-1][y] != '#')
55+
dfs_back(x-1, y);
56+
if(x < r-1 && !stuck[x+1][y] && area[x+1][y] != '-' && area[x+1][y] != '#' && area[x+1][y] != '.')
57+
dfs_back(x+1, y);
58+
if(y > 0 && !stuck[x][y-1] && area[x][y-1] != '|' && area[x][y-1] != '#' && area[x][y-1] != '.')
59+
dfs_back(x, y-1);
60+
if(y < c-1 && !stuck[x][y+1] && area[x][y+1] != '|' && area[x][y+1] != '#' && area[x][y+1] != '.')
61+
dfs_back(x, y+1);
62+
return;
63+
}
64+
65+
void print_reach(void)
66+
{
67+
for(int i=0;i<r;i++){
68+
for(int j=0;j<c;j++){
69+
printf("%d ", reach[i][j]);
70+
}
71+
cout << endl;
72+
}
73+
}
74+
void print_stuck(void)
75+
{
76+
for(int i=0;i<r;i++){
77+
for(int j=0;j<c;j++){
78+
printf("%d ", stuck[i][j]);
79+
}
80+
cout << endl;
81+
}
82+
}
83+
84+
int main()
85+
{
86+
cin >> r >> c;
87+
getchar();
88+
memset(reach, 0, sizeof(reach));
89+
memset(stuck, 0, sizeof(stuck));
90+
for(int i=0;i<r;i++){
91+
for(int j=0;j<c;j++){
92+
area[i][j] = getchar();
93+
if(area[i][j] == 'S'){
94+
start_x = i;
95+
start_y = j;
96+
}
97+
else if(area[i][j] == 'T'){
98+
end_x = i;
99+
end_y = j;
100+
}
101+
}
102+
getchar();
103+
}
104+
dfs_forward(start_x, start_y);
105+
// printf("Finish forward dfs!\n");
106+
// printf("end_x = %d, end_y = %d, reach[end_x][end_y] = %d\n", end_x, end_y, reach[end_x][end_y]);
107+
if(!reach[end_x][end_y])
108+
cout << "I'm stuck!" << endl;
109+
else{
110+
dfs_back(end_x, end_y);
111+
int cnt = 0;
112+
for(int i=0;i<r;i++){
113+
for(int j=0;j<c;j++){
114+
if(reach[i][j] && !stuck[i][j])
115+
cnt++;
116+
}
117+
}
118+
cout << cnt << endl;
119+
}
120+
// print_reach();
121+
// cout << endl;
122+
// print_stuck();
123+
return 0;
124+
}

ccf1403-1.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include<iostream>
2+
#include<cstring>
3+
4+
const int max_num = 1000;
5+
int num[max_num + 5]; // 每个数字出现的次数
6+
7+
int main()
8+
{
9+
int N, cnt = 0;
10+
cin >> N;
11+
memset(num, 0, sizeof(num));
12+
while(N-- > 0){
13+
int x;
14+
cin >> x;
15+
if(x < 0) x = -x;
16+
if(!num[x]) num[x]++; //没出现过
17+
else cnt++;
18+
}
19+
cout << cnt;
20+
return 0;
21+
}

ccf1403-2-test.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include<iostream>
2+
#include<fstream>
3+
#include<cstdio>
4+
#include<random>
5+
#include<utility> //swap
6+
using namespace::std;
7+
8+
int main()
9+
{
10+
ofstream out("ccf1403-2.in");
11+
out << "10 10" << endl;
12+
default_random_engine e;
13+
uniform_int_distribution<unsigned> x(0, 2559), y(0, 1439);
14+
for(int i=0;i<10;i++){
15+
unsigned x1 = x(e), y1 = y(e), x2 = x(e), y2 = y(e);
16+
if(x1 > x2) swap(x1, x2);
17+
if(y1 > y2) swap(y1, y2);
18+
out << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << endl;
19+
}
20+
for(int i=0;i<10;i++)
21+
out << x(e) << ' ' << y(e) << endl;
22+
out.close();
23+
return 0;
24+
}

ccf1403-2.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include<iostream>
2+
#include<list>
3+
using namespace::std;
4+
5+
struct window{
6+
window() = default;
7+
window(int a, int b, int c, int d, int l) : x1(a), y1(b), x2(c), y2(d), label(l) {} //ûÓзâºÅ
8+
int x1, y1, x2, y2, label;
9+
};
10+
11+
int main()
12+
{
13+
list<window> windows;
14+
int N, M;
15+
cin >> N >> M;
16+
for(int i=1;i<=N;i++){
17+
int a, b, c, d;
18+
cin >> a >> b >> c >> d;
19+
window win(a, b, c, d, i);
20+
windows.push_front(win);
21+
}
22+
while(M-- > 0){
23+
int x, y;
24+
cin >> x >> y;
25+
bool is_window = false;
26+
for(auto it = windows.begin(); it != windows.end(); it++){
27+
if(it->x1 <= x && it->y1 <= y && it->x2 >= x && it->y2 >= y){
28+
is_window = true;
29+
cout << it->label << endl;
30+
window w = *it;
31+
windows.erase(it);
32+
windows.push_front(w);
33+
break;
34+
}
35+
}
36+
if(!is_window) cout << "IGNORED" << endl;
37+
}
38+
return 0;
39+
}

ccf1903-1.cpp

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include<iostream>
2+
#include<cstdio>
3+
#include<vector>
4+
using namespace::std;
5+
6+
int main()
7+
{
8+
int n;
9+
cin >> n;
10+
vector<int> a;
11+
for(int i=0;i<n;i++){
12+
int x;
13+
cin >> x;
14+
a.push_back(x);
15+
}
16+
int len = a.size();
17+
if(len % 2){
18+
int first = a[0], last = a.back(), mid = a[len / 2];
19+
if(first >= last)
20+
printf("%d %d %d", first, mid, last);
21+
else
22+
printf("%d %d %d", last, mid, first);
23+
}
24+
else{
25+
int first = a[0], last = a.back(), mid1 = a[len / 2 - 1], mid2 = a[len / 2];
26+
if((mid1 + mid2) % 2){
27+
double mid = (mid1 + mid2) / 2.0;
28+
if(first >= last)
29+
printf("%d %.1f %d", first, mid, last);
30+
else
31+
printf("%d %.1f %d", last, mid, first);
32+
}
33+
else{
34+
if(first >= last)
35+
printf("%d %d %d", first, (mid1 + mid2) / 2, last);
36+
else
37+
printf("%d %d %d", last, (mid1 + mid2) / 2, first);
38+
}
39+
}
40+
return 0;
41+
}

ccf1903-2 (2).cpp

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#include<iostream>
2+
#include<cstdio>
3+
#include<map>
4+
using namespace std;
5+
int plu(int, int);
6+
int sub(int, int);
7+
int mul(int, int);
8+
int divi(int, int);
9+
using PF = int(*)(int, int);
10+
PF compute[3];
11+
map<char, int> com = {{'+', 0},{'-', 1},
12+
{'x',2}, {'/',3}};
13+
int cal(int a, int b, char m);
14+
/*****
15+
错误原因:
16+
最暴力的是考虑64种情况
17+
比较好的是考虑八种情况(三个位置,每个位置是否是乘除)
18+
考试时只考虑了四种情况,想偷懒
19+
结果根本不对
20+
其实当时还是太慌了
21+
要是测试一下,每种情况的计算结果,就知道对不对了
22+
硬是不肯算,就一行的事
23+
*****/
24+
25+
26+
int main()
27+
{
28+
int n;
29+
cin >> n;
30+
compute[0] = plu;
31+
compute[1] = sub;
32+
compute[2] = mul;
33+
compute[3] = divi;
34+
while(n-- > 0)
35+
{
36+
int res = 0;
37+
char old[8];
38+
scanf("%s", old);
39+
char a = old[0], b = old[2], c = old[4], d =old[6];
40+
char x = old[1], y = old[3], z = old[5];
41+
if(com[x] < 2){
42+
if(com[y] < 2){
43+
res = cal(c-'0', d-'0', z);
44+
// res = cal(res, b-'0', y);
45+
// res = cal(res, a-'0', x);
46+
// 上面计算顺序错了,要注意减号和除法的计算顺序是不同的
47+
res = cal(b-'0', res, y);
48+
res = cal(a-'0', res, x);
49+
}
50+
else{
51+
res = cal(b-'0', c-'0', y);
52+
res = cal(res, d-'0', z);
53+
// res = cal(res, a-'0', x);
54+
res = cal(a-'0', res, x);
55+
}
56+
}
57+
else{
58+
if(com[y] < 2){
59+
res = cal(a-'0', b-'0', x);
60+
int res2 = cal(c-'0', d-'0', z);
61+
res = cal(res, res2, y);
62+
}
63+
else{
64+
res = cal(a-'0', b-'0', x);
65+
res = cal(res, c-'0', y);
66+
res = cal(res, d-'0', z);
67+
}
68+
}
69+
// cout << res << endl;
70+
printf("%d\n", res);
71+
// if(res == 24)
72+
// cout << "Yes" << endl;
73+
// else
74+
// cout << "No" << endl;
75+
}
76+
return 0;
77+
}
78+
int plu(int a, int b)
79+
{
80+
return a+b;
81+
}
82+
int sub(int a, int b)
83+
{
84+
return a-b;
85+
}
86+
int mul(int a, int b)
87+
{
88+
return a*b;
89+
}
90+
int divi(int a, int b)
91+
{
92+
return a/b;
93+
}
94+
int cal(int a, int b, char m)
95+
{
96+
return (compute[com[m]])(a, b);
97+
}

0 commit comments

Comments
 (0)