Competition - 20181024

题目A

Masha has three sticks of length aa, bb and cc centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks.

What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices.

Input

The only line contains tree integers aa, bb and cc (1≤a,b,c≤1001≤a,b,c≤100) — the lengths of sticks Masha possesses.

Output

Print a single integer — the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks.

Examples

Input

3 4 5

Output

0

Input

2 5 3

Output

1

Input

100 10 10

Output

81

Note

In the first example, Masha can make a triangle from the sticks without increasing the length of any of them.

In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 22centimeter stick by one and after that form a triangle with sides 33, 33 and 55centimeters.

In the third example, Masha can take 3333 minutes to increase one of the 1010centimeters sticks by 3333 centimeters, and after that take 4848 minutes to increase another 1010 centimeters stick by 4848 centimeters. This way she can form a triangle with lengths 4343, 5858 and 100100 centimeters in 8181 minutes. One can show that it is impossible to get a valid triangle faster.

题意:

给定三条边,各边增加任意

长度,使三条边能组成一个三角形,求增加长度的和的最小值;

思路:

一开始万脸懵逼,只想到了两边之和大于第三遍,但是怎么实现对哪条边怎么增加,完全没思路。

然后自己嘀咕,三边都相等,增加即为零,等边三角形呀。

然后想,是不是可以按大小关系分类,我分了4类:(1)a=b=c(2)a<=b<c(3)a<b<=c(4)a<b<c;

发现了点东西,对于这四类,都已经满足 b+c>a,a+c>b,只需满足 b+a>c 即可,这不就是题目吗?最小增加值,就是b+a+x=c+1,即可,也不用分配到每条边,x即为增加的和;

正要写,发现一个问题,对于后三种分类,都可以找到例子让他们组成三角形,此时直接输出零即可。

整理正确思路:

1》若三遍满足“任意两边之和大于第三边”,输出“0”,结束程序。

2》否则,将三边排序,使最大边加1,减去两条较小边的和即可得到最小增加长度的和。

代码:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int main(){
    int a[5];
    for(int i=0;i<3;i++){
        cin>>a[i];
    }
    sort(a,a+3);
    if(a[1]+a[2]>a[0]){
        if(a[1]+a[0]>a[2]){
            if(a[0]+a[2]>a[1]){
                cout<<"0"<<endl;
                return 0;
            }
        }
    }
    cout<<(a[2]+1-a[1]-a[0])<<endl;
    return 0;
}

 


题目B

Colossal! — exclaimed Hawk-nose. — A programmer! That's exactly what we are looking for.

Arkadi and Boris Strugatsky. Monday starts on Saturday

Reading the book "Equations of Mathematical Magic" Roman Oira-Oira and Cristobal Junta found an interesting equation: a−(a⊕x)−x=0a−(a⊕x)−x=0 for some given aa, where ⊕⊕stands for a bitwise exclusive or (XOR) of two integers (this operation is denoted as ^ or xor in many modern programming languages). Oira-Oira quickly found some xx, which is the solution of the equation, but Cristobal Junta decided that Oira-Oira's result is not interesting enough, so he asked his colleague how many non-negativesolutions of this equation exist. This task turned out to be too difficult for Oira-Oira, so he asks you to help.

Input

Each test contains several possible values of aa and your task is to find the number of equation's solution for each of them. The first line contains an integer tt (1≤t≤10001≤t≤1000) — the number of these values.

The following tt lines contain the values of parameter aa, each value is an integer from 00 to 230−1230−1 inclusive.

Output

For each value of aa print exactly one integer — the number of non-negative solutions of the equation for the given value of the parameter. Print answers in the same order as values of aa appear in the input.

One can show that the number of solutions is always finite.

Example

Input

3
0
2
1073741823

Output

1
2
1073741824

Note

Let's define the bitwise exclusive OR (XOR) operation. Given two integers xx and yy, consider their binary representations (possibly with leading zeroes): xk…x2x1x0xk…x2x1x0and yk…y2y1y0yk…y2y1y0. Here, xixi is the ii-th bit of the number xx and yiyi is the ii-th bit of the number yy. Let r=x⊕yr=x⊕y be the result of the XOR operation of xx and yy. Then rr is defined as rk…r2r1r0rk…r2r1r0 where:

 

ri={1, if xi≠yi0, if xi=yiri={1, if xi≠yi0, if xi=yi

For the first value of the parameter, only x=0x=0 is a solution of the equation.

For the second value of the parameter, solutions are x=0x=0 and x=2x=2.

题意:a−(a⊕x)−x=0,其中“(a⊕x)”代表a与x异或,【二进制位上数字相同为0,相异为1】给定a,求解有多少个解。

思路:

。。

我对这种题一般都是敬而远之的,涉及位操作的题目我一律懵,

这次耐下性子看,仿佛没那么阔怕,用a=1,=2,=3,=4,试了几次,好像发现了什么规律,首先是0和a一定是解,然后又发现在将x从0-a遍历时,对应的位上,如果对应位上a=0,x=1,那么该数一定不是解,其余的怎么都想不出来什么了,

问同学,大佬表示“a对应为上为1,那对应的解上的该位0/1都可以,上为0下为0也可以,唯独0,1不行”;

我一脸懵,我知道啊,我试出来了,然后呢,大佬说,“就是将a中二进制上1的数目找出来,吧啦吧啦,,”;

虽然我没听明白,但不好意思再问了,,自己在纸上写写画画半个小时,跌跌撞撞找出了答案,,为什么这东西在大佬眼里就是天然的,本应如此,我看就是,为啥为啥为啥,。。太菜了。

整理思路:

1》转换公式,a−(a⊕x)−x=0,即a⊕x=a-x;

2》由于数据变态的大,遍历时不可能的,用二进制思想看左右两边,对于左边的位操作,1-1=0,1-0=1,0-0=0,这三种减法操作与位操作-异或1^1,1^0,0^0的对应结果是相同的,只有0-1时,需要借位思想,若可借,则其结果必为零,但对于右边0^1,结果则为1,两边二进制上对应位的值不想同,则十进制的值也必定不相同,

3》是不是有点蠢蠢欲动,但是这和a中1的个数有什么关系吗?我给不出推理,只能试,最终的结果就是2^1,2^2,2^3,,,2^num的和+1;【其中num为1的个数,最后加1是因为x=0一定为解】

代码:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<stdio.h>
using namespace std;
int main(){
    long long b;
    int t;
    cin>>t;
    for(int i=1;i<=t;i++){
        cin>>b;
        int num=0;
        while(b>0){
            if(b&0x1)	//与最低位相与,判断是0还是1
                num++; 
            b = b>>1;   //向右移1位
        }

        int ans=0;
        for(int i=1;i<=num;i++)
            ans+=pow(2,i-1);
        
        ans+=1;
        cout<<ans<<endl;
    }
    return 0;
}

题目C:

A non-empty string is called palindrome, if it reads the same from the left to the right and from the right to the left. For example, "abcba", "a", and "abba" are palindromes, while "abab" and "xy" are not.

A string is called a substring of another string, if it can be obtained from that string by dropping some (possibly zero) number of characters from the beginning and from the end of it. For example, "abc", "ab", and "c" are substrings of the string "abc", while "ac" and "d" are not.

Let's define a palindromic count of the string as the number of its substrings that are palindromes. For example, the palindromic count of the string "aaa" is 66 because all its substrings are palindromes, and the palindromic count of the string "abc" is 33 because only its substrings of length 11 are palindromes.

You are given a string ss. You can arbitrarily rearrange its characters. You goal is to obtain a string with the maximum possible value of palindromic count.

Input

The first line contains an integer nn (1≤n≤1000001≤n≤100000) — the length of string ss.

The second line contains string ss that consists of exactly nn lowercase characters of Latin alphabet.

Output

Print string tt, which consists of the same set of characters (and each characters appears exactly the same number of times) as string ss. Moreover, tt should have the maximum possible value of palindromic count among all such strings strings.

If there are multiple such strings, print any of them.

Examples

Input

5
oolol

Output

ololo

Input

16
gagadbcgghhchbdf

Output

abccbaghghghgdfd

Note

In the first example, string "ololo" has 99 palindromic substrings: "o", "l", "o", "l", "o", "olo", "lol", "olo", "ololo". Note, that even though some substrings coincide, they are counted as many times as they appear in the resulting string.

In the second example, the palindromic count of string "abccbaghghghgdfd" is 29.

题意:

给定一串字符,任意改变位置,输出任意一个使其回文子串最多的排列方式。

思路:

。。

这种题存在的意义大概就是练胆吧,我在这边列举着各中奇数偶数字母组合的排列方式,那边老哥哗哗的A了,什么??

这大概就是玄学,把数组排序输出即可。我真的不想找什么规律,想了半个小时的题,10行代码A了之后,总感觉智商被玩弄了一番,

真正想想,一个字符的回文串不说,

想构造两个字符的字符串,只能是两个相同的字符来实现;

想实现三个字符的回文,则两端必须相等,中间字母是与两边相同的必然比中间为其他字符的字符串回文子串多,若有三个相同的,当然要使他们在一块;

四个也是一样,,依次类推,就是那个有点弱智的解,字典排序,输出。

代码:

#include<bits/stdc++.h>
using namespace std;
int main(){
    int m;
    cin>>m;
    char ss[100001];
    for(int i=1;i<=m;i++) cin>>ss[i];
    sort(ss,ss+m+1);
    for(int i=1;i<=m;i++) cout<<ss[i];
    return 0;
}

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值