codeforces Gym 102465

A - City of Lights

题目

在这里插入图片描述
Paris has been called “ville lumière” (city of lights) since the 17th century. It earned this nickname in part because of the many city lights illuminating famous sites such as monuments, statues, churches, or fountains.

Those public lights in Paris are numbered from 1 to N and are all on by default. A group of hackers has gained the capability to toggle groups of lights. Every time the hackers use their program, they cause a number i (that they cannot control) to be sent to the system controlling the city lights. The lights numbered i, 2i, 3i, and so on (up to N) then change state instantly: lights that were on go off, and lights that were off go on.

During the night, the hackers use their programs k times. What is the greatest number of lights that are simultaneously off at the same time?

Input

The input comprises several lines, each consisting of a single integer:

The first line contains the number N of lights. 1≤N≤1000000.
The second line contains the number k of uses hackers’s program. 1≤k≤100.
The next k lines contain a number i sent to the system controlling the lights. 1≤i≤N.

Output

The output should consist of a single line, whose content is an integer, the greatest number of lights that are simultaneously off at the same time.

Example

Input

10
4
6
2
1
3

Output

6

Note

Sample Explanation:

We start with a group of 10 lights which are all on.
在这里插入图片描述
The hackers send the number 6: light 6 is toggled.
在这里插入图片描述

They then send the number 2: lights 2, 4, 6, 8, and 10 are toggled.
在这里插入图片描述

The number 1 is then sent: all lights are toggled.
在这里插入图片描述

They end up sending the number 3: lights 3, 6, and 9 are toggled.
在这里插入图片描述

The maximum number of lights off at the same time was 6.

答案

#include<bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define eps 1e-7
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
using namespace std;

int dp[N];

int main()
{
    int n,m;
    cin>>n>>m;
    int maxn=-1;
    int cnt=0;
    for(int i=1;i<=m;i++){
        int k;
        cin>>k;
        int pos=n/k;
        for(int j=1;j<=pos;j++){
            if(!dp[j*k]){
                dp[j*k]=1;
                cnt++;
            }
            else {
                dp[j*k]=0;
                cnt--;
            }
        }
        maxn=max(maxn,cnt);
    }
    cout<<maxn<<endl;
    return 0;
}

B - Blurred Pictures

题目

在这里插入图片描述
Damon loves to take photos of the places he visits during his travels, to put them into frames. All of his photos are in a square format of N×N pixels. He brought back beautiful pictures of the many monuments in Paris, such as the Eiffel Tower or the Louvre, but unfortunately, when he got back home, he realized that all his pictures were blurred on the edges. Looking closely, Damon realizes that he can easily distinguish the blurred pixels from the “good” (i.e., non-blurred) ones and that, luckily, all the non-blurred pixels are connected in such a way that any horizontal or vertical line drawn between two non-blurred pixels goes only through non-blurred pixels. In order to get the best from his failed pictures, he decides to cut out the biggest possible picture without any blurred pixel from each of his photos. And since his frames are all squares, for aesthetic reasons, the cut-out pictures have to be squares too. Damon does not want his pictures to be tilted so he wants the sides of the cut-outs to be parallel to the sides of the original picture.

Input

The input comprises several lines, each consisting of integers separated with single spaces:

The first line contains the length N, in pixels, of the input photo;
Each of the next N lines contains two integers ai and bi , the indices of the first (ai) and the last (bi) non-blurred pixel on the i-th line.
0<N≤100000,
0≤ai≤bi<N.

Output

The output should consist of a single line, whose content is an integer, the length of the largest square composed of non-blurred pixels inside the picture.

Examples

Input

3
1 1
0 2
1 1

Output

1

Input

8
2 4
2 4
1 4
0 7
0 3
1 2
1 2
1 1

Output

3

Note

In the input picture, each row and each column has at least one non-blurred pixel.
In any two consecutive lines, there are at least two non-blurred pixels in the same column.

答案

题目大意:
给出每一行的起始点坐标,判断形成的最大的正方形的个数。在这里插入图片描述

#include<bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define eps 1e-7
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
using namespace std;

int a[N];
int b[N];

int main()
{
    int n;
    cin>>n;
    int pos=1;
    int maxn=-1;
    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i];
        int x=max(a[i],a[pos]);
        int y=min(b[i],b[pos]);
        if(x<y){
            maxn=max(maxn,min(y-x+1,i-pos+1));
            while(y-x<i-pos){
                pos++;
                x=min(y,a[pos]);
                y=max(b[i],b[pos]);
            }
        }
        else{
            maxn=max(maxn,1);
            pos=i;
        }
    }
    cout<<maxn<<endl;
    return 0;
}

D - Monument Tour

题目

在这里插入图片描述
A tour operator proposes itineraries consisting of visits of N monuments and museums in Paris, modeled as a grid. The way the tour operates is the following: The bus enters the city from the west (on any street) and traverses the city, taking a left or a right turn to visit monuments when needed, returning to the same eastbound road it used to enter the city, and so on until it exits the city via the east.

A tour in a 6×5 grid city might look like the figure above. On the figure, the bus enters the city at coordinate (0,2) (we consider (0,0) to be the northwest corner of the city), first visits the monument at (1,2) (already on the main road), takes a left turn and visits the monument at (1,0), returns to the main road and moves east, takes a right turn and visits the monument at (2,4), returns to the main road, visits the monument at (4,2) (again on the main road), and then exits the city at coordinate (5,2) .

The bus operator counts that the traversal of one block costs 1 unit of gas. For the example above, the cost is thus 5+2×2+2×2=13 units of gas.

Your task is to help the tour operator choose which eastbound road the bus should travel through, so that the cost of the tour is minimized while visiting all N monuments.

Input

The input comprises several lines, each consisting of integers separated with single spaces:

The first line contains the number X of northbound streets and the number Y of eastbound streets.
The second line contains the number N of monuments the tour needs to visit.
The next N lines each contain the coordinates xi and yi of each monument.
1≤X,Y≤100000;
1≤N≤100000;
0≤xi<X,0≤yi<Y.

Output

The output should consist of a single line, whose content is an integer, representing the minimal cost of a tour.

Examples

Input

6 5
4
1 0
1 2
2 4
4 2

Output

13

Input

5 7
9
0 0
0 2
0 3
2 2
2 3
3 2
4 3
4 4
4 6

Output

20

Note

  • The bus operator is not allowed to return to a different, parallel, eastbound road; they have to use the same road as the one by which they entered the city.
  • More than one monument can be present at the same coordinate.

答案

找出一条线,能把点连起来切最短,连接方式如图
找出每个坐标的最小值和最大值,在这所有的点里面找到最中间的那个就是答案

#include<bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define eps 1e-7
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
using namespace std;

int a[N];
int b[N];

int main()
{
    int n;
    cin>>n;
    int pos=1;
    int maxn=-1;
    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i];
        int x=max(a[i],a[pos]);
        int y=min(b[i],b[pos]);
        if(x<y){
            maxn=max(maxn,min(y-x+1,i-pos+1));
            while(y-x<i-pos){
                pos++;
                x=min(y,a[pos]);
                y=max(b[i],b[pos]);
            }
        }
        else{
            maxn=max(maxn,1);
            pos=i;
        }
    }
    cout<<maxn<<endl;
    return 0;
}

E - Rounding

题目

在这里插入图片描述
You decided to stay an extra day in Paris visiting favorite places of Parisians around T’el’ecom ParisTech. You want to collect information about these favorite places, but asking people to fill in surveys is less fun than coding. For this reason, you asked the Parisian Agency for Really Imprecise Surveys to do it for you. You sent them a list of the P places you were interested in.

After surveying exactly 10 000 persons and asking them their favorite place (among these P places), the agency has just sent you the results. All persons surveyed answered the question. Unfortunately, the agency rounded the percentage results to the nearest integer, using the following formula: result=⌊original_value+12⌋. In particular, decimal values of .50 are rounded up.

But since 10000 persons were surveyed, you should have been able to get percentage values precise to the second decimal. What a loss of precision! You want to know the range in which each original result could be.

Input

  • The input comprises several lines:

  • The first line consists of an integer P.
    Each of the following P lines consists of the name of a place followed by an integer i, separated with a single space.

Limits

  • 1≤P≤10000;
  • the name of a place is a string of between 1 and 20 characters among Latin alphabet letters (‘A’ to ‘Z’ and ‘a’ to ‘z’) and the underscore character (’_’);
  • no two names are the same;
  • 0≤i≤100.

Output

If the results given by the agency are not consistent, print a single line with the word IMPOSSIBLE. Otherwise the output should consist of P lines, each of them should consist of the name of a place followed by a single space and two numbers, the smallest and the largest percentage values that place could have had in the original results, as floating-point numbers with two decimals separated with a single space (each number must have at least one digit before the decimal point, even if it is 0, and exactly 2 decimals, even if the trailing ones are 0). The places must be in the same order as in the input.

Examples

Input

4
Catacombes 32
Cite_Universitaire 22
Arenes_de_Lutece 26
Observatoire 19
Output
Catacombes 31.53 32.49
Cite_Universitaire 21.53 22.49
Arenes_de_Lutece 25.53 26.49
Observatoire 18.53 19.49

Input

7
Aqueduc_Medicis 11
Parc_Montsouris 40
Place_Denfert 10
Hopital_Sainte_Anne 4
Butte_aux_cailles 20
Cite_florale 12
Prison_de_la_Sante 0

Output

Aqueduc_Medicis 11.06 11.49
Parc_Montsouris 40.06 40.49
Place_Denfert 10.06 10.49
Hopital_Sainte_Anne 4.06 4.49
Butte_aux_cailles 20.06 20.49
Cite_florale 12.06 12.49
Prison_de_la_Sante 0.06 0.49

Input

2
Catacombes 50
Arenes_de_Lutece 49

Output

IMPOSSIBLE

答案

在这里插入图片描述

#include<bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define eps 1e-7
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
using namespace std;

int dp[N];
int dl[N],dr[N];
int ml[N],mr[N];
char s[N][30];

int main()
{
    int n;
    cin>>n;
    int coun=0;
    int suml=0,sumr=0;
    for(int i=0;i<n;i++){
        cin>>s[i]>>dp[i];
        dp[i]*=100;
        coun+=dp[i];
        dl[i]=max(0,dp[i]-50);
        suml+=dl[i];
        dr[i]=min(10000,dp[i]+49);
        sumr+=dr[i];
    }
    if(suml>10000||sumr<10000){
        cout<<"IMPOSSIBLE"<<endl;
        return 0;
    }
    for(int i=0;i<n;i++){
        ml[i]=max(dl[i],10000-(sumr-dr[i]));
        mr[i]=min(dr[i],10000-(suml-dl[i]));
    }
    for(int i=0;i<n;i++){
        cout<<s[i]<<" "<<ml[i]/100<<".";
        if(ml[i]%100<10)
            cout<<"0";
        cout<<ml[i]%100<<" "<<mr[i]/100<<".";
        if(mr[i]%100<10)
            cout<<"0";
        cout<<mr[i]%100<<endl;
    }
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值