8月9号水题走一波

Description

Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are n flowers in a row in the exhibition. Sonya can put either a rose or a lily in the i-th position. Thus each of n positions should contain exactly one flower: a rose or a lily.
She knows that exactly m people will visit this exhibition. The i-th visitor will visit all flowers from li to ri inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.
Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.

Input

The first line contains two integers n and m (1≤n,m≤103) — the number of flowers and visitors respectively.
Each of the next m lines contains two integers li and ri (1≤li≤ri≤n), meaning that i-th visitor will visit all flowers from li to ri inclusive.

Output

Print the string of n characters. The i-th symbol should be «0» if you want to put a rose in the i-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any.

Sample Input
Input

5 3
1 3
2 4
2 5

Output

01100

Input

6 3
5 6
1 4
4 6

Output

110010

Hint

In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;
    in the segment [1…3], there are one rose and two lilies, so the beauty is equal to 1⋅2=2;
    in the segment [2…4], there are one rose and two lilies, so the beauty is equal to 1⋅2=2;
    in the segment [2…5], there are two roses and two lilies, so the beauty is equal to 2⋅2=4.

The total beauty is equal to 2+2+4=8.

In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;
in the segment [5…6], there are one rose and one lily, so the beauty is equal to 1⋅1=1;
in the segment [1…4], there are two roses and two lilies, so the beauty is equal to 2⋅2=4;
in the segment [4…6], there are two roses and one lily, so the beauty is equal to 2⋅1=2 .

The total beauty is equal to 1+4+2=7.

题目意思:花园里要展览n棵花,有两种花,一种是玫瑰,一种是百合。有m位游客来参观花展,每一位游客只会观赏【l,r】的花,游客会有对花展的一种满意度,每一区域满意度等于玫瑰的种类×百合的种类,问要怎么样排列两种花才能得到最大的总的满意度。

解题思路:这道题耗费了我太久的时间,主要是样例太坑爹了,虽然知道正确答案不止一种但是样例的答案很有迷惑性,开始我一直在研究区间的覆盖,一直没有头绪,哎啊。

其实正确的思路是这样来想,我们想要得到区间内的最大满意度一定是尽量让两种花的种类尽可能的相等!而每一个区间都尽可能的相等进而就会得到整个区间的尽可能的相等分布,

那么最好的两种花间隔排列。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 int main()
 6 {
 7     int n,m,i,l,r;
 8     scanf("%d%d",&n,&m);
 9     for(i=0;i<m;i++)
10     {
11         scanf("%d%d",&l,&r);
12     }
13     for(i=0;i<n;i++)
14     {
15         if(i%2==0)
16         {
17             printf("1");
18         }
19         else
20         {
21             printf("0");
22         }
23     }
24     printf("\n");
25     return 0;
26 }

2.Sonya and Hotels

Description

Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.

The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has n
hotels, where the i-th hotel is located in the city with coordinate xi

. Sonya is a smart girl, so she does not open two or more hotels in the same city.

Sonya understands that her business needs to be expanded by opening new hotels, so she decides to build one more. She wants to make the minimum distance from this hotel to all others to be equal to d

. The girl understands that there are many possible locations to construct such a hotel. Thus she wants to know the number of possible coordinates of the cities where she can build a new hotel.

Because Sonya is lounging in a jacuzzi in one of her hotels, she is asking you to find the number of cities where she can build a new hotel so that the minimum distance from the original n
hotels to the new one is equal to d

.

Input

The first line contains two integers n
and d (1≤n≤100, 1≤d≤109

) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others.

The second line contains n
different integers in strictly increasing order x1,x2,…,xn (−109≤xi≤109

) — coordinates of Sonya's hotels.

Output

Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to d

.

Sample Input
Input

4 3
-3 2 9 16

Output

6

Input

5 2
4 8 11 18 19

Output

5

Hint

In the first example, there are 6
possible cities where Sonya can build a hotel. These cities have coordinates −6, 5, 6, 12, 13, and 19

.

In the second example, there are 5
possible cities where Sonya can build a hotel. These cities have coordinates 2, 6, 13, 16, and 21.

猜你喜欢

转载自www.cnblogs.com/wkfvawl/p/9451055.html