1 条题解
-
0
Initially, the obvious case one might first consider is an upright right triangle (specifically, the triangle with one of its sides parallel to the -axis). This side can only be made with two points in the form and . We only need to search third point. Turns out, the third point can be any other unused vertex! If the third point has , then it will be an upright triangle, but if the third point has , it will simply be upside down.
One of the other case is in the form of . Let's see why this is a right triangle. Recall that in right triangle, the sum of the squares of two of the sides must equal to the square of the third side. The length between the first and the second point is because it is the diagonal of by unit block. Similarily, the second and third point also has length . Obviously, the length between the first and third point is . Since we have , this is certainly a right triangle. Of course, we can flip the values of each point and it will still be a valid right triangle, just upside down.
/** * author: 小飞侠 * created: 2024.11.07 00:07:48 */ #include <bits/stdc++.h> using namespace std; #define ls u << 1 #define rs u << 1 | 1 #define LL long long #define int long long #define PII pair <int, int> #define fi first #define se second #define pub push_back #define pob pop_back #define puf push_front #define pof pop_front #define lb lower_bound #define ub upper_bound #define i128 __int128 #define pcnt(x) __builtin_popcount(x) #define mem(a,goal) memset(a, (goal), sizeof(a)) #define rep(x,start,end) for(int x = (start) - ((start) > (end)); x != (end) - ((start) > (end)); ((start) < (end) ? x ++ : x --)) #define aLL(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() const int INF = 998244353; const int P = 1e9 + 7; const int N = 2e5 + 5; void solve() { int n; cin >> n; set<PII> s; unordered_map<int, int> mp; for(int i = 0 ; i < n; ++ i) { int x, y; cin >> x >> y; s.insert({x,y}); mp[x] ++; } int ans = 0; for(auto [a, b] : mp) if(b == 2) ans += n - 2; for(auto [a, b] : s) { if(s.count({a - 1, b ^ 1}) && s.count({a + 1, b ^ 1})) ans ++; } cout << ans << '\n'; } signed main() { int t; cin >> t; while(t --) solve(); return 0; }
- 1
信息
- ID
- 5472
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- (无)
- 递交数
- 2
- 已通过
- 1
- 上传者