您的位置:首页 > 其它

NOIP2017前恢复性训练

2017-09-11 18:32 330 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  POJ 洛谷