intmain(){ cin >> x >> y >> z; int f1 = 0, f2 = 0, f3 = 0; if (x + z > y) f1 = 1; if (y + z > x) f2 = 1; if (abs(x - y) <= z) f3 = 1; int sum = f1 + f2 + f3; if (sum > 1) puts("?"); elseif (f1) puts("+"); elseif (f2) puts("-"); elseputs("0"); return0; }
intmain(){ cin >> n; int m = (n + 1) / 2 + (n + 1) % 2; cout << m << '\n'; int c = 1; for (int i = 1; c <= n && i <= m; c++, i++) { printf("%d %d\n", 1, i); } for (int i = 2; c <= n && i <= m; c++, i++) { printf("%d %d\n", i, m); } return0; }
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<utility> #ifdef XLor #define dbg(args...) do {cout << #args << " ->"; err(args);} while (0) #else #define dbg(...) #endif void err() {std::cout << std::endl;} template<typename T, typename...Args> void err(T a, Args...args){std::cout << a << ' '; err(args...);} #define ms(a,b) memset(a,b,sizeof(a)) using namespace std; typedef long long ll; typedef pair<int,int> PII; const int mod = 998244353; const int inf = 1 << 30; const int maxn = 200000 + 5; int n, a[maxn], b[maxn]; int main() { scanf("%d", &n); int my = 0, dk = 0; for (int i = 1; i <= n; i++) { scanf("%d", a + i); if (a[i] == 1) my = i; } for (int i = 1; i <= n; i++) { scanf("%d", b + i); if (b[i] == 1) dk = i; } if (my) { int mx = 0; for (int i = 1; i <= n; i++) { if (b[i] == 0) continue; mx = max(mx, i - b[i] + 1); } printf("%d", mx + n); } else if (dk == n) { int f = 1; for (int i = 1; i < n; i++) { if (b[i] == 0) continue; if (b[i] - 2 < i) { f = 0; break; } } if (f) printf("%d", n - 1); else printf("%d", n + n); } else { int f = 1; for (int i = dk + 1; i <= n; i++) { if (b[i] == 0) { f = 0; break; } if (b[i] - b[i - 1] != 1) { f = 0; break; } } if (f) { int f = 1; int cur = n - dk + 1; for (int i = 1; i < dk; i++) { if (b[i] == 0) continue; // dbg(b[i], cur); if (b[i] - cur - 1 < i) { f = 0; break; } } if (f) printf("%d", dk - 1); else printf("%d", n + dk); } else { int mx = 0; for (int i = dk + 1; i <= n; i++) { if (b[i] == 0) continue; // dbg(i - b[i] - dk + 1); mx = max(mx, i - b[i] - dk + 1); } // dbg(mx); printf("%d", dk + n + mx); } } return 0; }
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<utility> #ifdef XLor #define dbg(args...) do {cout << #args << " ->"; err(args);} while (0) #else #define dbg(...) #endif void err() {std::cout << std::endl;} template<typename T, typename...Args> void err(T a, Args...args){std::cout << a << ' '; err(args...);} #define ms(a,b) memset(a,b,sizeof(a)) using namespace std; typedef long long ll; typedef pair<int,int> PII; const int mod = 998244353; const int inf = 1 << 30; const int maxn = 200000 + 5; int n, f[maxn], siz[maxn]; vector<int> edge[maxn]; int dfs(int u, int ff) { siz[u] = 1; int r = 1; for (int& v: edge[u]) { if (v == ff) continue; r = 1ll * r * dfs(v, u) % mod; // if (siz[v] > 1) r = 2ll * r % mod; r = 1ll * r * (int)(edge[v].size()) % mod; siz[u] += siz[v]; } dbg(edge[u].size()); int sz = (int)edge[u].size(); if (u != 1) sz--; return 1ll * r * f[sz] % mod; } int main() { f[0] = 1; for (int i = 1; i < maxn; i++) f[i] = 1ll * i * f[i - 1] % mod; scanf("%d", &n); for (int i = 2, u, v; i <= n; i++) { scanf("%d%d", &u, &v); edge[u].push_back(v); edge[v].push_back(u); } int ans = dfs(1, 0); cout << 1ll * n * ans % mod; return 0; }