原題下載
答案
(Analysis by Jonathan Paulson - jonathanpaulson@gmail.com)
We can go along the squares in top-to-bottom, left-to-right order. For each square, we want to see if it starts a clue. It can start either a horizontal or vertical clue. For it to start a horizontal clue, the cell to the left must be blocked or off the board, and the two cells to the right must be clear and on the board. Similarly, to start a vertical clue, the cell above must be blocked or off the board, and the two cells below must be on the board and clear.
As we find cells that start a clue, we can add them to a list. Then at the end, we need to print the size of the list and its contents. Here's my C++ code:
#include <cstdio>
#include <vector>
#define MP make_pair
#define PB push_back
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
int main() {
ll R, C;
scanf("%lld %lld\n", &R, &C);
vector<vector<char> > G(R, vector<char>(C, ' '));
for(ll r=0; r<R; r++) {
char buf[100];
scanf("%s", buf);
for(ll c=0; c<C; c++) {
G[r][c] = buf[c];
}
}
vector<pll> A;
for(ll r=0; r<R; r++) {
for(ll c=0; c<C; c++) {
bool horizontal = (c+2<C && G[r][c]=='.' && G[r][c+1]=='.' && G[r][c+2]=='.' &&
(c==0 || G[r][c-1]=='#'));
bool vertical = (r+2<R && G[r][c]=='.' && G[r+1][c]=='.' && G[r+2][c]=='.' &&
(r==0 || G[r-1][c]=='#'));
if(horizontal || vertical) {
A.PB(MP(r+1, c+1));
}
}
}
printf("%lu\n", A.size());
for(pll clue : A) {
printf("%lld %lld\n", clue.X, clue.Y);
}
}
以上就是關于【USACO 2014 December Contest, Bronze Problem 2. Crosswords】的解答,如需了解學校/賽事/課程動態,可至翰林教育官網獲取更多信息。
往期文章閱讀推薦:
AI奧賽2026國家隊名單公布!?新賽季翰林助力直通IOAI全球總決賽!
NOAI人工智能奧賽 2026-2027 活動章程出爐:新規則必看!

? 2026. All Rights Reserved. 滬ICP備2023009024號-1