NOIP2017前恢复性训练

Emmmm....反正是又要从零开始了....


Day1 会写代码恢复性训练

小玉家的电费

不高兴的津津

津津的储蓄计划

铺地毯

级数求和

POJ 2386 也是好久没写八连块了...

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

const int MAXM = 100 + 10;
const int MAXN = 100 + 10;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {0, 1, 0, -1};

char map[MAXN][MAXM];
int N, M;

void dfs(int x, int y) {
    map[x][y] = '.';
    for(int i = 1; i <= 3; ++i) for(int j = 1; j <= 3; ++j) {
        int nx = dx[i] + x, ny = dy[j] + y;
        if(nx >= 1 && nx <= N && ny >= 0 && ny < M && map[nx][ny] == 'W') dfs(nx, ny);
    }
    return;
}

int main() {
    while( ~scanf("%d%d", &N, &M)) {
        int ans = 0;
        for(int i = 1; i <= N; ++i) scanf("%s", map[i]);
        for(int i = 1; i <= N; ++i) for(int j = 0; j < M; ++j) { if(map[i][j] == 'W') { dfs(i, j); ans++; } }
        printf("%d\n", ans);
    }
    return 0;
}


三连击 这题居然还想了一会儿能不能用数论...

洛谷的题解中有一个判断两个集合相加相乘的 那个结论显然是错的 本题能过只是因为三位数找不到反例

这里贴一下自己的程序

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;

bool vis[20];

inline bool check(int x) {
	int a = x / 100, b = (x % 100 - x % 10) / 10, c = x % 10;
	if(a == b || a == c || b == c || b == 0 || c == 0) return false;
	if(vis[a] == false && vis[b] == false && vis[c] == false) {
		vis[a] = true; vis[b] = true; vis[c] = true;
		return true;
	}
	else return false;
}

int main() {
	for(int a = 123; a <= 333; ++a) {
		memset(vis, false, sizeof(vis));
		int b = a * 2, c = a * 3;
		int x = a / 100, y = (a % 100 - a % 10) / 10, z = a % 10;
		if(x == y || x == z || y == z || y == 0 || z == 0) continue;
		vis[x] = true;
		vis[y] = true;
		vis[z] = true;
		if(check(b) && check(c)) printf("%d %d %d\n", a, b, c);
	}
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值