洛谷 P1013 进制位
来源:互联网 发布:淘宝正道体育假货 编辑:程序博客网 时间:2024/05/16 07:50
P1013 进制位
题目
题目描述
著名科学家卢斯为了检查学生对进位制的理解,他给出了如下的一张加法表,表中的字母代表数字。 例如:
L K V E
L L K V E
K K V E KL
V V E KL KK
E E KL KK KV
其含义为:
L+L=L,L+K=K,L+V=V,L+E=E
K+L=K,K+K=V,K+V=E,K+E=KL
…… E+E=KV
根据这些规则可推导出:L=0,K=1,V=2,E=3
同时可以确定该表表示的是4进制加法
//感谢lxylxy123456同学为本题新加一组数据
输入输出格式
输入格式:
n(n≤9)表示行数。
以下n行,每行包括n个字符串,每个字串间用空格隔开。(字串仅有一个为‘+’号,其它都由大写字母组成)
输出格式:
① 各个字母表示什么数,格式如:L=0,K=1,……按给出的字母顺序。
② 加法运算是几进制的。
③ 若不可能组成加法表,则应输出“ERROR!”
输入输出样例
输入样例#1:
5+ L K V EL L K V EK K V E KLV V E KL KKE E KL KK KV
输出样例#1:
L=0 K=1 V=2 E=34
题解
先找到ch+ch=ch的位子,这个ch就等于0,再找到两位的字符串,第一位的第一个数就是1,然后就一直递推,推出所有数字,并检验所有的条件是否成立
注意只有两位的时候,要写特判
代码(Pascal)
var n:longint; turn:array['A'..'Z']of longint; map:array['A'..'Z','A'..'Z']of string; q:array[0..10]of char; procedure init; var i,j:longint; ch,x:char; begin readln(n); read(ch);dec(n); for i:=1 to n do begin read(ch); while (ch<'A')or(ch>'Z') do read(ch); q[i]:=ch; end; readln; for i:=1 to n do begin read(ch); while (ch<'A')or(ch>'Z') do read(ch); x:=ch; for j:=1 to n do begin read(ch); map[q[j],x]:=''; while (ch<'A')or(ch>'Z') do read(ch); while ('A'<=ch)and(ch<='Z') do begin map[q[j],x]:=map[q[j],x]+ch; read(ch); end; end; end; end; procedure main; var i,j,t:longint; x,y,next:char; begin x:='a';y:='a'; for i:=1 to n do begin if map[q[i],q[i]]=q[i] then begin x:=q[i];turn[x]:=0;end; if length(map[q[i],q[i]])=2 then begin y:=map[q[i],q[i]][1];turn[y]:=1;end; end; if (x<'A')or(x>'Z')or(y<'A')or(y>'Z') then begin write('ERROR!'); halt; end; next:=y;t:=1; repeat inc(t); turn[map[y,next][1]]:=t; next:=map[y,next][1]; until t>=n-1; turn[y]:=1; end; procedure check; var i,j,k,x:longint; begin for i:=1 to n do for j:=1 to n do begin x:=0; for k:=1 to length(map[q[i],q[j]]) do x:=x*n+turn[map[q[i],q[j]][k]]; if x<>turn[q[i]]+turn[q[j]] then begin write('ERROR!'); halt; end; end; end; procedure print; var i:longint; begin for i:=1 to n do write(q[i],'=',turn[q[i]],' '); writeln; write(n); end; begin init; main; check; print; end.
阅读全文
0 0
- 洛谷 P1013 进制位
- 洛谷 P1013 进制位
- 洛谷 P1013 [NOIP1998 T3] 进制位
- 搜索——洛谷P1013 进制位
- 洛谷 P1013 进制位 【搜索 + 进制运算】
- p1013
- p1013
- TYVJ P1013 找啊找啊找GF
- Counterfeit Dollar(P1013)
- tyvj P1013 - 找啊找啊找GF
- smartoj P1013 最优贸易
- P1013找啊找啊找GF
- Tyvj P1013 找啊找啊找GF
- 【BZOJ】【P1013】【JSOI2008】【球形空间产生器sphere】【题解】【高斯消元】
- 【洛谷 1013】 进制位
- poj1152 数学题(进制位)
- Reverse Bits 翻转进制位
- 16进制位运算
- 01背包
- frame框架
- 【Machine Learning】通过网格搜索进行调参
- [Err] ORA-00979: not a GROUP BY expression
- 【OpenCV3图像处理】查找二值图像的边缘 函数findContours()详解
- 洛谷 P1013 进制位
- *c#在64位上编写32位程序时注册表重定向的问题解决办法**
- Python中sorted函数的用法
- Native/Hybrid/Web App
- 端口
- AVL树的进一步实现
- C++宏定义详解
- 使用Maven+Nexus+Jenkins+Svn+Tomcat+Sonar搭建持续集成环境(一)
- Maven+eclipse+Java+cucumber测试框架运行测试的一种运行方式