其他分享
首页 > 其他分享> > Dyson Box(模拟题--周长)

Dyson Box(模拟题--周长)

作者:互联网

swjtu—春季集训 - Virtual Judge (vjudge.net)

Dyson Box
Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 256 megabytes
A Dyson Sphere is a hypothetical megastructure that completely encompasses a star and captures a large
percentage of its power output. The concept is a thought experiment that attempts to explain how a
spacefaring civilization would meet its energy requirements once those requirements exceed what can be
generated from the home planet’s resources alone. Only a tiny fraction of a star’s energy emissions reach
the surface of any orbiting planet. Building structures encircling a star would enable a civilization to
harvest far more energy.
One day, Moca has another idea for a thought experiment. Assume there is a special box called Dyson
Box. The gravitational field in this box is unstable. The direction of the gravity inside the box can not
be determined until it is opened.
The inside of the box can be formed as a 2-dimensional grid, while the bottom left corner’s coordinate
is (0, 0) and the upper right corner’s coordinate is (2 · 105
, 2 · 105
). There will be n events. In the i-th
event, a new cube will appear, whose upper right corner’s coordinate is (xi
, yi) and bottom left corner’s
coordinate is (xi − 1, yi − 1).
There are two directions of gravity in the box, vertical and horizontal. Suppose Moca opens the box
after the i-th event. In that case, she has 1
2
probability of seeing the direction of the gravity inside the
box is vertical, and the other 1
2
probability is horizontal. And then, she will measure the total length
of the outline of all the cubes. If the direction of gravity is horizontal, all the cubes inside will move
horizontally to the left under its influence. Similarly, vertical gravity will cause all the cubes to move
downward.
Moca hates probability, so that she is asking for your help. If you have known the coordinates of all the
cubes in chronological order, can you calculate the total length of these two cases after each event?
Input
The first line contains one integer n (1 ≤ n ≤ 2 · 105
) – the number of cubes.
Each of the following n lines describes a cube with two integers xi
, yi (1 ≤ xi
, yi ≤ 2 · 105
).
It is guaranteed that no two cubes have the same coordinates.
Output
For each of the n cubes, print one line containing two integers – two answers when the the direction of
gravity is vertical and horizontal.
Example
standard input standard output
4
1 2
3 2
2 1
4 1
4 4
8 6
8 8
10 8
Note
In the only example, the inside of the box is as below, and the bold lines mark the outline of all the cubes.
After the 1-st event
View Problem

思路:

#include <bits/stdc++.h>
using namespace std;
#define ri register int
#define M 200005

template <class G> void read(G &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch<'0'||ch>'9'){f|=ch=='-';ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    x=f?-x:x;
    return ;
}

int x[M],y[M];
int n,m;
int main(){
    
    
    read(n);
    long long ansx=0,ansy=0;
    while(n--)
    {
        int a,b;
        read(a);read(b);
        x[a]++;
        ansx+=4;
    
        if(x[a-1]>=x[a]) ansx-=2;
        if(x[a+1]>=x[a]) ansx-=2;
        if(x[a]>=2) ansx-=2;
        y[b]++;
        ansy+=4;
        
        if(y[b-1]>=y[b]) ansy-=2;
        if(y[b+1]>=y[b]) ansy-=2;
        if(y[b]>=2) ansy-=2;
        printf("%lld %lld\n",ansx,ansy);
    }
    return 0;
    
} 
View Code

 

标签:Box,box,ch,--,gravity,two,模拟题,will,cubes
来源: https://www.cnblogs.com/Lamboofhome/p/16225375.html