Zju2492 A Dp Problem
2013-11-06 19:35
295 查看
给你一些一元一次方程,让你求出未知数的解,如果只有一个解则输出这个解,如果有无数个则输出"IDENTITY"(如 x=x),无解则输出“IMPOSSIBLE”(如 x+2=x+3)。
考虑等式两边也就是“=”两边,分别求出两边未知数项的系数和常数项,分别为,f1,d1,f2,d2,那么最后的答案就是(d2-d1)/(f1-f2)。(这个。。。大家应该都懂!!!)。
处理系数有点恶心。
code:
考虑等式两边也就是“=”两边,分别求出两边未知数项的系数和常数项,分别为,f1,d1,f2,d2,那么最后的答案就是(d2-d1)/(f1-f2)。(这个。。。大家应该都懂!!!)。
处理系数有点恶心。
code:
var s:ansistring; n,i,j,k,f1,d1,f2,d2,tmp,x,t,code,tot:longint; ch,cc:char; begin readln(tot); while tot>0 do begin readln(s); for cc:='a' to 'z' do if pos(cc,s)<>0 then begin ch:=cc; break; end; n:=pos('=',s); i:=1; x:=1; f1:=0; f2:=0; d1:=0; d2:=0; tmp:=0; while (i<n) do begin if (s[i]=ch) and ((i=1) or (s[i-1] in ['+','-'])) then begin inc(i); inc(f1,x); continue; end; if s[i]=ch then begin inc(i); inc(f1,x*tmp); tmp:=0; continue; end; inc(d1,x*tmp); if s[i]='-' then begin inc(i); x:=-1; tmp:=0; continue; end; if s[i]='+' then begin inc(i); x:=1; tmp:=0; continue; end; tmp:=0; repeat if (s[i] in [ch,'+','-','='] )then break; val(s[i],t,code); tmp:=tmp*10+t; inc(i); until false; end; inc(d1,x*tmp); i:=n+1; x:=1; tmp:=0; while i<=length(s) do begin if (s[i]=ch) and ((i=n+1) or (s[i-1] in['+','-'])) then begin inc(i); inc(f2,x); continue; end; if s[i]=ch then begin inc(i); inc(f2,x*tmp); tmp:=0; continue; end; inc(d2,x*tmp); if s[i]='-' then begin inc(i); x:=-1; tmp:=0; continue; end; if s[i]='+' then begin inc(i); x:=1; tmp:=0; continue; end; tmp:=0; repeat if (i=length(s)+1) then break; if s[i] in [ch,'-','+'] then break; val(s[i],t,code); tmp:=tmp*10+t; inc(i); until false; end; inc(d2,tmp*x); if (d2-d1=0) and (f1-f2=0) then writeln('IDENTITY') else if (f1-f2=0) then writeln('IMPOSSIBLE') else
if (d2-d1)/(f1-f2)=0 then writeln(0)
else writeln((d2-d1)/(f1-f2):0:0); dec(tot); end; end.
相关文章推荐
- Flex4 初始化过慢解决方法
- 如何完全卸载 MySQL
- UVa 10719 Quotient Polynomial
- chmod命令详细用法
- windows下搭建cakephp+bootstrap环境
- linux shell 中 " if [ ]; ... then ... fi " 的使用
- 黑马程序员——集合&List
- 有关The Last Promise的汉化②改写程序
- 南阳理工OJ_1的个数
- SCOM2012功能测试(1)—发现计算机并安装客户端
- 通过淘宝IP地址库获取IP位置
- HDU2578--Dating with girls(1) (map||排序+二分)
- feeling
- android每次调试程序 模拟器都重新启动 非常不爽
- memcached搭建和使用要点
- memcached搭建和使用要点
- su与su-切换用户
- 打开chm乱码时解决方案
- 面试经历(华为,瑞晟,大华,海康,虹软,顺丰)
- Grade 的分佈