fzuacm 2017 新生寒假训练 5

A - a

Limak is a little polar bear. He has n balls, the i-th ball has size t i .

Limak wants to give one ball to each of his three friends. Giving gifts isn’t easy — there are two rules Limak must obey to make friends happy:

  • No two friends can get balls of the same size.
  • No two friends can get balls of sizes that differ by more than 2.

For example, Limak can choose balls with sizes 4, 5 and 3, or balls with sizes 90,91 and 92. But he can’t choose balls with sizes 5, 5 and 6 (two friends would get balls of the same size), and he can’t choose balls with sizes 30, 31 and 33 (because sizes 30 and 33 differ by more than 2).

Your task is to check whether Limak can choose three balls that satisfy conditions above.

Input:

The first line of the input contains one integer n (3 ≤ n ≤ 50) — the number of balls Limak has.

The second line contains n integers t 1 , t 2 , …, t n (1 ≤ t i ≤ 1000) where  t i denotes the size of the i-th ball.

Output:

Print “YES” (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print “NO” (without quotes).

Example:

Input:

4
18 55 16 17

Output:

YES

Input:

6
40 41 43 44 44 44

Output:

NO

Input:

8
5 972 3 4 1 4 970 971

Output:

YES

Note:

In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17.

In the second sample, there is no way to give gifts to three friends without breaking the rules.

In the third sample, there is even more than one way to choose balls:

  1. Choose balls with sizes 3, 4 and 5.
  2. Choose balls with sizes 972, 970, 971.

Code:

#include <stdio.h>
#include <math.h>
int main (void)
{
    int n;
    int a[60];
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for (int i=1;i<=n-2;i++)
    {
        for (int j=i+1;j<=n-1;j++)
        {
            for (int k=j+1;k<=n;k++)
            {
                if (a[i]!=a[j] && a[i]!=a[k] && a[j]!=a[k])
                    if ((fabs(a[i]-a[j])<3) && (fabs(a[i]-a[k])<3) && (fabs(a[j]-a[k])<3)) 
                    {   //用 abs() 会 Compilation error
                        printf("YES");
                        return 0;
                    }
            }
        }
    }
    printf("NO");
    return 0;
}

网上别人用的是排序、去重,不过既然枚举能AC就不管了。


B - b

Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.

The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.

Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.

Input:

The first line of the input contains two integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 10 000, n ≥ 2*m*) — the number of participants of the qualifying contest and the number of regions in Berland.

Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive).

It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.

Output:

Print m lines. On the i-th line print the team of the i-th region — the surnames of the two team members in an arbitrary order, or a single character “?” (without the quotes) if you need to spend further qualifying contests in the region.

Example:

Input:

5 2
Ivanov 1 763
Andreev 2 800
Petrov 1 595
Sidorov 1 790
Semenov 2 503

Output:

Sidorov Ivanov
Andreev Semenov

Input:

5 2
Ivanov 1 800
Andreev 2 763
Petrov 1 800
Sidorov 1 800
Semenov 2 503

Output:

?
Andreev Semenov

Note:

In the first sample region teams are uniquely determined.

In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: “Petrov”-“Sidorov”, “Ivanov”-“Sidorov”, “Ivanov” -“Petrov”, so it is impossible to determine a team uniquely.


Code:

#include <stdio.h>
#include <string.h>
struct ST
{
    char name[15];
    int region;
    int score;
}
stu[100010];
int main (void)
{
    int n,m;
    int x[10010],y[10010],z[10010],a[10010],b[10010];
    memset(x,-1,sizeof(x));
    memset(y,-1,sizeof(y));
    memset(z,-1,sizeof(z));
    memset(a,-1,sizeof(a));
    memset(b,-1,sizeof(b));
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++)
    {
        scanf("%s%d%d",stu[i].name,&stu[i].region,&stu[i].score);
        if (stu[i].score>x[stu[i].region])
        {
        //x,y,z储存前三名分数,a,b储存前两名序号。
      z[stu[i].region]=y[stu[i].region];y[stu[i].region]=x[stu[i].region];x[stu[i].region]=stu[i].score;
            b[stu[i].region]=a[stu[i].region];a[stu[i].region]=i;
        }
        else if (stu[i].score>y[stu[i].region])
        {
            z[stu[i].region]=y[stu[i].region];y[stu[i].region]=stu[i].score;
            b[stu[i].region]=i;
        }
        else if (stu[i].score>z[stu[i].region])
        {
            z[stu[i].region]=stu[i].score;
        }
    }
    for (int i=1;i<=m;i++)
    {
        if (y[i]==z[i])
            printf("?\n");
        else
        {
            printf("%s %s\n",stu[a[i]].name,stu[b[i]].name);
        }
    }
    return 0;
}

笨办法,手动排序,只排前三名,判断一二名分数是否相等。


C - c

Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.

The scales is in equilibrium if the total sum of weights on the left pan is equal to the total sum of weights on the right pan.

Input:

The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol “|” indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially on the left pan of the scale. All weights that are recorded in the sequence after the delimiter are initially on the right pan of the scale.

The second line contains a non-empty sequence containing uppercase English letters. Each letter indicates a weight which is not used yet.

It is guaranteed that all the English letters in the input data are different. It is guaranteed that the input does not contain any extra characters.

Output:

If you cannot put all the weights on the scales so that the scales were in equilibrium, print string “Impossible”. Otherwise, print the description of the resulting scales, copy the format of the input.

If there are multiple answers, print any of them.

Example:

Input:

AC|T
L

Output:

AC|TL

Input:

|ABC
XYZ

Output:

XYZ|ABC

Input:

W|T
F

Output:

Impossible

Input:

ABC|
D

Output:

Impossible

Code:

#include <stdio.h>
#include <string.h>
int main (void)
{
    char s[30],mid[30];
    scanf("%s",s); 
    scanf("%s",mid);
    int n,m;
    n=strlen(s);
    m=strlen(mid);
    int ok=1,l=0,r=0;
    for (int i=0;i<n;i++)
    {
        if (s[i]=='|')
        {
            ok=0;
            continue;
        }
        if (ok)
            l++;
        else
            r++;
    }
    int x;
    x=n+m-1;
    if (x%2!=0 || l>x/2 || r>x/2)   //如果砝码数为奇数,或一边固定的砝码超过总数的一半
    {
        printf("Impossible\n");
        return 0;
    }
    int j;
    j=x/2-l;
    for (int i=0;i<j;i++)
        printf("%c",mid[i]);
    for (int i=0;i<n;i++)
        printf("%c",s[i]);
    for (int i=j;i<m;i++)
        printf("%c",mid[i]);
    printf("\n");
    return 0;
}

D - d

Many students live in a dormitory. A dormitory is a whole new world of funny amusements and possibilities but it does have its drawbacks.

There is only one shower and there are multiple students who wish to have a shower in the morning. That’s why every morning there is a line of five people in front of the dormitory shower door. As soon as the shower opens, the first person from the line enters the shower. After a while the first person leaves the shower and the next person enters the shower. The process continues until everybody in the line has a shower.

Having a shower takes some time, so the students in the line talk as they wait. At each moment of time the students talk in pairs: the (2*i* - 1)-th man in the line (for the current moment) talks with the (2*i*)-th one.

Let’s look at this process in more detail. Let’s number the people from 1 to 5. Let’s assume that the line initially looks as 23154 (person number 2 stands at the beginning of the line). Then, before the shower opens, 2 talks with 3, 1 talks with 5, 4 doesn’t talk with anyone. Then 2 enters the shower. While 2 has a shower, 3 and 1 talk, 5 and 4 talk too. Then, 3 enters the shower. While 3 has a shower, 1 and 5 talk, 4 doesn’t talk to anyone. Then 1 enters the shower and while he is there, 5 and 4 talk. Then 5 enters the shower, and then 4 enters the shower.

We know that if students i and j talk, then the i-th student’s happiness increases by g i j and the j-th student’s happiness increases by g j i . Your task is to find such initial order of students in the line that the total happiness of all students will be maximum in the end. Please note that some pair of students may have a talk several times. In the example above students 1 and 5 talk while they wait for the shower to open and while 3 has a shower.

Input:

The input consists of five lines, each line contains five space-separated integers: the j-th number in the i-th line shows g i j (0 ≤ g i j  ≤ 105). It is guaranteed that g i i  = 0 for all i.

Assume that the students are numbered from 1 to 5.

Output:

Print a single integer — the maximum possible total happiness of the students.

Example:

Input:

0 0 0 0 9
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
7 0 0 0 0

Output:

32

Input:

0 43 21 18 2
3 0 21 11 65
5 2 0 1 4
54 62 12 0 99
87 64 81 33 0

Output:

620

Note:

In the first sample, the optimal arrangement of the line is 23154. In this case, the total happiness equals:

    (*g*23 + *g*32 + *g*15 + *g*51) + (*g*13 + *g*31 + *g*54 + *g*45) + (*g*15 + *g*51) + (*g*54 + *g*45) = 32


Code:

#include <stdio.h>
#include <string.h>
int main (void)
{
    int g[6][6];
    for (int i=1;i<=5;i++)
        for (int j=1;j<=5;j++)
            scanf("%d",&g[i][j]);
    int max=-1;
    for (int a=1;a<=5;a++)
        for (int b=1;b<=5;b++)
            for (int c=1;c<=5;c++)
                for (int d=1;d<=5;d++)
                    for (int e=1;e<=5;e++)
                    {   //黑科技:判断五个数是否互不相同。
                        char s[6],buf[6]="12345";
                        int ok=1;
                        sprintf(s,"%d%d%d%d%d",a,b,c,d,e);
                        for (int i=0;i<6;i++)
                            if (strchr(s,buf[i])==NULL) ok = 0;
                        if (ok)
                        {
                            int x;
                            x = g[a][b]+g[b][a]+2*g[c][d]+2*g[d][c]+g[b][c]+g[c][b]+2*g[d][e]+2*g[e][d];
                            if (x > max)
                                max = x;
                        }
                    }
    printf("%d\n",max);
    return 0;
}

E - e

A coordinate line has n segments, the i-th segment starts at the position l i and ends at the position r i . We will denote such a segment as [l i , r i ].

You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all other ones. Now you want to test your assumption. Find in the given set the segment which covers all other segments, and print its number. If such a segment doesn’t exist, print -1.

Formally we will assume that segment [a, b] covers segment [c, d], if they meet this condition a ≤ c ≤ d ≤ b.

Input:

The first line contains integer n (1 ≤ n ≤ 105) — the number of segments. Next n*lines contain the descriptions of the segments. The *i-th line contains two space-separated integers l i , r i (1 ≤ l i  ≤ r i  ≤ 109) — the borders of the i-th segment.

It is guaranteed that no two segments coincide.

Output:

Print a single integer — the number of the segment that covers all other segments in the set. If there’s no solution, print -1.

The segments are numbered starting from 1 in the order in which they appear in the input.

Example:

Input:

3
1 1
2 2
3 3

Output:

-1

Input:

6
1 5
2 3
1 10
7 10
7 7
10 10

Output:

3

Code:

#include <stdio.h>
int main (void)
{
    int n;
    int min=1000000010,minl=1000000010,max=-1,maxr=-1;
    int a;
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
    {
        int l,r;
        scanf("%d%d",&l,&r);
        if (l<=min && r>=max)  //都要取等号
        {
            min=l;
            max=r;
            a=i;
        }
        if (r>maxr)
            maxr=r;
        if (l<minl)
            minl=l; 
    }
    if (max==maxr && min==minl)
        printf("%d\n",a);
    else
        printf("%d\n",-1);
    return 0;
}

F - f

You have a description of a lever as string s. We’ll represent the string length as record |s|, then the lever looks as a horizontal bar with weights of length |s| - 1with exactly one pivot. We will assume that the bar is a segment on the Ox axis between points 0 and |s| - 1.

The decoding of the lever description is given below.

  • If the i-th character of the string equals “^”, that means that at coordinate *i*there is the pivot under the bar.
  • If the i-th character of the string equals “=”, that means that at coordinate *i*there is nothing lying on the bar.
  • If the i-th character of the string equals digit c (1-9), that means that at coordinate i there is a weight of mass c on the bar.

Your task is, given the lever description, print if it will be in balance or not. Assume that the bar doesn’t weight anything. Assume that the bar initially is in balance then all weights are simultaneously put on it. After that the bar either tilts to the left, or tilts to the right, or is in balance.

Input:

The first line contains the lever description as a non-empty string s (3 ≤ |s| ≤ 10 6 ), consisting of digits (1-9) and characters “^” and “=”. It is guaranteed that the line contains exactly one character “^”. It is guaranteed that the pivot of the lever isn’t located in any end of the lever bar.

To solve the problem you may need 64-bit integer numbers. Please, do not forget to use them in your programs.

Output:

Print “left” if the given lever tilts to the left, “right” if it tilts to the right and “balance”, if it is in balance.

Example:

Input:

=^==

Output:

balance

Input:

9===^==1

Output:

left

Input:

2==^7==

Output:

right

Input:

41^52==

Output:

balance

Note:

As you solve the problem, you may find the following link useful to better understand how a lever functions:

http://en.wikipedia.org/wiki/Lever.

The pictures to the examples:


Code:

#include <stdio.h>
#include <string.h> 
int main (void)
{
    char s[1000010];
    scanf("%s",s);
    int n,mid;
    long long l=0,r=0;
    n=strlen(s);
    for (int i=0;i<n;i++)
        if (s[i]=='^')
        {
            mid=i;
            break;
        }
    int left=1;
    for (int i=0;i<n;i++)
    {
        if (s[i]=='^')
        {
            left=0;
            continue;
        }
        if (left)
        {
            if (s[i]<='9' && s[i]>'0')
                l+=(s[i]-'0')*(mid-i);
        }
        else
        {
            if (s[i]<='9' && s[i]>'0')
                r+=(s[i]-'0')*(i-mid);
        }
    }
    if (l>r)
        printf("left");
    else if (r>l)
        printf("right");
    else
        printf("balance");
    return 0;
}

G - g

An infinitely long railway has a train consisting of n cars, numbered from 1 to n(the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it either to the beginning of the train, or to the end of the train, at his desire. What is the minimum number of actions David Blaine needs to perform in order to sort the train?

Input:

The first line of the input contains integer n (1 ≤ n ≤ 100 000) — the number of cars in the train.

The second line contains n integers p i (1 ≤ p i  ≤ n, p i  ≠ p j if i ≠ j) — the sequence of the numbers of the cars in the train.

Output:

Print a single integer — the minimum number of actions needed to sort the railway cars.

Example:

Input:

Output:
5
4 1 2 5 3


Output:

2


---

Input:

4
4 1 3 2


Output:

2


---

**Note:**

In the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train.

---

**Code:**

​```c
#include <stdio.h>
#include <string.h>
int main (void)
{
    int n,max=-1;
    scanf("%d",&n);
    int a[100010],b[100010];
    memset(b,0,sizeof(b));
    for (int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for (int i=1;i<=n;i++)
        b[a[i]]=b[a[i]-1]+1;   //动态规划:b[n] = b[n-1] + 1
    for (int i=1;i<=n;i++)
        if (b[i]>max)
            max=b[i];
    printf("%d\n",n-max);
    return 0;
}

找最长上升连续子序列,这部分固定不动,移其他的。即需要移 (n - 子序列长)步。


H - h

Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.

Mr. Scrooge’s signature can be represented as a polyline A 1 A 2 A n . Scrooge signs like that: first it places a pen at the point A 1 , then draws a segment from point A*1to point *A 2 , then he draws a segment from point A 2 to point A 3 and so on to point*A n *, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant — 50millimeters per second.

Scrooge signed exactly k papers throughout his life and all those signatures look the same.

Find the total time Scrooge wasted signing the papers.

Input:

The first line contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ 1000). Each of the following n lines contains the coordinates of the polyline’s endpoints. The i-th one contains coordinates of the point A i — integers x i and y i , separated by a space.

All points A i are different. The absolute value of all coordinates does not exceed20. The coordinates are measured in millimeters.

Output:

Print one real number — the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 6 .

Example:

Input:

2 1
0 0
10 0

Output:

0.200000000

Input:

5 10
3 1
-5 6
-2 -1
3 2
10 0

Output:

6.032163204

Input:

6 10
5 0
4 0
6 0
3 0
7 0
2 0

Output:

3.000000000

Code:

#include <stdio.h> 
#include <math.h>
int main (void)
{
    int n,k;
    scanf("%d%d",&n,&k);
    double d=0.0;
    int a,b;
    for (int i=1;i<=n;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        if (i==1)
        {
            a=x;
            b=y;
            continue;
        }
        d+=sqrt((x-a)*(x-a)+(y-b)*(y-b));
        a=x;
        b=y;
    }
    d=d*k/50.0;
    printf("%.9f",d);
    return 0;
}

I - i

One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!

Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture.

In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals n, then the player wins, otherwise the player loses.

The player has already got the first card, it’s the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals n.

Input:

The only line contains n (1 ≤ n ≤ 25) — the required sum of points.

Output:

Print the numbers of ways to get the second card in the required way if the first card is the queen of spades.

Example:

Input:

12

Output:

4

Input:

20

Output:

15

Input:

10

Output:

0

Note:

In the first sample only four two’s of different suits can earn the required sum of points.

In the second sample we can use all tens, jacks, queens and kings; overall it’s 15cards, as the queen of spades (as any other card) is only present once in the pack of cards and it’s already in use.

In the third sample there is no card, that would add a zero to the current ten points.


Code:

#include <stdio.h> 
int main (void)
{
    int n;
    scanf("%d",&n);
    if (n<=10 || n>21)
        printf("%d\n",0);
    else if (n!=20)
        printf("%d\n",4);
    else
        printf("%d\n",15);
    return 0;
}

J - j

Let’s denote as popcount(x) the number of bits set (‘1’ bits) in the binary representation of the non-negative integer x.

You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, and popcount(x) is maximum possible. If there are multiple such numbers find the smallest of them.

Input:

The first line contains integer n — the number of queries (1 ≤ n ≤ 10000).

Each of the following n lines contain two integers l i , r i — the arguments for the corresponding query (0 ≤ l i  ≤ r i  ≤ 10 1 8 ).

Output:

For each query print the answer in a separate line.

Example:

Input:

3
1 2
2 4
1 10

Output:

1
3
7

Note:

The binary representations of numbers from 1 to 10 are listed below:

1 1 0  = 1 2

2 1 0  = 10 2

3 1 0  = 11 2

4 1 0  = 100 2

5 1 0  = 101 2

6 1 0  = 110 2

7 1 0  = 111 2

8 1 0  = 1000 2

9 1 0  = 1001 2

10 1 0  = 1010 2


Code:

#include <stdio.h>
#include <string.h> 
int main (void)
{
    int n;
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
    {
        long long l,r;
        scanf("%I64d%I64d",&l,&r);
        if (l==r)
        {   //如果左右边界值相等,即答案就是边界值。
            printf("%I64d\n",r);
            continue;
        }
        int left[70],right[70];
        memset(left,0,sizeof(left));
        int longl=0,longr=0;                //先将两个边界值转换为二进制,用数组存储。
        do                                  //除以基数,倒取余数
        {
            left[++longl]=l%2;
            l=l/2;  
        }
        while (l!=0);
        do
        {
            right[++longr]=r%2;
            r=r/2;  
        }
        while (r!=0);

        int k,ok=0;
        for (int j=longr;j>0;j--)           //然后从最高位开始逐位比较两个边界值
        {
            if (!ok)
            {
                if (left[j]!=right[j])      //当在第 k 位发现比较结果不相等
                {
                    ok=1;
                    k=j;
                }
            }
            else
            {
                if (right[j]==0)            //判断右边界值 k 位以下是否都为 1
                {
                    ok=0;
                    break;
                }
            }
        }
        long long sum=0,power=1,t;
        for (int j=1;j<=k;j++)
        {
            sum+=power;
            if (j==k)
                t=power;
            power*=2;
        }
        for (int j=k+1;j<=longr;j++)
        {
            sum+=power*right[j];
            power*=2;
        }
        if (ok)
            printf("%I64d\n",sum);
        else
            printf("%I64d\n",sum-t);
    }
    return 0;
}

先将两个边界值转换为二进制,用数组存储。

然后从最高位开始逐位比较两个边界值,

当在第 k 位发现比较结果不相等时,即一定是左边界值此位为0,右边界值此位为1。

则左右边界值之间必存在一个数是 k 位以下皆为 1。

所以只要判断右边界值 k 位以下是否都为 1,

如果是,则 “ 1 ” 个数最多的数为右边界值,

否则,“ 1 ” 个数最多的数为 k 位为0,k 位以下皆为 1,其余位和右边界值相应位相等 的数。

最后再把此数转化为十进制输出即可。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值