// // // // // // // // // // // // // //

2021.1.3 校测 题解报告

2021.1.3 校测 题解报告

前言:

做题情况:

T1 : 100 Pts

T2 : 100 Pts

T3 : 35 Pts

半个小时二百分 两个小时三十五分...

关于考试:

搜索专场

爆搜居多

T1 T2 都写了优化的 但是发现好像没有用 数据似乎不是太毒瘤 但是跑的快一点也是一点安慰了 虽然并没有什么鸟用就是了

T3 写了优化 但是好像是负优化...

另:

题目什么的懒得粘了.... 就这样吧

下次来了再补

T1 math

/*
  Time: 1.3
  Worker: Blank_space
  Source: Problem 1 数学题
*/
/*--------------------------------------------*/
#include<cstdio>
using namespace std;
/*--------------------------------------头文件*/
const int A = 1e4 + 7;
const int B = 1e5 + 7;
const int C = 1e6 + 7;
const int D = 1e7 + 7;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int FFF = 0x8fffffff;
/*------------------------------------常量定义*/
int n, p, s, ans, a[11];
int d[11] = {0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55};
/*------------------------------------变量定义*/
inline int read() {
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
/*----------------------------------------快读*/
void print()
{
	for(int i = 1; i <= n; i++) printf("%d ", a[i]);
	puts("");
}
void dfs(int t, int sum, int last)
{
	if(sum > s) return ;
	if(t > 1 && sum + (n - t + 1) * last + d[n - t + 1] * p < s) return ;
	if(t == n + 1)
	{
		if(sum == s) ans++;
//		print();
		return ;
	}
	if(t == 1)
	for(int i = 1; i <= s - n + 1; i++) a[t] = i, dfs(t + 1, sum + i, i);
	else
	for(int i = -p; i <= p; i++)
		if(last + i > 0) a[t] = last + i, dfs(t + 1, sum + last + i, last + i);
}
/*----------------------------------------函数*/
int main()
{
	freopen("math.in", "r", stdin);
	freopen("math.out", "w", stdout);
    n = read(); s = read(); p = read();
    if(!p) {printf("%d", s % n == 0 ? 1 : 0); return 0;}
    dfs(1, 0, 0);
    printf("%d", ans);
	return 0;
}

T2 grid

/*
  Time: 1.3
  Worker: Blank_space
  Source: Problem 2 网格
*/
/*--------------------------------------------*/
#include<cstdio>
#include<queue>
using namespace std;
/*--------------------------------------头文件*/
const int A = 1e4 + 7;
const int B = 1e5 + 7;
const int C = 1e6 + 7;
const int D = 1e7 + 7;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int FFF = 0x8fffffff;
/*------------------------------------常量定义*/
int n, sx, sy, tx, ty, dis1[1010][1010], dis2[1010][1010];
int dx[5] = {0, 1, -1, 0, 0};
int dy[5] = {0, 0, 0, 1, -1};
int vis1[1010][1010], vis2[1010][1010];
bool mp[1010][1010], p;
struct node {
	int x, y;
};
queue <node> q1;
queue <node> q2;
/*------------------------------------变量定义*/
inline int read() {
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
/*----------------------------------------快读*/
void bfs()
{
	while(!q1.empty() && !q2.empty())
	{
		if(q1.size() <= q1.size() && !q1.empty())
		{
			node h = q1.front(); q1.pop();
			int x = h.x, y = h.y;
			for(int i = 1; i <= 4; i++)
			{
				int xx = x + dx[i], yy = y + dy[i];
				if(xx < 1 || xx > n || yy < 1 || yy > n || vis1[xx][yy] || mp[xx][yy]) continue;
				vis1[xx][yy] = vis1[x][y] + 1;
				if(vis2[xx][yy]) {printf("%d", vis1[xx][yy] + vis2[xx][yy] - 2); p = 1; return ;}
				q1.push((node){xx, yy});
			}
		}
		if(q1.size() > q2.size() && !q2.empty())
		{
			node h = q2.front(); q2.pop();
			int x = h.x, y = h.y;
			for(int i = 1; i <= 4; i++)
			{
				int xx = x + dx[i], yy = y + dy[i];
				if(xx < 1 || xx > n || yy < 1 || yy > n || vis2[xx][yy] || mp[xx][yy]) continue;
				vis2[xx][yy] = vis2[x][y] + 1;
				if(vis1[xx][yy]) {printf("%d", vis1[xx][yy] + vis2[xx][yy] - 2); p = 1; return ;}
				q2.push((node){xx, yy});
			}
		}
	}
}
/*----------------------------------------函数*/
int main()
{
//	freopen("out", "r", stdin);
	freopen("grid.in", "r", stdin);
	freopen("grid.out", "w", stdout);
    n = read();
    for(int i = 1; i <= n; i++)
    	for(int j = 1; j <= n; j++) mp[i][j] = read();
    sx = read(); sy = read(); tx = read(); ty = read();
    q1.push((node){sx, sy}); q2.push((node){tx, ty});
    vis1[sx][sy] = 1; vis2[tx][ty] = 1;
    bfs();
    if(!p) puts("-1");
	return 0;
}

T3 gokigen

/*
  Time: 1.3
  Worker: Blank_space
  Source: C 戈兰斜
  我真的不行了... 
*/
/*--------------------------------------------*/
#include<cstdio>
#include<iostream>
using namespace std; 
/*--------------------------------------头文件*/
const int A = 1e4 + 7;
const int B = 1e5 + 7;
const int C = 1e6 + 7;
const int D = 1e7 + 7;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int FFF = 0x8fffffff;
/*------------------------------------常量定义*/
int n, mp[10][10], fa[110], cur[10][10], limit[10][10], c[10][10], ans[10][10];
bool p, vis;
int dx[5] = {0, 0, 1, 0, 1};
int dy[5] = {0, 0, 0, 1, 1};
/*------------------------------------变量定义*/
inline int read() {
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
/*----------------------------------------快读*/
int find(int x) {return !fa[x] ? x : find(fa[x]);}
bool check(int x, int y)
{
	if(mp[x][y] == -1) return 1;
	if(cur[x][y] <= mp[x][y] && cur[x][y] + limit[x][y] >= mp[x][y]) return 1;
	return 0;
}
void dfs(int x, int y)
{
	if(y == n) y = 1, x++;
	if(x == n) {p = 1; return ;}
	cur[x][y]++; cur[x + 1][y + 1]++;//连边 
	limit[x][y]--; limit[x + 1][y + 1]--;//边的限制 
	limit[x + 1][y]--; limit[x][y + 1]--;//可连的边
	vis = 0;
	for(int i = 1; i <= 4; i++)
	{
		int xx = x + dx[i], yy = y + dy[i];
		if(!check(xx, yy)) {vis = 1; break;}//没救了 
	}
	if(!vis)
	{
//		int u = find(c[x][y]), v = find(c[x + 1][y + 1]);
		int u = find((x - 1) * n + y), v = find(x * n + y + 1);
		if(u != v)
		{
			ans[x][y] = 1; fa[u] = v;
			dfs(x, y + 1);
			if(p) return ;
			fa[u] = 0;
		}
	}
	cur[x][y]--; cur[x + 1][y + 1]--;
	cur[x + 1][y]++; cur[x][y + 1]++;
	vis = 0;
	for(int i = 1; i <= 4; i++)
	{
		int xx = x + dx[i], yy = y + dy[i];
		if(!check(xx, yy)) {vis = 1; break;}
	}
	if(!vis)
	{
//		int u = find(c[x + 1][y]), v = find(c[x][y + 1]);
		int u = find(x * n + y), v = find((x - 1) * n + y + 1);
		if(u != v)
		{
			ans[x][y] = 0; fa[u] = v;
			dfs(x, y + 1);
			if(p) return ;
			fa[u] = 0;
		}
	}
	cur[x + 1][y]--; cur[x][y + 1]--;
	limit[x][y]++; limit[x + 1][y + 1]++;
	limit[x + 1][y]++; limit[x][y + 1]++;
}
/*----------------------------------------函数*/
int main()
{
  	freopen("gokigen.in","r",stdin);
  	freopen("gokigen.out","w",stdout);
    n = read() + 1; int k = 0;
    for(int i = 1; i <= n; i++)
    	for(int j = 1; j <= n; j++)
    	{
    		char s; cin >> s;
    		if(s >= '0' && s <= '9') mp[i][j] = s - 48;
    		else mp[i][j] = -1;
    		c[i][j] = ++k; limit[i][j] = 4;
    		if((i == 1 || i == n) && (j == 1 || j == n)) limit[i][j] = 1;
    		else if(i == 1 || i == n || j == 1 || j == n) limit[i][j] = 2;
    	}
//    for(int i = 1; i <= k; i++) fa[i] = i;
    dfs(1, 1); n--;
    for(int i = 1; i <= n; i++)
    {
    	for(int j = 1; j <= n; j++)
    		if(ans[i][j]) printf("\\");
    		else printf("/");
    	puts("");
    }
	return 0;
}
posted @ 2021-01-03 22:09  Blank_space  阅读(66)  评论(0编辑  收藏  举报
// // // // // // //