20/07/12测试

T1

搜索

和以前做过一道关于排序的题有亿点点像,看到这么小的数据范围竟然脑抽没去想搜索....

直接暴力枚举目前的点在哪个矩形里即可。

#include <bits/stdc++.h>
using namespace std;

const int maxn = 60;

int n, k, ans= 0x3fffff;

struct node{
	int x, y;
}a[maxn];

struct matrix{
	int cnt, maxx, minx, miny, maxy;
	void add_node(int x, int y){
		if(!cnt){
			maxx = minx = x;
			miny = maxy = y;
			cnt = 1;
		}else{
			minx = min(minx, x);
			maxx = max(maxx, x);
			miny = min(miny, y);
			maxy = max(maxy, y);
		}
	}
	int get_s(){
		if(!cnt) return 0;
		return (maxx-minx)*(maxy-miny);	
	}
}m[4];

int judge(matrix a, matrix b){
	if(a.maxy < b.miny or b.maxy < a.miny) return 1;
	if(a.maxx < b.minx or b.maxx < a.minx) return 1;
	return 0;//判断矩形是否相交,不相交只有四种情况,可画图理解
}

int check(){
	for(int i = 0; i < k; i ++){
		for(int j = i+1; j < k; j ++){
			if(!judge(m[i],m[j])) return 0;//判断四个矩形是否相交
		}
	}
	return 1;
}

void DFS(int now, int s){
	if(s > ans) return;
	if(now > n){
		if(check()){
			ans = min(ans, s);
			return;
		}else return;
	}
	matrix cmp;
	for(int i = 0; i < k; i ++){
		cmp = m[i];
		m[i].add_node(a[now].x, a[now].y);
		DFS(now+1, s-cmp.get_s()+m[i].get_s());
		m[i] = cmp;
	}
}

signed main(){
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i ++){
		scanf("%d%d", &a[i].x, &a[i].y);
	}
	DFS(1,0);
	printf("%d", ans);
	return 0;
}

T2

筛法

受欧拉筛的启示,我们换个方向思考,考虑这个数是几个数的倍数

#include <bits/stdc++.h>
using namespace std;

const int maxn = 1000000+10;

int n, sum, a[maxn], tong[maxn], ans[maxn];

signed main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; ++ i){
		scanf("%d", &a[i]);
		tong[a[i]] ++;
		sum = max(a[i], sum);
	}
	for(int i = 1; i <= sum; ++ i){
		if(!tong[i]) continue;
		for(int j = 1; j*i<= sum; ++ j){
			ans[i*j] += tong[i];
		}
	}
	for(int i = 1; i <= n; ++ i){
		printf("%d
", ans[a[i]]-1);
	}
	return 0;
}

T3

区间DP

弃坑

本来是打算弃坑的....但教练亲自理解题意+理解题解,躬身入局,帮助我们进行理解,我也不好意思弃坑了啊qaq,反正现在不知道干啥所以来填坑了--20/07/14

填坑失败qaq

原文地址:https://www.cnblogs.com/Vanyun/p/13290031.html