# 2023/03/13刷题()-其他

## 2023/03/13刷题()

### 链接

C. Boxes Packing

``````#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstring>
#include <unordered_set>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <sstream>
#include <queue>
#define int long long
#define yes cout<<"YES"<<'\n'
#define no 	cout<<"NO"<<'\n'

using namespace std;

const int N = 5100;
signed main () {
int n;
int a[N] = {0};
scanf("%lld", &n);
for (int i = 0; i < n; i++) {
scanf("%lld", &a[i]);
}
sort(a, a + n);
//因为是10的9次方,所以不能用st数组存,可以用map或者先排序然后判断有多少个
int ans = 0;
int cnt = 1;
for (int i = 1; i < n; i++) {
if (a[i] == a[i - 1]) {
cnt++;
} else {
ans = max(ans, cnt);
cnt = 1;
}

}
ans = max(ans, cnt);//通过上面的过程得到ans
cout << ans << '\n';//打印ans

return 0;
}
``````

### 链接

``````#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstring>
#include <unordered_set>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <sstream>
#include <queue>
#define int long long
#define yes cout<<"YES"<<'\n'
#define no 	cout<<"NO"<<'\n'

using namespace std;
const int N = 100008;

void solve() {
int n, m, s_x, s_y, d;
cin >> n >> m >> s_x >> s_y >> d;
int flag1 = 1, flag2 = 1;
//两个flag符合一个就可以
for (int i = 1; i <= n; i++) {
if (abs(i - s_x) + abs(1 - s_y) <= d) {
flag1 = 0;//先向右走,如果碰到激光直接失败
}
}
for (int j = 1; j <= m; j++) {
if (abs(n - s_x) + abs(j - s_y) <= d) {
flag1 = 0;//再向上走,如果碰到激光直接失败
}
}

for (int j = 1; j <= m; j++) {
if (abs(1 - s_x) + abs(j - s_y) <= d) {
flag2 = 0;//先向上走,如果碰到激光直接失败
}
}
for (int i = 1; i <= n; i++) {
if (abs(i - s_x) + abs(m - s_y) <= d) {
flag2 = 0;//再向右走,如果碰到激光直接失败
}
}

if (flag1 == 1 || flag2 == 1) {//满足以恶搞打印最短距离就可以
cout << abs(n - 1) + abs(m - 1) << '\n';
} else {
cout << -1 << '\n';//否则打印-1

}
}
signed main () {
int t;
cin >> t;
while (t) {
solve();
t--;
}

return 0;
}
``````

### 链接

Settlement of Guinea Pigs

``````#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstring>
#include <unordered_set>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <sstream>
#include <queue>
#define int long long
#define yes cout<<"YES"<<'\n'
#define no 	cout<<"NO"<<'\n'

using namespace std;

int b[200006] = {0};
signed main () {

int n;
scanf("%lld", &n);
if (n % 2 == 0) { //先判断奇数和偶数
no;

return 0;
}
int flag = 0;
int cnt = 1;
for (int i = 1; i <= n; i++) {
if (flag % 2 == 0) {
b[i] = cnt++;
b[i + n] = cnt++;
} else {
b[i + n] = cnt++;
b[i] = cnt++;
}
flag++;
}//然后按照分许的进行填充
yes;
for (int i = 1; i <= 2 * n; i++) { //最后打印2*n个数字

printf("%lld ", b[i]);
}

return 0;
}
``````
————————

### 链接

C. Boxes Packing

``````#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstring>
#include <unordered_set>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <sstream>
#include <queue>
#define int long long
#define yes cout<<"YES"<<'\n'
#define no 	cout<<"NO"<<'\n'

using namespace std;

const int N = 5100;
signed main () {
int n;
int a[N] = {0};
scanf("%lld", &n);
for (int i = 0; i < n; i++) {
scanf("%lld", &a[i]);
}
sort(a, a + n);
//因为是10的9次方,所以不能用st数组存,可以用map或者先排序然后判断有多少个
int ans = 0;
int cnt = 1;
for (int i = 1; i < n; i++) {
if (a[i] == a[i - 1]) {
cnt++;
} else {
ans = max(ans, cnt);
cnt = 1;
}

}
ans = max(ans, cnt);//通过上面的过程得到ans
cout << ans << '\n';//打印ans

return 0;
}
``````

### 链接

``````#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstring>
#include <unordered_set>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <sstream>
#include <queue>
#define int long long
#define yes cout<<"YES"<<'\n'
#define no 	cout<<"NO"<<'\n'

using namespace std;
const int N = 100008;

void solve() {
int n, m, s_x, s_y, d;
cin >> n >> m >> s_x >> s_y >> d;
int flag1 = 1, flag2 = 1;
//两个flag符合一个就可以
for (int i = 1; i <= n; i++) {
if (abs(i - s_x) + abs(1 - s_y) <= d) {
flag1 = 0;//先向右走,如果碰到激光直接失败
}
}
for (int j = 1; j <= m; j++) {
if (abs(n - s_x) + abs(j - s_y) <= d) {
flag1 = 0;//再向上走,如果碰到激光直接失败
}
}

for (int j = 1; j <= m; j++) {
if (abs(1 - s_x) + abs(j - s_y) <= d) {
flag2 = 0;//先向上走,如果碰到激光直接失败
}
}
for (int i = 1; i <= n; i++) {
if (abs(i - s_x) + abs(m - s_y) <= d) {
flag2 = 0;//再向右走,如果碰到激光直接失败
}
}

if (flag1 == 1 || flag2 == 1) {//满足以恶搞打印最短距离就可以
cout << abs(n - 1) + abs(m - 1) << '\n';
} else {
cout << -1 << '\n';//否则打印-1

}
}
signed main () {
int t;
cin >> t;
while (t) {
solve();
t--;
}

return 0;
}
``````

### 链接

Settlement of Guinea Pigs

``````#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstring>
#include <unordered_set>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <sstream>
#include <queue>
#define int long long
#define yes cout<<"YES"<<'\n'
#define no 	cout<<"NO"<<'\n'

using namespace std;

int b[200006] = {0};
signed main () {

int n;
scanf("%lld", &n);
if (n % 2 == 0) { //先判断奇数和偶数
no;

return 0;
}
int flag = 0;
int cnt = 1;
for (int i = 1; i <= n; i++) {
if (flag % 2 == 0) {
b[i] = cnt++;
b[i + n] = cnt++;
} else {
b[i + n] = cnt++;
b[i] = cnt++;
}
flag++;
}//然后按照分许的进行填充
yes;
for (int i = 1; i <= 2 * n; i++) { //最后打印2*n个数字

printf("%lld ", b[i]);
}

return 0;
}
``````