首页 > 其他分享 >2023/03/13刷题

2023/03/13刷题

时间:2023-03-17 21:22:25浏览次数:48  
标签:03 13 cout int long 刷题 yes include define

C. Boxes Packing

链接

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;
}

B. Deadly Laser

链接

B. Deadly Laser

凭借直觉可以发现,要不我们向右走走到最右边然后向上走,

要不2先向上走然后向右走

这是两种极限的情况

所以我们判断这两种极限情况

#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

链接

Settlement of Guinea Pigs

这个题还是理解的不够透彻就是偶数的是不可能组成相应的环的只有奇数才可以而且还是,在第i和第n+i个地方放上对应的数字,然后连续的从n+i+1和i+1的地方放上对应的数字

最后打印结果

#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;
}

标签:03,13,cout,int,long,刷题,yes,include,define
From: https://www.cnblogs.com/harper886/p/17228190.html

相关文章