int solve(int x1, int y1, int x2, int y2, int cx, int cy, int R)
{
int count = 0;
int R_squared = R * R;
for (int y = y1; y <= y2; ++y)
{
int dy_squared = (y - cy) * (y - cy);
if (dy_squared > R_squared)
continue;
int dx = static_cast<int>(sqrt(R_squared - dy_squared));
int min_x = std::max(x1, cx - dx);
int max_x = std::min(x2, cx + dx);
if (min_x <= max_x)
{
count += (max_x - min_x + 1);
}
}
return count;
}
int main()
{
int x1 = 1, y1 = 1, x2 = 100000, y2 = 100000, cx = 50000, cy = 50000, R = 1000;
cin >> x1 >> y1 >> x2 >> y2 >> cx >> cy >> R;
cout << solve(x1, y1, x2, y2, cx, cy, R) << endl;
return 0;
}
//Cordinates sprinkler โ
{
int count = 0;
int R_squared = R * R;
for (int y = y1; y <= y2; ++y)
{
int dy_squared = (y - cy) * (y - cy);
if (dy_squared > R_squared)
continue;
int dx = static_cast<int>(sqrt(R_squared - dy_squared));
int min_x = std::max(x1, cx - dx);
int max_x = std::min(x2, cx + dx);
if (min_x <= max_x)
{
count += (max_x - min_x + 1);
}
}
return count;
}
int main()
{
int x1 = 1, y1 = 1, x2 = 100000, y2 = 100000, cx = 50000, cy = 50000, R = 1000;
cin >> x1 >> y1 >> x2 >> y2 >> cx >> cy >> R;
cout << solve(x1, y1, x2, y2, cx, cy, R) << endl;
return 0;
}
//Cordinates sprinkler โ
Contiguous substring โ
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
int main() {
int n, a, b;
cin >> n >> a >> b;
map<pair<int, int>, int> slope_map;
for (int i = 0; i < n; ++i) {
int x, y;
cin >> x >> y;
int dy = y - b;
int dx = x - a;
int g = gcd(dx, dy);
dy /= g;
dx /= g;
if (dx < 0) {
dy = -dy;
dx = -dx;
} else if (dx == 0) {
dy = abs(dy);
}
slope_map[{dy, dx}]++;
}
int aa = 0;
for (auto &entry : slope_map) {
int count = entry.second;
aa += count * (count - 1) / 2;
}
cout << aa << endl;
return 0;
}
MAQ Software โ
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <bits/stdc++.h>
using namespace std;
bool isVowel(char c) {
return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
}
vector<int> hasVowels(vector<string>& strArr, vector<string>& queries) {
int n = strArr.size();
vector<int> prefix(n + 1, 0);
for (int i = 0; i < n; i++) {
bool startsAndEndsWithVowel = isVowel(strArr[i][0]) && isVowel(strArr[i].back());
prefix[i + 1] = prefix[i] + (startsAndEndsWithVowel ? 1 : 0);
}
vector<int> results;
for (string query : queries) {
int l, r;
sscanf(query.c_str(), "%d-%d", &l, &r);
l--; r--;
int count = prefix[r + 1] - prefix[l];
results.push_back(count);
}
return results;
}
IBM HASVOWELโ
class UnionFind:
def __init__(self, n):
self.parent = list(range(n))
self.rank = [0] * n
self.components = n
def find(self, x):
if self.parent[x] != x:
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def union(self, x, y):
px, py = self.find(x), self.find(y)
if px != py:
if self.rank[px] < self.rank[py]:
self.parent[px] = py
elif self.rank[px] > self.rank[py]:
self.parent[py] = px
else:
self.parent[py] = px
self.rank[px] += 1
self.components -= 1
def minOperations(compNodes, compFrom, compTo):
uf = UnionFind(compNodes + 1)
for u, v in zip(compFrom, compTo):
uf.union(u, v)
operations = uf.components - 2
return operations if operations >= 0 else -1
IBM computer networks โ
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <unordered_map>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
class designCache {
public:
class Node {
public:
int key;
int val;
Node* prev;
Node* next;
Node(int key, int val) {
this->key = key;
this->val = val;
}
};
Node* head = new Node(-1, -1);
Node* tail = new Node(-1, -1);
int cap;
unordered_map<int, Node*> m;
designCache(int capacity) {
cap = capacity;
head->next = tail;
tail->prev = head;
}
void addNode(Node* newnode) {
Node* temp = head->next;
newnode->next = temp;
newnode->prev = head;
head->next = newnode;
temp->prev = newnode;
}
void deleteNode(Node* delnode) {
Node* prevv = delnode->prev;
Node* nextt = delnode->next;
prevv->next = nextt;
nextt->prev = prevv;
}
int get(int key) {
if (m.find(key) != m.end()) {
Node* resNode = m[key];
int ans = resNode->val;
m.erase(key);
deleteNode(resNode);
addNode(resNode);
m[key] = head->next;
return ans;
}
return -1;
}
void put(int key, int value) {
if (m.find(key) != m.end()) {
Node* curr = m[key];
m.erase(key);
deleteNode(curr);
}
if (m.size() == cap) {
m.erase(tail->prev->key);
deleteNode(tail->prev);
}
addNode(new Node(key, value));
m[key] = head->next;
}
};
int main() {
string attribs, attrib;
getline(cin, attribs);
stringstream ss(attribs);
int capacity, key, val;
cin >> capacity;
designCache obj(capacity);
while (getline(ss, attrib, ' ')) {
if (attrib == "put") {
cin >> key >> val;
obj.put(key, val);
cout << "null ";
} else if (attrib == "get") {
cin >> key;
val = obj.get(key);
cout << val << " ";
}
}
return 0;
}
Atlan Fellowship โ
def longestChain(ws):
wset, memo = set(ws), {}
def cl(w):
if w not in wset: return 0
if w in memo: return memo[w]
ml = 1
for i in range(len(w)):
ml = max(ml, 1 + cl(w[:i] + w[i+1:]))
memo[w] = ml
return ml
return max(cl(w) for w in ws)
UI Path longest chainโ
def waysToChooseSum(lowLimit, highLimit):
ds, mw, wc = [0] * 46, 0, 0
for n in range(lowLimit, highLimit + 1):
s = sum(int(d) for d in str(n))
ds[s] += 1
mw = max(mw, ds[s])
for c in ds:
if c == mw:
wc += 1
return [mw, wc]
Way to chooose sumโ
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include<bits/stdc++.h>
using namespace std;
class Trie {
public:
map<int, int> hot;
map<int, unordered_map<int, int>> trie;
map<int, int> index;
int curr = 0;
void insert(string& s, int ind) {
int p = 0;
for (int i = 0; i < s.size(); i++) {
int temp = s[i] - '0';
if (trie.count(p) == 0 || trie[p].count(temp) == 0) {
trie[p][temp] = ++curr;
}
p = trie[p][temp];
index[p] = ind;
}
hot[p]++;
}
int longest_pref(string& s, int ind) {
int p = 0;
int last_ind = -1;
for (int i = 0; i < s.size(); i++) {
if (trie.count(p) == 0 || trie[p].count(s[i] - '0') == 0) break;
p = trie[p][s[i] - '0'];
last_ind = index[p];
}
insert(s, ind);
return last_ind;
}
};
vector<int> autocomplete(vector<string> command) {
vector<int> result;
Trie* t = new Trie();
for (int i = 0; i < command.size(); i++) {
int val = t->longest_pref(command[i], i);
if (val == -1 && i == 0) result.push_back(0);
else if (val == -1) result.push_back(i);
else result.push_back(val + 1);
}
delete t;
return result;
}
BNY (intern) โ
๐2
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <bits/stdc++.h>
using namespace std;
vector<long> bitwiseEquations(vector<long> a, vector<long> b)
{
int n = a.size();
vector<long> ans(n);
for (int i = 0; i < n; i++)
{
if (a[i] < b[i])
{
ans[i] = 0;
continue;
}
long x = 0, y = 0;
long diff = (a[i] - b[i]) / 2;
for (int j = 0; j < 64; j++)
{
if (b[i] & (1LL << j))
{
if ((diff & (1LL << j)) == 0)
{
y |= (1LL << j);
}
else
{
x = 0;
y = 0;
break;
}
}
else
{
if ((diff & (1LL << j)))
{
x |= (1LL << j);
y |= (1LL << j);
}
}
}
ans[i] = 2 * x + 3 * y;
}
return ans;
}
bitwiseEquations
BNY (Intern) โ