2017蓝桥杯省赛A组部分题题解

方块分割:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<map>
#include<stack>
#include<cmath>
#include<string>
using namespace std;
typedef long long ll;

int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 };
int vis[10][10];
int ans = 0;

void dfs(int x, int y)
{
	if (x == 0 || y == 6 || x == 6 || y == 0)
	{
		ans++;
		return;
	}
	for (int i = 0; i < 4; i++)
	{
		int xx = x + dx[i];
		int yy = y + dy[i];
		if (xx < 0 || xx>6 || yy < 0 || yy>6)
			continue;
		if (!vis[xx][yy])
		{
			vis[xx][yy] = 1;
			vis[6 - xx][6 - yy] = 1;
			dfs(xx, yy);
			vis[xx][yy] = 0;
			vis[6 - xx][6 - yy] = 0;
		}
	}
}

int  main()
{
	vis[3][3] = 1;
	dfs(3, 3);
	printf("%d\n", ans / 4);
	return 0;
}

包子凑数:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<map>
#include<stack>
#include<cmath>
#include<string>
using namespace std;
typedef long long ll;
const int maxn = 10010;
int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 };

int n, g, a[105], dp[maxn];

int gcd(int a, int b)
{
	return b == 0 ? a : gcd(b, a%b);
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	g = a[1];
	for (int i = 2; i <= n; i++)
		g = gcd(g, a[i]);
	if (g != 1)
	{
		printf("INF\n");
		return 0;
	}

	dp[0] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = 0; j + a[i] < maxn; j++)
			if (dp[j])
				dp[j + a[i]] = 1;
	int cnt = 0;
	for (int i = maxn - 1; i >= 0; i--)
		if (dp[i] == 0)
			cnt++;
	printf("%d\n", cnt);
	return 0;
}

分巧克力:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<map>
#include<stack>
#include<cmath>
#include<string>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 };

int n, k, h[maxn], w[maxn];

bool check(int x)
{
	int cnt = 0;
	for (int i = 1; i <= n; i++)	
		cnt += (h[i] / x)*(w[i] / x);
	return cnt >= k;
}

int main()
{
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++)	scanf("%d", &h[i]);
	for (int i = 1; i <= n; i++)	scanf("%d", &w[i]);

	int l = 1, r = maxn, mid;
	while (l <= r)
	{
		mid = (l + r) / 2;
		if (check(mid))
			l = mid + 1;
		else
			r = mid - 1;
	}
	printf("%d\n", l - 1);
	return 0;
}

油漆面积:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<map>
#include<stack>
#include<cmath>
#include<string>
using namespace std;
typedef long long ll;
const int maxn = 1e4 + 10;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1

double x[maxn];

struct seg
{
	double l, r, h;
	int	cnt;
	seg(){}
	seg(double a, double b, double c, int d):l(a),r(b),h(c),cnt(d){}
}edge[maxn];

bool cmp(seg a, seg b)
{
	return a.h < b.h;
}

struct Node
{
	double len;
	int cnt;
}node[maxn * 4];

void pushdown(int l, int r, int rt)
{
	if (node[rt].cnt)
		node[rt].len = x[r + 1] - x[l];
	else if (l == r)
		node[rt].len = 0;
	else
		node[rt].len = node[rt << 1].len + node[rt << 1 | 1].len;
}

void update(int L, int R, int l, int r, int rt, int v)
{
	if (L <= l&&R >= r)
	{
		node[rt].cnt += v;
		pushdown(l, r, rt);
		return;
	}
	int m = (l + r) >> 1;
	if (L <= m)
		update(L, R, lson, v);
	if (R > m)
		update(L, R, rson, v);
	pushdown(l, r, rt);
}


int main()
{
	double a, b, c, d;
	int tot, n, cas = 1;
	scanf("%d", &n);
	tot = 0;
	double ans = 0;
	memset(node, 0, sizeof(node));
	for (int i = 1; i <= n; i++)
	{
		scanf("%lf%lf%lf%lf", &a, &b, &c, &d);
		x[tot] = a;
		edge[tot++] = seg(a, c, b, 1);
		x[tot] = c;
		edge[tot++] = seg(a, c, d, -1);
	}
	sort(x, x + tot);
	sort(edge, edge + tot, cmp);
	int maxlen = unique(x, x + tot) - x;

	for (int i = 0; i < tot; i++)
	{
		int l = lower_bound(x, x + maxlen, edge[i].l) - x;
		int r = lower_bound(x, x + maxlen, edge[i].r) - x - 1;
		update(l, r, 0, maxlen, 1, edge[i].cnt);
		ans += node[1].len*(edge[i + 1].h - edge[i].h);
	}
	printf("%f\n", ans);//自行修改类型精度
	return 0;
}


猜你喜欢

转载自blog.csdn.net/Egqawkq/article/details/79643053