2024 ICPC 陕西省赛 M. Window Decoration

M. Window Decoration

time limit per test: 1 second

memory limit per test: 256 megabytes

There is a window with dimensions 100cm×100cm and n square window decorations, each with a diagonal length of 2cm. Establish a coordinate system with the origin at the bottom left corner of the window (0,0) and the top right corner at (100,100). The center of the i-th window decoration is placed at a non-edge integer coordinate point (xi,yi) (1≤xi,yi≤99), and the diagonals of the window decorations are parallel to the coordinate axes.

Find out the total area of the window covered by at least one window decoration.

Input

The first line contains an integer n (1≤n≤10000).

Following are n lines, each containing two integers xi,yi (1≤xi,yi≤99), as described above.

Output

Output a single line with a single real number: area of the window covered by at least one window decoration.

Your answer is considered correct if its absolute or relative error does not exceed 10^{-4}. Formally, let your answer be a, and the jury's answer be b. Your answer is accepted if and only if \frac{|a-b|}{max(1,|b|)}\leq 10^{-4}.

Example

input

5

1 1

2 1

3 2

5 5

5 5

output

7.5

Note

Explanation for the first example is shown as follows:

【思路分析】

思维+数学。用map去重,找出相邻xi和yi即可。

#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <cstring>
#include <iomanip>

#define i64 long long

using namespace std;

i64 n;

bool searchFirst(const vector<pair<i64,i64>>& arr,i64 val,i64 se){
    for (auto & i : arr) {
        if (i.first == val&&i.second == se) return true;
    }
    return false;
}

bool searchSecond(vector<pair<i64,i64>> arr,i64 val,i64 fi){
    for (auto & i : arr) {
        if (i.second == val&&i.first == fi) return true;
    }
    return false;
}

void solve() {
    cin>>n;
    i64 res = 0;
    vector<pair<i64,i64>> arr(n);
    for (int i = 0; i < n; ++i) cin>>arr[i].first>>arr[i].second;
    sort(arr.begin(), arr.end());
    for (int i = 1; i < arr.size(); ++i) {
        if (arr[i].first==arr[i-1].first&&arr[i].second==arr[i-1].second) {
            arr.erase(arr.begin()+i);
            --i;
        }
    }
    for (int i = 0; i < arr.size(); ++i) {
        if (searchFirst(arr,arr[i].first-1,arr[i].second)) --res;
        if (searchSecond(arr,arr[i].second-1,arr[i].first)) --res;
    }
    res+=4*arr.size();
    cout<<res*0.5<<endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值