2017百度之星程序设计大赛 - 复赛 01,03,05
Arithmetic of Bomb
Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 32768/32768 K (Java/Others)
它最近在學習小學算術,第一次發現這個世界上居然存在兩位數,三位數……甚至N位數!
但是這回的算術題可并不簡單,由于含有表示bomb的#號,度度熊稱之為 Arithmetic of Bomb。

Bomb Number中的bomb,也就是#號,會展開一些數字,這會導致最終展開的數字超出了度度熊所能理解的范疇。比如”(1)#(3)”表示”1”出現了3次,將會被展開為”111”,
同理,”(12)#(2)4(2)#(3)”將會被展開為”12124222”。
為了方便理解,下面給出了Bomb Number的BNF表示。
```
<bomb number> := <bomb term> | <bomb number> <bomb term>
<bomb term> := <number> | '(' <number> ')' '#' '(' <non-zero-digit> ')'
<number> := <digit> | <digit> <number>
<digit> := '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
<non-zero-digit> := '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
```
請將Bomb Number中所有的#號展開,由于數字可能很長,結果對 1 000 000 007 取模。
?
Input 第一行為T,表示輸入數據組數。每組數據包含一個Bomb Expression。
- 1≤T≤100
- 1≤length(Bomb Number)≤1000
?
Output 對每組數據輸出表達式的結果,結果對 1 000 000 007 取模。?
Sample Input 4 1 (1)#(3) (12)#(2)4(2)#(3) (12)#(5)?
Sample Output 1 111 12124222 212121205?
Source 2017"百度之星"程序設計大賽 - 復賽思路:模擬;根據BNF得到重復個數小于10;
#include<iostream> #include<cstdio> #include<cmath> #include<string> #include<queue> #include<algorithm> #include<stack> #include<cstring> #include<vector> #include<list> #include<set> #include<map> using namespace std; #define LL __int64 #define pi (4*atan(1.0)) #define eps 1e-8 #define bug(x) cout<<"bug"<<x<<endl; const int N=2e3+10,M=2e6+10,inf=1e9+10; const LL INF=1e18+10,mod=1e9+7;char a[N]; int main() {int T;scanf("%d",&T);while(T--){scanf("%s",a);int n=strlen(a);LL ans=0;for(int i=0;i<n;i++){if(a[i]=='('){int pos;for(int j=i;;j++)if(a[j]==')'){pos=j;break;}int num=a[pos+3]-'0';for(int k=0;k<num;k++){for(int l=i+1;l<pos;l++){ans=(ans*10+a[l]-'0')%mod;}}i=pos+4;}else ans=(ans*10+a[i]-'0')%mod;}printf("%lld\n",ans);}return 0; }Pokémon GO
? Accepts: 738 ? Submissions: 1725 Time Limit: 3000/1500 MS (Java/Others) ? Memory Limit: 32768/32768 K (Java/Others) Problem Description眾所周知,度度熊最近沉迷于 Pokémon GO。
今天它決定要抓住所有的精靈球!
為了不讓度度熊失望,精靈球已經被事先放置在一個2*N的格子上,每一個格子上都有一個精靈球。度度熊可以選擇任意一個格子開始游戲,抓捕格子上的精靈球,然后移動到一個相鄰的至少有一個公共點的格子上繼續抓捕。例如,(2, 2) 的相鄰格子有(1, 1), (2, 1) 和 (1, 2) 等等。
現在度度熊希望知道將所有精靈球都抓到并且步數最少的方案數目。兩個方案被認為是不同,當且僅當兩個方案至少有一步所在的格子是不同的。
Input第一行為T,表示輸入數據組數。
每組數據包含一個數N。
●1≤T≤100
●1≤N≤10000
Output對每組數據輸出方案數目,結果對 1 000 000 007 取模。
Sample Input 3 1 2 3 Sample Output 2 24 96思路:原題;http://blog.csdn.net/yanghui07216/article/details/50490089
Valley Numer
? Accepts: 548 ? Submissions: 1125 Time Limit: 2000/1000 MS (Java/Others) ? Memory Limit: 32768/32768 K (Java/Others) Problem Description眾所周知,度度熊非常喜歡數字。
它最近發明了一種新的數字:Valley Number,像山谷一樣的數字。
當一個數字,從左到右依次看過去數字沒有出現先遞增接著遞減的“山峰”現象,就被稱作 Valley Number。它可以遞增,也可以遞減,還可以先遞減再遞增。在遞增或遞減的過程中可以出現相等的情況。
比如,1,10,12,212,32122都是 Valley Number。
121,12331,21212則不是。
度度熊想知道不大于N的Valley Number數有多少。
注意,前導0是不合法的。
Input第一行為T,表示輸入數據組數。
每組數據包含一個數N。
● 1≤T≤200
● 1≤length(N)≤100
Output對每組數據輸出不大于N的Valley Number個數,結果對 1 000 000 007 取模。
Sample Input 3 3 14 120 Sample Output 3 14 119思路:數位dp,dp[i][j][k]表示第i位前一位為j的方案數,k==0表示前面沒有遞增的情況,k==1表示有遞增的情況;
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #include<cstdio> #include<cmath> #include<string> #include<queue> #include<algorithm> #include<stack> #include<cstring> #include<vector> #include<list> #include<set> #include<map> using namespace std; #define LL __int64 #define pi (4*atan(1.0)) #define eps 1e-8 #define bug(x) cout<<"bug"<<x<<endl; const int N=2e3+10,M=2e6+10,inf=1e9+10; const LL INF=1e18+10,mod=1e9+7;LL f[110][12][3],bit[N]; LL dp(int pos,int pre,int now,int flag,int p) {if(pos==0)return 1;if(p&&flag&&f[pos][pre][now]!=-1)return f[pos][pre][now];int x=flag?9:bit[pos];LL ans=0;for(int i=0;i<=x;i++){if(!p)ans+=dp(pos-1,i,0,flag||i<x,p||i);else{if(now){if(i>=pre)ans+=dp(pos-1,i,now,flag||i<x,p||i);}elseans+=dp(pos-1,i,now||i>pre,flag||i<x,p||i);}}ans%=mod;if(p&&flag)f[pos][pre][now]=ans;return ans; } char a[N]; LL getans() {scanf("%s",a);int len=0,n=strlen(a);for(int i=n-1;i>=0;i--)bit[++len]=a[i]-'0';return dp(len,0,0,0,0); } int main() {memset(f,-1,sizeof(f));int T;scanf("%d",&T);while(T--){LL out=getans();out=(out+mod-1)%mod;printf("%lld\n",out);}return 0; }?
Arithmetic of Bomb
Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 20????Accepted Submission(s): 17
它最近在學習小學算術,第一次發現這個世界上居然存在兩位數,三位數……甚至N位數!
但是這回的算術題可并不簡單,由于含有表示bomb的#號,度度熊稱之為 Arithmetic of Bomb。

Bomb Number中的bomb,也就是#號,會展開一些數字,這會導致最終展開的數字超出了度度熊所能理解的范疇。比如”(1)#(3)”表示”1”出現了3次,將會被展開為”111”,
同理,”(12)#(2)4(2)#(3)”將會被展開為”12124222”。
為了方便理解,下面給出了Bomb Number的BNF表示。
```
<bomb number> := <bomb term> | <bomb number> <bomb term>
<bomb term> := <number> | '(' <number> ')' '#' '(' <non-zero-digit> ')'
<number> := <digit> | <digit> <number>
<digit> := '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
<non-zero-digit> := '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
```
請將Bomb Number中所有的#號展開,由于數字可能很長,結果對 1 000 000 007 取模。
?
Input 第一行為T,表示輸入數據組數。每組數據包含一個Bomb Expression。
- 1≤T≤100
- 1≤length(Bomb Number)≤1000
?
Output 對每組數據輸出表達式的結果,結果對 1 000 000 007 取模。?
Sample Input 4 1 (1)#(3) (12)#(2)4(2)#(3) (12)#(5)?
Sample Output 1 111 12124222 212121205?
Source 2017"百度之星"程序設計大賽 - 復賽轉載于:https://www.cnblogs.com/jhz033/p/7390607.html
總結
以上是生活随笔為你收集整理的2017百度之星程序设计大赛 - 复赛 01,03,05的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 返回变量内容的错误示例和正确返回的4种方
- 下一篇: C#的初学知识点