Codeforces 975 前缀和二分算存活人数 思维离直线速度相同判平行
A
/* Huyyt */ #include <bits/stdc++.h> using namespace std; typedef long long ll; string a[1005]; int num[30]; map<ll, int> mp; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } int anser = 0; for (int i = 1; i <= n; i++) { memset(num, 0, sizeof(num)); int now = 0; for (int j = 0; j < a[i].size(); j++) { int cur = a[i][j] - 'a'; if (!num[cur]) { num[cur] = 1; now += (1LL << cur); } } if (!mp[now]) { anser++; mp[now]++; } } cout << anser << endl; }
B
/* Huyyt */ #include <bits/stdc++.h> using namespace std; typedef long long ll; string a[1005]; ll num[30]; ll ans[30]; int main() { ll anser = 0; for (int i = 1; i <= 14; i++) { cin >> num[i]; } for (int i = 1; i <= 14; i++) { ll now = 0; ll has; for (int j = 1; j <= 14; j++) { ans[j] = num[j]; } if (ans[i] == 0) { continue; } if (ans[i] >= 14) { ll bei = ans[i] / 14; has = ans[i] - 14 * bei; ans[i] = 0; for (int j = 1; j <= 14; j++) { ans[j] += bei; } int cur = i + 1; if (cur > 14) { cur -= 14; } while (has) { ans[cur]++; cur++; if (cur > 14) { cur -= 14; } has--; } } else { has = ans[i]; ans[i] = 0; int cur = i + 1; if (cur > 14) { cur -= 14; } while (has) { ans[cur]++; cur++; if (cur > 14) { cur -= 14; } has--; } } for (int j = 1; j <= 14; j++) { if (ans[j] % 2 == 0) { now += ans[j]; } } anser = max(now, anser); } cout << anser << endl; }
C
前缀和+二分
/* Huyyt */ #include <bits/stdc++.h> using namespace std; typedef long long ll; ll n, m; ll num[200005]; int getans(ll x) { int l = 1, r = n; int mid, ans; while (l <= r) { mid = (l + r) / 2; if (num[mid] > x) { ans = mid; r = mid - 1; } else { l = mid + 1; } } return ans; } int main() { ll now = 0; ll q; cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> num[i]; num[i] += num[i - 1]; } for (int i = 1; i <= m; i++) { cin >> q; now += q; if (now >= num[n]) { cout << n << endl; now = 0; } else { cout << n + 1 - getans(now) << endl; } } }
D
将点以离开原来所在直线的速度排序 相同速度的为一团
当且仅当两个速度方向一样(Vxi=Vxj Vyi=Vyj)的时候不会相交
/* Huyyt */ #include <bits/stdc++.h> using namespace std; typedef long long ll; const ll cheng = 2000000000; ll dian[200005]; ll k, anser; ll sum = 0; ll kb; ll vx, vy; map<ll, ll> mp; int main() { int n, m; cin >> n; cin >> k >> kb; for (int i = 1; i <= n; i++) { cin >> kb >> vx >> vy; sum = 1LL * vx * (1LL * cheng + 1); sum += vy; anser -= 2LL * mp[sum]; mp[sum]++; dian[i] = 1LL * vx * k - vy; } sum = 0; sort(dian + 1, dian + n + 1); for (int i = 1; i <= n; i++) { if (dian[i] == dian[i - 1]) { sum++; } else { anser += 1LL * sum * (sum - 1); sum = 1; } } ll add = 1LL * sum * (sum - 1); anser += add; cout << anser << endl; }