1. 定义了一个类命名为a,调用a类中的func()函数

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
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <unordered_map>

using namespace std;

unordered_map<char, int> h{{'+','1'}, {'-','1'}, {'*','2'}, {'/','2'}};

stack<char> op;
stack<int> nums;

void eval()
{
int b = nums.top();
nums.pop();

int a = nums.top();
nums.pop();

char c = op.top();
op.pop();

int x;
if(c == '+') x = a + b;
if(c == '-') x = a - b;
if(c == '*') x = a * b;
if(c == '/') x = a / b;

nums.push(x);
}

int main()
{
string str;
cin >> str;

for(int i = 0; i < str.size(); i ++ )
{
if(isdigit(str[i]))
{
int j = i, sum = 0;
while(j < str.size() && isdigit(str[j]))
{
sum = sum * 10 + str[j] - '0';
j ++ ;
}
nums.push(sum);

i = j - 1;
}
else if(str[i] == '(') op.push(str[i]);
else if(str[i] == ')')
{
while(op.top() != '(')
{
eval();
}
op.pop();
}
else
{
while(op.size() && h[op.top()] >= h[str[i]])
{
eval();
}
op.push(str[i]);
}
}

while(op.size()) eval();

cout << nums.top() << endl;

return 0;
}
  1. 首先获取聊天框的组件,利用正则表达式,定义一些敏感词,比如卖号QQ微信之类,当要用户要发送这些数据的时候,经过后端判断,才能发送。

  2. 整体思路:如果图是稠密图,可以围绕该点一圈一圈的进行遍历(代码一),时间复杂度$O(nm)$。如果是稀疏图,可以用二分找到离得近的点,时间复杂度$10^7\times log_{2}10^7$(代码二)。

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

// 代码一

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <unordered_map>

using namespace std;

const int N = 10010;

typedef pair<int, int> PII;

int n, m;
int Map[N][N];
PII ans;

void Find(int x, int y)
{
int len = 1;
while(len <= min(n, m))
{
for(int i = max(1, x - len); i <= min(m, x + len); i ++ ) // 遍历上下横边
if(Map[max(1, y - len)][i])
{
ans.first = max(1, y - len);
ans.second = i;
return;
}
else if(Map[max(1, y + len)][i])
{
ans.first = max(1, y + len);
ans.second = i;
return;
}

for(int i = max(1, y - len); i <= min(m, y + len); i ++ ) // 遍历左右竖边
if(Map[i][max(1, x - len)])
{
ans.first = i;
ans.second = max(1, x - len);
return;
}
else if(Map[i][max(1, x + len)])
{
ans.first = i;
ans.second = max(1, x + len);
return;
}

len ++ ;
}
}

int main()
{
int x, y;
cin >> n >> m;
for(int i = 1; i <= n; i ++ )
for(int j = 1; j <= m; j ++ )
cin >> Map[i][j];

cin >> x >> y;

Find(x, y);

cout << ans.first << " " << ans.second << endl;

return 0;
}


// 代码二
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <unordered_map>

using namespace std;

const int N = 1000010;

typedef pair<int, int> PII;

PII Map[N];
int n;
int x, y;

int cmp(PII a, PII b)
{
if(a.first != b.first) return a.first < b.first;
else return a.second < b.second;
}

int main()
{
// 排序
cin >> n;
for(int i = 1; i <= n; i ++ ) cin >> Map[i].first >> Map[i].second;
sort(Map + 1, Map + 1 + n, cmp);

cin >> x >> y;

// 二分

int L, R;

int l = 1, r = n;
while(l < r)
{
int mid = l + r + 1 >> 1;
if(x >= Map[mid].first) l = mid;
else r = mid - 1;
}

if(x != Map[l].first)
{
int dis1 = abs(Map[l].first - x) + abs(Map[l].second - y);
int dis2 = abs(Map[l + 1].first - x) + abs(Map[l + 1].second - y);
cout << min(dis1, dis2) << endl;
return 0;
}

R = l; // 找到右端

l = 1, r = n;
while(l < r)
{
int mid = l + r >> 1;
if(x <= Map[mid].first) r = mid;
else l = mid + 1;
}

L = l; // 找到左端

while(L < R)
{
int mid = L + R >> 1;
if(y <= Map[mid].second) R = mid;
else L = mid + 1;
}

int dis1 = abs(Map[L].first - x) + abs(Map[L].second - y);
int dis2 = abs(Map[L + 1].first - x) + abs(Map[L + 1].second - y);
cout << min(dis1, dis2) << endl;

return 0;
}
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
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <unordered_map>

using namespace std;

const int N = 60;

int g[N][N];
bool st[N][N];
int ans[N];
int idx;

int n, m;

int main()
{
cin >> n >> m;

for(int i = 1; i <= n; i ++ )
for(int j = 1; j <= m; j ++ )
cin >> g[i][j];

for(int i = 1; i <= n; i ++ )
for(int j = 1; j <= m; j ++ )
if(g[i][j] && !st[i][j])
{
bool flag = false;
st[i][j] = true;
int cnt = 1;
for(int k = j + 1; k <= m; k ++ )
if(g[i][k] && !st[i][k])
{
cnt ++ ;
st[i][k] = true;
}
else
{
flag = true;
break;
}

for(int k = i + 1; k <= cnt - 1; k ++ )
for(int u = j; u <= cnt; u ++ )
if(g[k][u] && !st[k][u])
{
st[k][u] = true;
}
else
{
flag = true;
break;
}

if(!flag) ans[idx ++ ] = cnt;
}


sort(ans, ans + idx - 1);

for(int i = 0; i < idx; i ++ ) cout << ans[i] << " ";
cout << endl;

return 0;
}
  1. 栈是先进后出的数据结构,队列是先进先出的数据结构。栈常用于括号匹配,深度优先搜索;队列常用于宽度优先搜索。

  2. .

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
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <unordered_map>

using namespace std;

double t;

int main()
{
cin >> t;
double l = 0, r = 1e8;
while(r - l > 1e-8)
{
double mid = (l + r) / 2;
if(mid * mid >= t) r = mid;
else l = mid;
}

printf("%lf\n", l);

return 0;
}