专业网站建设价格分析,免费ps素材图片大全,简单网站 快速建设,朗格手表网站题目链接#xff1a;https://vjudge.net/problem/UVA-213 题目翻译摘自《算法禁赛入门经典》 题目大意 考虑下面的 01 串序列#xff1a; 0, 00, 01, 10, 000, 001, 010, 011, 100, 101, 110, 0000, 0001, …, 1101, 1110, 00000, … 首先是长度为 1 的串#xff0c;然… 题目链接https://vjudge.net/problem/UVA-213 题目翻译摘自《算法禁赛入门经典》 题目大意 考虑下面的 01 串序列 0, 00, 01, 10, 000, 001, 010, 011, 100, 101, 110, 0000, 0001, …, 1101, 1110, 00000, … 首先是长度为 1 的串然后是长度为 2 的串依此类推。如果看成二进制相同长度的后一个串等于前一个串加 1。注意上述序列中不存在全为 1 的串。 你的任务是编写一个解码程序。首先输入一个编码头例如AB#TANCnrtXc则上述序列的每个串依次对应编码头的每个字符。例如0对应A00对应B01对应#…110对应X0000对应c。接下来是编码文本可能由多行组成你应当把它们拼成一个长长的01串。编码文本由多个小节组成每个小节的前3个数字代表小节中每个编码的长度用二进制表示例如010代表长度为2然后是各个字符的编码以全1结束例如编码长度为2的小节以11结束。编码文本以编码长度为000的小节结束。 例如编码头为\$#**\编码文本为0100000101101100011100101000应这样解码010(编码长度为2)00(#)00(#)10(*)11(小节结束)011(编码长度为3)000(\)111(小节结束)001(编码长度为1)0(\$)1(小节结束)000(编码结束)。 分析 大部分时间都在弄输入输出。。。 代码如下 1 #include bits/stdc.h2 using namespace std;3 4 #define INIT() ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);5 #define Rep(i,n) for (int i 0; i (n); i)6 #define For(i,s,t) for (int i (s); i (t); i)7 #define rFor(i,t,s) for (int i (t); i (s); --i)8 #define ForLL(i, s, t) for (LL i LL(s); i LL(t); i)9 #define rForLL(i, t, s) for (LL i LL(t); i LL(s); --i)10 #define foreach(i,c) for (__typeof(c.begin()) i c.begin(); i ! c.end(); i)11 #define rforeach(i,c) for (__typeof(c.rbegin()) i c.rbegin(); i ! c.rend(); i)12 13 #define pr(x) cout #x x 14 #define prln(x) cout #x x endl15 16 #define LOWBIT(x) ((x)(-x))17 18 #define ALL(x) x.begin(),x.end()19 #define INS(x) inserter(x,x.begin())20 21 #define ms0(a) memset(a,0,sizeof(a))22 #define msI(a) memset(a,inf,sizeof(a))23 #define msM(a) memset(a,-1,sizeof(a))24 25 #define MP make_pair26 #define PB push_back27 #define ft first28 #define sd second29 30 templatetypename T1, typename T231 istream operator(istream in, pairT1, T2 p) {32 in p.first p.second;33 return in;34 }35 36 templatetypename T37 istream operator(istream in, vectorT v) {38 for (auto x: v)39 in x;40 return in;41 }42 43 templatetypename T1, typename T244 ostream operator(ostream out, const std::pairT1, T2 p) {45 out [ p.first , p.second ] \n;46 return out;47 }48 49 inline int gc(){50 static const int BUF 1e7;51 static char buf[BUF], *bg buf BUF, *ed bg;52 53 if(bg ed) fread(bg buf, 1, BUF, stdin);54 return *bg;55 } 56 57 inline int ri(){58 int x 0, f 1, c gc();59 for(; c48||c57; f c-?-1:f, cgc());60 for(; c47c58; x x*10 c - 48, cgc());61 return x*f;62 }63 64 templateclass T65 inline string toString(T x) {66 ostringstream sout;67 sout x;68 return sout.str();69 }70 71 typedef long long LL;72 typedef unsigned long long uLL;73 typedef pair double, double PDD;74 typedef pair int, int PII;75 typedef pair int, PII PIPII;76 typedef pair string, int PSI;77 typedef pair int, PSI PIPSI;78 typedef set int SI;79 typedef set PII SPII;80 typedef vector int VI;81 typedef vector VI VVI;82 typedef vector PII VPII;83 typedef map int, int MII;84 typedef map int, PII MIPII;85 typedef map PII, int MPIII;86 typedef map string, int MSI;87 typedef map string, string MSS;88 typedef map PII, string MPIIS;89 typedef multimap int, int MMII;90 //typedef unordered_map int, int uMII;91 typedef pair LL, LL PLL;92 typedef vector LL VL;93 typedef vector VL VVL;94 typedef priority_queue int PQIMax;95 typedef priority_queue int, VI, greater int PQIMin;96 const double EPS 1e-6;97 const LL inf 0x7fffffff;98 const LL infLL 0x7fffffffffffffffLL;99 const LL mod 1e9 7;
100 const int maxN 1e4 7;
101 const LL ONE 1;
102 const LL evenBits 0xaaaaaaaaaaaaaaaa;
103 const LL oddBits 0x5555555555555555;
104
105 string str;
106 char dic[8][1 8];
107
108 inline int getInt(int n) {
109 int ret 0;
110 char tmp;
111 while(n--) {
112 cin tmp;
113 if(tmp \r || tmp \n) continue;
114 ret ret * 2 tmp - 0;
115 }
116 return ret;
117 }
118
119 int main(){
120 //freopen(MyOutput.txt,w,stdout);
121 //freopen(input.txt,r,stdin);
122 INIT(); // 有了这个就不能用getchar,printf和scanf等等了
123 while(getline(cin, str)) {
124 int x 1, y 0;
125 Rep(i, str.size()) {
126 if(y (ONE x) - 2) {
127 x;
128 y 0;
129 }
130 dic[x][y] str[i];
131 }
132
133 int len;
134 while(len getInt(3)) {
135 while(1) {
136 int value getInt(len);
137 if(!dic[len][value]) break;
138 cout dic[len][value];
139 }
140 }
141 cout endl;
142 getline(cin, str); // 处理掉多余的尾巴
143 }
144 return 0;
145 } View Code 转载于:https://www.cnblogs.com/zaq19970105/p/11024518.html