補題連接:Hereios
題意:高橋(Takahashi )如今要去距離家 \(D\) 米的地方面基,請問若是以最高速度 \(S\) 可否再 \(T\) 時刻準時到達?spa
\(cout << (d / s <= t ? "Yes" : "No");\)code
注意點使用
float
ci
注意到 S
和 T
長度很小,全部能夠枚舉get
int main() { ios_base::sync_with_stdio(false), cin.tie(0); string s, t; cin >> s >> t; int n = s.size(), m = t.size(); int ans = m; for (int start = 0; start <= n - m; ++start) { int cnt = 0; for (int i = 0; i < m; ++i) if (t[i] != s[start + i]) cnt++; ans = min(ans, cnt); } cout << ans << "\n"; return 0; }
維護後綴和,記得取模便可string
using ll = long long; const ll mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(false), cin.tie(0); int n; cin >> n; ll a[n + 1], lst[n + 2] = {}; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = n; i >= 1; --i) { lst[i] = (lst[i + 1] % mod + (i == n ? 0 : a[i + 1]) % mod) % mod; } ll ans = 0; for (int i = 1; i < n; ++i) { ans = (ans + a[i] * lst[i] + mod) % mod; } cout << ans % mod << "\n"; return 0; }
題意:給定 n 我的的 m 對朋友關係,如今進行最小化分組要是每一個組裏都沒有互相認識的人,hash
思路:並查集,求出最大連通份量便可it
const int N = 2e5 + 7; int f[N], Siz[N]; int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); } void merge(int x, int y) { x = find(x), y = find(y); if (x != y) f[x] = y, Siz[y] += Siz[x]; } int main() { ios_base::sync_with_stdio(false), cin.tie(0); int n, m; for (int i = 1; i <= N - 1; ++i) f[i] = i, Siz[i] = 1; cin >> n >> m; while (m--) { int x, y; cin >> x >> y; merge(x, y); } sort(Siz, Siz + n + 1); cout << Siz[n]; return 0; }
質因數分解,統計含有每一個質因子的數的個數,而後求出最大的個數。若是這個值爲 \(1\),說明兩兩互質;若是這個值小於\(N\),說明整體互質。io
int cnt[1 << 20]; int all = 0; bool isp[1 << 20]; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { ios_base::sync_with_stdio(false), cin.tie(0); int n; cin >> n; for (int i = 0, x; i < n; ++i) { cin >> x; cnt[x]++; all = gcd(all, x); } bool f = true; for (int i = 2; i < (1 << 20); ++i) { int sum = 0; for (int j = i; j < (1 << 20); j += i) sum += cnt[j]; if (sum > 1) f = false; } cout << (f ? "pairwise coprime" : all == 1 ? "setwise coprime" : "not coprime"); return 0; }
AtCoder Beginner Contest 177class