Loading Similar Posts
#includeusing namespace std; int TestCases, L, R; int main() { cin >> TestCases; while (TestCases--) { cin >> L >> R; cout << (__gcd(L, R)==1?"Yes":"No") << "\n"; } }
int n, m, shops[3000003], L, R; int main() { cin >> TestCases; while (TestCases--) { cin >> n >> m; for (int i = 0; i <= n; i++) shops[i] = 0; for (int i = 0; i < m; i++) cin >> L >> R, shops[L]++, shops[++R]++; for (int i = 1; i <= n; i++) shops[i] += shops[i-1], ord.pb(mp(-shops[i],i)); sort(shops.begin(), shops.end()); for (int i = 0; i < 3; i++) reord.insert(shops[i].second); for (auto c: reord) cout << c << " ";cout << endl; } return 0; }
#includeusing namespace std; vector g[1000010]; vector vis[1000010]; int n, m, area, ans = 0; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; bool dry = false; bool check(int x, int y) { if (min(x, y) < 0 or x >= n or y >= m) return false; return true; } void dfs(int x, int y) { vis[x][y] = true; ++area; for (int i = 0; i < 4; i++) { int a = x+dx[i], b = y+dy[i]; if (check(a, b) == false) { dry = true; } else { if (vis[a][b] == false and g[a][b]=='.') dfs(a, b); } } } int main() { cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { g[i].push_back('.'); vis[i].push_back(false); } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> g[i][j]; vis[i][j] = false; } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (vis[i][j] == false) { dry = false; area = 0; if (vis[i][j] == false and g[i][j] == '.') dfs(i, j); if (dry == false) ans += area; } } } cout << ans << "\n"; }
http://thejoboverflow.com/p/p49/#p61