2020牛客寒假演算法基礎集訓營4 E 最小表示式

2021-10-02 18:26:48 字數 1007 閱讀 6195

給出乙個包含數字1-9和加號的字串,請你將字串中的字元任意排列,但每種字元數目不變,使得結果是乙個合法的表示式,而且表示式的值最小。輸出那個最小表示式的值

合法的表示式的定義如下:

保證給出的表示式經過重排,存在乙個合法的解。

一行輸入乙個字串,僅包含數字1-9和加號+。

字串的長度小於5∗1

05

5*10^5

5∗105。

一行輸出乙個數字,代表最小的解。

111+1
22
9998765432111
1112345678999
12+35
38
23984692+238752+2+34+
5461
#include

using

namespace std;

typedef

long

long ll;

const

int n=

5e5+5;

int cnt[10]

,num=1;

//cnt代表每個數字有多少個,num計數括號

int sum[n]

;int

main()

int p=

0,cp=0;

//p作為計數器,cp表示答案的位數

for(

int i=

10;i>=

1;i--)}

for(

int i=

0;i)int opt=0;

for(

int i=n;i>=

0;i--)}

cout

}

2020牛客寒假演算法基礎集訓營

長期更新,補完為止 2 g 判正誤 題意 t組資料。判斷a d b e c f是否等於g。1e9 a,b,c,g 1e9,0 d,e,f 1e9。保證不會出現指數和底數同為 0 的情況。思路 硬算會tle或mle。快速冪取模,為了增加過題概率,多取幾個模數判斷。includeusing namesp...

2020牛客寒假演算法基礎集訓營1

找規律,推公式 三角形個數為2 m n m n m 1 n 1 2 m n mn m 1 n 1 2 m n mn m 1 n 1 include include include include using namespace std typedef long long ll const int m...

2020牛客寒假演算法基礎集訓營1

h題 突然發現h題可以用好多種方法做的。方法一 雙指標,維護乙個修改次數小於等於k的區間 include using namespace std typedef long long ll const int mod 1e9 7 const int n 1e5 5 const int inf 0x3f...