A: http://codeforces.com/contest/1157/problem/Aios
題意:每次加到10的整數倍以後,去掉後面的0,問最多有多少種可能。app
1 #include <iostream> 2 #include <algorithm> 3 #include <vector> 4 #include <string> 5 #include <set> 6 7 using namespace std; 8 9 int main() 10 { 11 ios::sync_with_stdio(false); 12 cin.tie(0); 13 cout.tie(0); 14 15 int n; 16 set<int> si; 17 while(cin>>n){ 18 si.clear(); 19 si.insert(si.end(),n); 20 while(n!=1){ 21 n++; 22 while(n%10==0){ 23 n/=10; 24 } 25 si.insert(si.end(),n); 26 } 27 n=2; 28 si.insert(si.end(),n); 29 while(n!=1){ 30 n++; 31 while(n%10==0){ 32 n/=10; 33 } 34 si.insert(si.end(),n); 35 } 36 cout<<si.size()<<endl; 37 } 38 return 0; 39 }
B: http://codeforces.com/contest/1157/problem/Bide
題意:有一個很長的字符串,和1-9之間數字的映射關係。問修改其中一段獲得的最大的串是什麼。(能夠進行0次或1次修改)spa
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <set> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; string s1; int mapp[9]; while(cin>>n){ cin>>s1; string s3(s1); for(int i=0;i<9;i++){ cin>>mapp[i]; } for(int j=0;j<s1.size();j++){ string s2(s1); for(int i=j;i<s1.size();i++){ char t=mapp[s1[i]-'1']+'0'; if(t>=s1[i]){ s2[i]=mapp[s1[i]-'1']+'0'; }else{ break; } } if(s2>s3) s3=s2; } cout<<s3<<endl; } return 0; }