获得 Access 数据表名列表

  一个小项目里用到的,由于系统要求精简,故选择了简单的access,以前尝试过获得sql server的所有用户表名,sql server的sysobjects表中,用户表类型使用'U'标志,'S'是系统表

select name from sysobjects where type='U'

  但发现这个无法运用在access上,现在只能南辕北辙般的在代码层上动手脚ado.net,通过下面的手段获得表名

Dim MyConn As OleDbConnection = New OleDbConnection(myspclass.ConnStr)
MyConn.Open()
Dim schemaTable As DataTable = MyConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {NothingNothingNothing"TABLE"})
For i As Integer = 0 To schemaTable.Rows.Count  1
    listbox1.Items.Add(schemaTable.Rows(i).Item(
2).ToString())
Next

  先这样将就着,大家有什么好办法吗?
 

关于 Windows 2003 .. 表示父路径解决方法

刚在帮个朋友在自己机器上调试其写的forum插件,出现错误提示:

Active Server Pages 错误 'ASP 0131' 不允许的父路径 /exam/admin/login.asp,行 1 包含文件 '../include/conn.asp' 不能用 '..' 表示父目录。

然后就开始在M$的站上狂搜,终于找到了解决方法。。。 IIS,网站站点,属性,主目录选项卡,配置,选项,勾上“启用父路径”,一切OK 估计是不启用父路径比较安全吧。。。^_^

交通灯控制器的设计——竞赛整理(二)

由于是直接从word中复制过来的,图片无法导入,如果想查看全文,请点击这里下载PDF文档。

关键词
交通信号系统、VHDL语言、ispLEVER、Lattice、ispLSI1032E

题目要求
1. 路型:十字交叉
2. 相变周期:30s
3. 绿闪时间:5s
4. 黄灯时间:2s
5. 绿信比:1:2
6. 定时输入:256Hz TTL
7. 两位数码倒计时
8. 强制放行按钮:东西、南北方向(任意按钮解除)

摘要
 本设计的红绿交通灯信号系统为模拟实际的十字路口交通信号灯。故外部硬件电路方面包括:两组红绿灯、两组七段显示器、一组手动与自动控制开关。软件方面:将红绿灯交通信号系统划分成若干个子电路,赋予VHDL程序代码实现,将各个小电路相连接。交通灯系统可以调整红绿灯电路的强制通行和复位,以增加灵活性。

一、设计状态转移图及软件模块图
1、绘制软件模块图
2、利用状态机绘制状态转移图

二、交通信号系统VHDL模块
 该系统由四个子电路构成(如图):
 
(1) clk_gen 时钟脉冲发生电路(即分频电路)
(2) count_down 倒计时控制电路
(3) traffic_mux 计数秒数选择电路
(4) traffic_fsm 红绿信号灯控制电路

1、 clk_gen 时钟脉冲发生电路
    在红绿交通信号系统中,大多数的情况是通过自动控制的方式指挥交通的。此,为了避免意外事件的发牛,电路必须给一个稳定的时钟才能让系统正常运作。但为了配合高峰时段,防止交通拥挤。有时也必须使用手动控制,即让交警能够顺利指挥交通。clk_gen电路路最主要的功能就是产生—些额外的输出信号,井将其用做后续几个电路的使能控制与同步信号处理。

clk_gen时钟脉冲发生电路VHDL程序:
 
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity clk_gen is
 port( reset: in std_logic;
  clk: in std_logic;
  ena_two: in std_logic;
  ena_scan: out std_logic;
  ena_1hz: out std_logic;
  flash_1hz: out std_logic);
end;
architecture behavior of clk_gen is
constant scan_bit: positive :=2;
constant scan_val: positive :=4;
constant two_hz_bit: positive :=7;
constant two_hz_val: positive :=125;
signal clk_scan_ff: std_logic_vector(scan_bit-1 downto 0);
signal clk_2hz_ff: std_logic_vector(two_hz_bit-1 downto 0);
signal ena_s: std_logic;
signal ena_one: std_logic;
signal ena_two: std_logic;
begin
scan:process(reset,clk)
 begin
  if reset='1' then
   clk_scan_ff<="00";
   ena_s<='0';
  elsif (clk'event and clk='1') then
   if clk_scan_ff>=scan_val-1 then
    clk_scan_ff<="00";
    ena_s<='1';
   else
    clk_scan_ff<=clk_scan_ff+1;
    ena_s<='0';
   end if;
  end if;
 end process;
 ena_scan<=ena_s;
two_hz:process(reset,clk,ena_s)
 begin
  if reset='1' then
   ena_one<='0';
   ena_two<='0';
   clk_2hz_ff<="0000000";
  elsif (clk'event and clk='1') then
   if ena_s='1' then
    if clk_2hz_ff>=two_hz_val-1 then
     clk_2hz_ff<="0000000";
     ena_two<='1';
     ena_one<=not ena_one;
    else
     clk_2hz_ff<=clk_2hz_ff+1;
     ena_two<='0';
     ena_one<=ena_one;
    end if;
   end if;
  end if;
 end process;
 ena_1hz<=ena_one and ena_two and ena_s;
 flash_1hz<=ena_one;
end behavior;
 

模块波形仿真:

2、count_down 倒计时控制电路
当过马路的时候,绿灯的一方有时会附加—个显示器告诉行人,日前还剩下几秒信号灯将变红。因此,count_down 电路最主要的功能就是负责接收traffic_mux电路输出的倒计时秒数值,然后将其转换成BCD码,利用七显示管显示.让行人能清楚知道再过多久就会变成红灯。

count_down 倒计时控制电路VHDL程序:
 
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity count_down is
port( reset: in std_logic;
 clk: in std_logic;
 ena_1hz: in std_logic;
 recount: in std_logic;
 load: in std_logic_vector(7 downto 0);
 seg7: out std_logic_vector(15 downto 0);
 next_state: out std_logic);
end;
architecture count_down of count_down is
signal cnt_ff: std_logic_vector(7 downto 0);
begin
count:process(clk,reset)
 begin
  if (reset='1') then
   cnt_ff<="00000000";
   seg7<="0000000000000000";
  elsif (clk'event and clk='1') then
   if ena_1hz='1' then
    if (recount='1') then
     cnt_ff<=load-1;
    else
     cnt_ff<=cnt_ff-1;
    end if;
   end if;
   case conv_integer(cnt_ff) is
    when 0=>seg7(15 downto 0)<="0011111100111111";
    when 1=>seg7(15 downto 0)<="0011111100000110";
    when 2=>seg7(15 downto 0)<="0011111101011011";
    when 3=>seg7(15 downto 0)<="0011111101001111";
    when 4=>seg7(15 downto 0)<="0011111101100110";
    when 5=>seg7(15 downto 0)<="0011111101101101";
    when 6=>seg7(15 downto 0)<="0011111101111101";
    when 7=>seg7(15 downto 0)<="0011111100000111";
    when 8=>seg7(15 downto 0)<="0011111101111111";
    when 9=>seg7(15 downto 0)<="0011111101111011";
    when 10=>seg7(15 downto 0)<="0000011000111111";
    when 11=>seg7(15 downto 0)<="0000011001011011";
    when 12=>seg7(15 downto 0)<="0000011001011011";
    when 13=>seg7(15 downto 0)<="0000011001001111";
    when 14=>seg7(15 downto 0)<="0000011001100110";
    when 15=>seg7(15 downto 0)<="0000011001101101";
    when 16=>seg7(15 downto 0)<="0000011001111101";
    when 17=>seg7(15 downto 0)<="0000011000000111";
    when 18=>seg7(15 downto 0)<="0000011001111111";
    when 19=>seg7(15 downto 0)<="0000011001111011";
    when 20=>seg7(15 downto 0)<="0101101100111111";
    when 21=>seg7(15 downto 0)<="0101101100000110";
    when 22=>seg7(15 downto 0)<="0101101101011011";
    when 23=>seg7(15 downto 0)<="0101101101001111";
    when 24=>seg7(15 downto 0)<="0101101101100110";
    when 25=>seg7(15 downto 0)<="0101101101101101";
    when 26=>seg7(15 downto 0)<="0101101101111101";
    when 27=>seg7(15 downto 0)<="0101101100000111";
    when 28=>seg7(15 downto 0)<="0101101101111111";
    when 29=>seg7(15 downto 0)<="0101101101111011";
    when others=>seg7(15 downto 0)<="0011111100111111";
   end case;
  end if;
 end process;
 next_state<='1' when cnt_ff=1 else '0';
end count_down;
 

模块波形仿真:

3、traffic_mux 计数秒数选择电路
traffic_mux电路最主要的功能就是负责输出显示器需要的倒数秒数值,作为倒数显示器电路的计数秒数。

traffic_mux 计数秒数选择电路VHDL程序:
 
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;

entity traffic_mux is
 port( reset: in std_logic;
  clk: in std_logic;
  ena_scan: in std_logic;
  recount: in std_logic;
  sign_state: in std_logic_vector(1 downto 0);
  load: out std_logic_vector(7 downto 0));
end;

–define the signal_structure and flow of the device
architecture behavior of traffic_mux is
constant yellow0_time: integer:=5;
constant green0_time: integer:=20;
constant yellow1_time: integer:=5;
constant green1_time: integer:=20;
begin

–to generate a value of counter by load
load_time:process(reset,clk)
 begin
  if reset='1' then
   load<="00000000";
  elsif (clk'event and clk='1') then
   if (ena_scan='1' and recount='1') then
    case sign_state is
     when "00"=>
      load<=conv_std_logic_vector(green1_time,8);
     when "01"=>
      load<=conv_std_logic_vector(yellow0_time,8);
     when "10"=>
      load<=conv_std_logic_vector(green0_time,8);
     when others=>
      load<=conv_std_logic_vector(yellow1_time,8);
    end case;
   end if;
  end if;
 end process;
end behavior;
 

模块波形仿真:

4、traffic_fsm 红绿信号灯控制电路
 在红绿灯交通系统中,大多数的情况是通过自动控制的方式指挥交通的。但为了配合高峰时段,防止交通拥挤,有时还必须使用手动控制,即交警自行指挥交通。因此,traffic_fsm电路除了负责监控路口红绿灯之外,主要的功能就是能够利用开关来切换手动与自动的模式,让交警能够通过外部输入的方式来控制红绿灯交通型号系统的运作。
假如是由于电器效应引起开关误动作,开关抖动的速度是非常快的,故电路可能会产生误动作,本程序的debounce段代码就是为了达到这种抖动消除装置的目的。

traffic_fsm 红绿信号灯控制电路VHDL程序:
 
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity traffic_fsm is
port( reset: in std_logic;
 clk: in std_logic;
 ena_scan: in std_logic;
 ena_1hz: in std_logic;
 flash_1hz: in std_logic;
 a_m: in std_logic;
 st_butt: in std_logic;
 next_state: in std_logic;
 recount: out std_logic;
 sign_state: out std_logic_vector(1 downto 0);
 red: out std_logic_vector(1 downto 0);
 green: out std_logic_vector(1 downto 0);
 yellow: out std_logic_vector(1 downto 0));
end;
architecture traffic_fsm of traffic_fsm is
type sreg0_type is (r0g1, r0y1, g0r1, y0r1, y0y1, y0g1, g0y1, r0r1);
signal state: sreg0_type;
signal st_transfer: std_logic;
signal light: std_logic_vector(5 downto 0);
begin
debounce:process (reset,clk,ena_scan,st_butt)
 variable rebn_ff: std_logic_vector(5 downto 0);
 begin
  if (st_butt='1' or reset='1') then
   rebn_ff:="111111";
   st_transfer<='0';
  elsif (clk'event and clk='1') then
   if (ena_scan='1') then
    if (rebn_ff>=3) then
     rebn_ff:=rebn_ff-1;
     st_transfer<='0';
    elsif (rebn_ff=2) then
     rebn_ff:=rebn_ff-1;
     st_transfer<='1';
    else
     rebn_ff:=rebn_ff;
     st_transfer<='0';
    end if;
   end if;
  end if;
 end process;

fsm:process (clk,ena_1hz,reset)
 begin
  if(reset='1') then
   state<=r0g1;
   sign_state<="01";
   recount<='1';
  else
   if (clk'event and clk='1') then
    case state is
     when r0g1 =>
      if (a_m='1' and ena_1hz='1') then
       if (next_state='1') then
        recount<='1';
        state<=r0y1;
        sign_state<="01";
       else
        recount<='0';
        state<=r0g1;
       end if;
      elsif (a_m='0' and ena_scan='1') then
       if (st_transfer='0') then
        recount<='1';
        state<=r0g1;
       else
        recount<='1';
        state<=r0y1;
        sign_state<="01";
       end if;
      end if;
     when r0y1 =>
      if (a_m='1' and ena_1hz='1') then
       if (next_state='1') then
        recount<='1';
        state<=g0r1;
        sign_state<="10";
       else
        recount<='0';
        state<=r0y1;
       end if;
      elsif (a_m='0' and ena_scan='1') then
       if (st_transfer='0') then
        recount<='1';
        state<=r0y1;
       else
        recount<='1';
        state<=g0r1;
        sign_state<="10";
       end if;
      end if;
     when g0r1 =>
      if (a_m='1' and ena_1hz='1') then
       if (next_state='1') then
        recount<='1';
        state<=y0r1;
        sign_state<="11";
       else
        recount<='0';
        state<=g0r1;
       end if;
      elsif (a_m='0' and ena_scan='1') then
       if (st_transfer='0') then
        state<=g0r1;
       else
        recount<='1';
        state<=y0r1;
        sign_state<="11";
       end if;
      end if;
     when y0r1 =>
      if (a_m='1' and ena_1hz='1') then
       if (next_state='1') then
        recount<='1';
        state<=y0g1;
        sign_state<="00";
       else
        recount<='0';
        state<=y0r1;
       end if;
      elsif (a_m='0' and ena_scan='1') then
       if (st_transfer='0') then
        recount<='1';
        state<=y0r1;
       else
        recount<='1';
        state<=r0r1;
        sign_state<="00";
       end if;
      end if;
     when others =>
      state<=r0g1;
      recount<='0';
      sign_state<="00";
    end case;
   end if;
  end if;
 end process;
light<="010010" when (state=r0g1) else
 "011000" when (state=r0y1) else
 "100001" when (state=r0y1) else
 "100100" when (state=r0y1) else
 "110000";
red<=light(5 downto 4);
yellow<=light(3 downto 2) and (flash_1hz & flash_1hz);
green<=light(1 downto 0);
end traffic_fsm;

配合完整模块仿真:

三、完整软件波形仿真结果
1、clk_gen 时钟脉冲发生电路(即分频电路)
2、count_down 倒计时控制电路
3、traffic_mux 计数秒数选择电路
4、traffic_fsm 红绿信号灯控制电路
四、ispLS1032E芯片引脚图
 

波形发生器的制作——竞赛整理(一)

由于是直接从word中复制过来的,图片无法导入,如果想查看全文,请点击这里下载PDF文档。

关键词

运算放大器,正弦波

 

题目要求

1、  能产生正弦波、方波、三角波、锯齿波四种波形的波形发生器;

2、  输出波形的频率为1KHz

3、  要求用模拟运放电路实现(规定用LM324设计)

4、  要求波形的失真度尽量小

5、  Protel原理图仿真工具完成仿真;

6、  在实验班上安装并完成电路调试。

 

摘要

本设计由三个模块电路构成:方波、三角波发生器,后级正弦波发生器和脉冲波、锯齿波发生器。

前级由电压比较器产生方波,对其输出波形进行一次积分产生三角波,三角波再进行一次积分产生正弦波。而对三角波电路增加二极管,控制三角波的逆程冲放电时间,产生脉冲波,并对其积分产生锯齿波。

 

一、方案选择与论证

1、方波、三角波发生器

方波发生器由电路由迟滞比较器和一个RC充放电回路组成,电压比较器是一种产生方波的最简单的电路之一。而三角波可以通过方波信号积分得到。

 

       2、正弦波发生器

       方案一:通过双三极管差分放大器完成正弦波发生器。差分放大器主要有工作点稳定,输入阻抗高,抗干扰能力较强等有点。特别是作为直流放大器时,可以有效的抑制零点漂移,因此可将频率很低的三角波变换成为正弦波。波形变换的原理时利用差分放大器传输特性的非线性。单由于三极管的个性差异,无法避免由于三极管的双指数特性的不同所导致的输出正弦波的失真,而且电路较为复杂。

 

       方案二:通过运放积分器对前级输出三角波进行积分,输出正弦波。由于前级输出三角波是由比较器产生的方波积分而成,只要前级输出的三角波达到设计要求,其产生的正弦波便自然会达到设计要求,不过由于输入三角波的信号幅度已经有所降低,可能导致输出的正弦波幅值较小,故在后级增加同相比例放大器进行放大操作。

电原理图:

 

       就两方案比较,后者由于设置简单,频率和失真都可以达到设计要求,安装简单。故选用了方案二。

 

3、脉冲波、锯齿波发生器

在考虑方波和三角波产生时,一般下降时间远小于上升时间,就可得到锯齿波。故在三角波发生器上端的电容前增加二极管控制上升和下降时间。

 

二、理论分析与参数计算

1、方波、三角波发生器

 

方波、三角波发生器由电压比较器和基本积分器组成,如图所示。

运算放大器A1R1R2R3 Rw1Dz1Dz2组成电压比较器;运算放大器A2R4Rw2R5C1 C2组成反相积分器,比较器与 积分器首尾相连,形成闭环电路,构成能自动产生方波、三角波的发生器。

电路参数: 

1.方波的幅度: Uo1m = Uz ——(1

    2.三角波的幅度: ——(2

3.方波、三角波的频率: ——(3

    其中C可选择C1C2。从式(2)和(3)可以看出,调节电位器Rw1可改变三角波的幅度,但会影响方波、三角波的频率;调节电位器Rw2可改变方波、三角波的频率,但不会影响方波、三角波的幅度。

Good judgment comes from experience, and experience comes from bad judgment

  半个星期下来,身体已经近乎于透支,天天面对着块块方方正正的电路板和杂乱的导线,人逐渐开始麻木,思维开始僵硬。和其他组成员的寒暄成了唯一语言上的交流。为了焊块板子,身体蜷缩在那里整整的5、6个小时,让我相信身体是完全有极限这回事的。开始时对实验室的好感早已被冰冷的实验桌和浓浓的松香味替代。这周的理论课完全就不知道在上些什么,姓方的家伙一眼看上去就像是那种领导的人(而且貌似不是我们学院的),应该不会是上课的。幻想着我们这组高频部分的实验怎么做……
  七段译码器动态的板子早已把我打的找不着北,今天一早起床总算是把最高位那个乱显示的问题给解决了。Good judgment comes from experience, and experience comes from bad judgment. 现在看来应该算是勉励了。看着那块焊的密密麻麻的板子,说是bad judgment也不至为过,从挫折中总结经验吧。OK,一切会好的。

PS. 谢谢fanfan的经验和指导^_^

Simulink 命令集

仿真命令:
    sim       —
仿真运行一个simulink模块
    sldebug   —
调试一个simulink模块
    simset    —
设置仿真参数
    simget    —
获取仿真参数

线性化和整理命令:
    linmod    —
从连续时间系统中获取线性模型(状态方程)
    linmod2   —
也是获取线性模型,采用高级方法
    dinmod    —
从离散时间系统中获取线性模型
    trim      —
为一个仿真系统寻找稳定的状态参数

构建模型命令:
    open_system   —
打开已有的模型
    close_system  —
关闭打开的模型或模块
    new_system    —
创建一个新的空模型窗口
    load_system   —
加载已有的模型并使模型不可见
    save_system   —
保存一个打开的模型
    add_block     —
添加一个新的模块
    add_line      —
添加一条线(两个模块之间的连线)
    delete_block  —
删除一个模块
    delete_line   —
删除一根线
    find_system   —
查找一个模块
    hilite_system —
使一个模块醒目显示
    replace_block —
用一个新模块代替已有的模块
    set_param     —
为模型或模块设置参数
    get_param     —
获取模块或模型的参数
    add_param     —
为一个模型添加用户自定义的字符串参数
    delete_param  —
从一个模型中删除一个用户自定义的参数
    bdclose       —
关闭一个simulink窗口
    bdroot        —
根层次下的模块名字
    gcb           —
获取当前模块的名字
    gcbh          —
获取当前模块的句柄
    gcs           —
获取当前系统的名字
    getfullname   —
获取一个模块的完全路径名
    slupdate      —
1.x的模块升级为3.x的模块
    addterms      —
为未连接的端口添加terminators模块
    boolean       —
将数值数组转化为布尔值
    slhelp        –simulink
的用户向导或者模块帮助

封装命令:
    hasmask       —
检查已有模块是否封装
    hasmaskdlg    —
检查已有模块是否有封装的对话框
    hasmaskicon   —
检查已有模块是否有封装的图标
    iconedit      —
使用ginput函数来设计模块图标
    maskpopups    —
返回并改变封装模块的弹出菜单项
    movemask      —
重建内置封装模块为封装的子模块

诊断命令:
    sllastdiagnostic  —
上一次诊断信息
    sllasterror       —
上一次错误信息
    sllastwarning     —
上一次警告信息
    sldiagnostics     —
为一个模型获取模块的数目和编译状态

硬拷贝和打印命令:
    frameedit         —
编辑打印画面
    print             —
simulink系统打印成图片,或将图片保存为m文件
    printopt          —
打印机默认设置
    orient            —
设置纸张的方向

TopCoder(R) Single Round Match 258

Problem Statement for ClassScores

Problem Statement

    

A teacher has just finished grading the test papers for his class. To get an idea of how difficult the test was, he would now like to determine the most common score on the test. In statistics, this is called the "mode" of a set of data points. For instance, if the scores were {65, 70, 88, 70}, then the mode would be 70, since it appears twice while all others appear once.

Sometimes, in the case of a tie, the mode will be more than one number. For instance, if the scores were {88, 70, 65, 70, 88}, then the mode would be {70, 88}, since they both appear most frequently.

You are given a int[] scores. You are to return a int[] representing the mode of the set of scores. In the case of more than one number, they should be returned in increasing order.

 

Definition

    
Class: ClassScores
Method: findMode
Parameters: int[]
Returns: int[]
Method signature: int[] findMode(int[] scores)
(be sure your method is public)
    
 
 

Constraints

scores will contain between 1 and 50 elements, inclusive.
Each element of scores will be between 0 and 100, inclusive.
 

Examples

0)  
    
The first example from the problem statement.
1)  
    
The second example from the problem statement.
2)  
    
With no duplicates, all of the elements are the most frequent (appearing once each).

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2005, TopCoder, Inc. All rights reserved.

 


 

 

public class ClassScores {

public int[] findMode(int[] scores) {
  
int[] count = new int[101];
  
for (int i = 0; i < scores.length; i++)
    count[scores[i]]
++;
  
for (int i = scores.length; i ≥ 1; i{
    
int c = 0;
    
for (int j = 0; j ≤ 100; j++)
      
if (count[j] == i)
        c
++;
    
if (c > 0{
      
int p = 0;
      
int[] ret = new int[c];
      
for (int j = 0; j ≤ 100; j++)
        
if (count[j] == i) {
          ret[p] 
= j;
          p
++;
        }

      
return ret;
    }

  }

  
return new int[0];
}


}


 


 

 

Problem Statement for AutoLoan

Problem Statement

    

Auto dealerships frequently advertise tempting loan offers in order to make it easier for people to afford the "car of their dreams". A typical sales tactic is to show you various cars, and then talk in terms of what your monthly payment would be, to say nothing of how much you are actually paying for the car, how much interest you pay, or how long you have to make payments.

A typical auto loan is calculated using a fixed interest rate, and is set up so that you make the same monthly payment for a set period of time in order to fully pay off the balance. The balance of your loan starts out as the sticker price of the car. Each month, the monthly interest is added to your balance, and the amount of your payment is subtracted from your balance. (The payment is subtracted after the interest is added.) The monthly interest rate is 1/12 of the yearly interest rate. Thus, if your annual percentage rate is 12%, then 1% of the remaining balance would be charged as interest each month.

You have been checking out some of the cars at your local dealership, TopAuto. An excited salesman has just approached you, shouting about how you can have the car you are looking at for a payment of only monthlyPayment for only loanTerm months! You are to return a double indicating the annual percentage rate of the loan, assuming that the initial balance of the loan is price.

 

Definition

    
Class: AutoLoan
Method: interestRate
Parameters: double, double, int
Returns: double
Method signature: double interestRate(double price, double monthlyPayment, int loanTerm)
(be sure your method is public)
    
 
 

Notes

Because of the way interest is compounded monthly, the actual interest accrued over the course of a year is not necessarily the same as (balance * yearly interest rate). In fact, it's usually more.
In a real situation, information like this would typically need to be disclosed, but since you aren't at a point of signing any paperwork, the salesman has no legal obligation to tell you anything.
The return value must be within 1e-9 absolute or relative error of the actual result.
 

Constraints

price will be between 1 and 1000000, inclusive.
monthlyPayment will be between 0 and price / 2, inclusive.
loanTerm will be between 1 and 600, inclusive.
The resulting interest rate will be between 0 and 100, inclusive.
 

Examples

0)  
    
Noting that 68 payments of 100 equals the total price of 6800, so there is no interest.
1)  
    
Here, we do pay a little interest. At 9.562% annual interest, that means each month we pay 0.7968% of the balance in interest. Our payment schedule looks like this:
2)  
    
This is similar to what purchasing a new car with no money down might look like, if you make payments for 4 years.

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2005, TopCoder, Inc. All rights reserved.

 


 

 

public class AutoLoan {

private double amort(double principal, double payment, int term, double interest) {
  
double m = interest / 1200;
  
if (principal * m > payment)
    
return 1;
  
for (int i = 0; i < term; i++)
    principal 
= principal * (1 + m)  payment;
  
return principal;
}


public double interestRate(double price, double monthlyPayment, int loanTerm) {
double ret = 0;
double inc = 1000000000;
while (inc ≥ 1.0E-18{
  
double d = amort(price, monthlyPayment, loanTerm, ret + inc);
  
if (d ≤ 0{
    ret 
+= inc;
  }

  inc 
/= 2.0;
}


return ret;

}


}


 


Problem Statement for MissileTarget

Problem Statement

    

You are working for a defense agency that is testing the accuracy of a new missile guidance system. As part of this effort, several missiles have been fired off. Each missile fired was programmed with the same target coordinates, although the actual points of impact vary.

Your task is to determine the "best fit" point to describe the location where the missiles actually landed. To determine how well a point describes the location, calculate the cartesian distance from the point to each of the landing points. Then, total the sum of the squares of these distances. The best fit point is the point that minimizes this sum.

You are given int[]s x and y, both containing the same number of elements, where the i-th element of x and the i-th element of y describe the coordinates of the i-th missile landing point. You are to return a int[] with exactly two elements, describing the coordinates of the lattice point (point with integral coordinates) that is closest to the "best fit" point. The first element should be the x-coordinate, and the second element should be the y-coordinate.

 

Definition

    
Class: MissileTarget
Method: bestFit
Parameters: int[], int[]
Returns: int[]
Method signature: int[] bestFit(int[] x, int[] y)
(be sure your method is public)
    
 
 

Notes

The cartesian distance between two points (x1, y1) and (x2, y2) is defined as Sqrt((x2-x1)^2 + (y2-y1)^2).
The return value must be within 1e-9 absolute or relative error of the actual result.
 

Constraints

x will contain between 1 and 50 elements, inclusive.
x and y will contain the same number of elements.
Each element of x will be between -1000000 and 1000000, inclusive.
Each element of y will be between -1000000 and 1000000, inclusive.
The actual (possibly non-lattice) best fit point will be at least 1e-2 closer to the correct return value than to any other lattice point.
 

Examples

0)  
    
These three impacts are all pretty close to the origin, and sure enough, the origin is the best fit point.
1)  
    
With only one point, it is its own best fit.
2)  
    
With only two points, the best fit is the midpoint between the two.
3)  
    
 
4)  
    
In this case, notice that the actual best fit point possible is (5.333, 0). If we look at lattice points only, then our best fit is (6, 0), however, we are interested in the lattice point that is closest to the actual best fit point, so we return (5, 0).

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2005, TopCoder, Inc. All rights reserved.


 

This is another problem that is fairly easily solved with a bit of grunt work to calculate out the desired values. Since we are looking for the lattice point that is closest to our best fit, our best bet is to first calculate the location of the actual best fit point (using floating point, that is), and then find the closest lattice point.

To find the best fit point, we one important observation: calculating the best fit x-coordinate and the best fit y-coordinate separately will give us our best fit point. Why? Since the scoring of a point as being best fit is based upon the sum of the squares of the distances from each of the points, we see that:

score = sum(d^2) = sum(sqrt((xx0)^2 – (yy0)^2)^2)
  = sum((xx0)^2 + (yy0)^2)
  = sum((xx0)^2) + sum((yy0)^2)

So, to minimize the score, it suffices to minimize each sum separately.

To minimize each sum, a ternary search works well. However, in this case, if you were inclined to do the mathematical gruntwork, then you found a nice shortcut. The average of the x-coordinates will give you the x-coordinate of the best fit point, and the same goes for the y-coordinates. (Why? Hint: Use calculus to prove where the minimum value is.)

Either way, once you have the location of the best fit point it's just simply a matter of finding the closest lattice point, and the easiest way to do this is by rounding. (Note the constraints were intended to prohibit the case where a point was equidistant from multiple lattice points.)

TopCoder(R) Single Round Match 257

本来想试试昨天的TopCoder(R) Single Round 的的,起得太晚了,没赶上Registration ,哎~~~可惜。。。
贴上题目做做吧
 


 

SubstitutionCode  Point 250
 Division Two – Level One

 

Problem Statement for SubstitutionCode

Problem Statement

     A simple, easy to remember system for encoding integer amounts can be very useful. For example, dealers at flea markets put the information about an item on a card that they let potential buyers see. They find it advantageous to encode the amount they originally paid for the item on the card.

A good system is to use a substitution code, in which each digit is encoded by a letter. An easy to remember 10-letter word or phrase, the key, is chosen. Every '1' in the value is replaced by the first letter of the key, every '2' is replaced by the second letter of the key, and so on. Every '0' is replaced by the last letter of the key. Letters that do not appear in the key can be inserted anywhere without affecting the value represented by the code.. This helps to make the resulting code much harder to break (without knowing the key).

Create a class SubstitutionCode that contains the method getValue that is given the Strings key and code as input and that returns the decoded value.

 

Definition

    
Class: SubstitutionCode
Method: getValue
Parameters: String, String
Returns: int
Method signature: int getValue(String key, String code)
(be sure your method is public)
    
 
 

Constraints

code contains between 1 and 9 characters inclusive, all uppercase letters 'A'-'Z'
code contains at least one letter that is found in key
key contains exactly 10 uppercase letters 'A'-'Z', all distinct from each other
 

Examples

0)  
    
The L,X, and V are ignored since they do not appear in the key. G is the seventh letter in the key, W is the 10th letter, and E is the 9th letter.
1)  
    
 
2)  
    
 

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2005, TopCoder, Inc. All rights reserved.

 

 


 

BridgePts  Point 500
 Division Two – Level Two

 

Problem Statement for BridgePts

Problem Statement

     A deck of cards contains 52 cards. Each card has a suit (Clubs,Diamonds,Hearts,Spades) and a value (Ace,2,3,…,9,10,Jack,Queen,King). In the game of bridge a hand consists of 13 cards from the deck.

A player needs to evaluate his hand, giving it a point value. The standard method is as follows: count 4 points for each Ace, 3 points for each King, 2 points for each Queen, and 1 point for each Jack. For each suit, count 1 point if the hand contains exactly two cards of that suit, 2 points if exactly one card, and 3 points if the hand contains no cards of that suit. The point value of the hand is the sum of all these points.

Create a class BridgePts that contains a method pointValue that is given a int[] hand and that returns the point value of the hand.

Each element of hand indicates a card. The clubs are numbered 1 to 13, the diamonds are 14 to 26, the hearts are numbered 27 to 39, and the spades are numbered 40 to 52. Within each suit, the cards are numbered in the order Ace, 2, 3, …, 9, 10, Jack, Queen, King. So, for example, the King of Hearts is numbered 39 and the Ace of Spades is numbered 40.

 

Definition

    
Class: BridgePts
Method: pointValue
Parameters: int[]
Returns: int
Method signature: int pointValue(int[] hand)
(be sure your method is public)
    
 
 

Constraints

hand will contain exactly 13 elements, all distinct.
Each element of hand will have a value between 1 and 52 inclusive.
 

Examples

0)  
    
This hand contains all diamonds, so it has one Ace, one King, one Queeen, and one Jack, and it contains no cards in three suits. So its point value is 4 + 3 + 2 + 1 + 3 + 3 + 3 = 19.
1)  
    
This hand contains only 2's, 3's, 4's and one 5. It has 3 or 4 cards in each suit.

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2005, TopCoder, Inc. All rights reserved.

 

 


 

TimeCard  Point 1000
 Division Two – Level Three

 

Problem Statement for TimeCard

Problem Statement

     When I start my shift at work I punch in my starting time, and when I leave I punch out. The times are printed on a card using exactly 8 characters in the format where hh is the 2 digit representation of the hour, mm is the 2 digit representation of the minute, and xx is either am or pm. The ':' and ',' are literal. "12:00,am" denotes midnight, while "12:00,pm" denotes noon.

The difference between that time I punch in and the time I punch out is the amount of time I have worked so, for example, if I punch in at 03:33pm and punch out at 03:34pm I have worked 1 minute.

No shift is allowed to be more than 20 hours long. This is my last shift of the week and I am supposed to work 40 hours during the week. Create a class TimeCard that contains a method leave that is given a String[] time of all the times on this week's timecard and that returns a String (using the same format) that tells when I can leave and have exactly 40 hours for the week. Return "BELOW 40" or "ABOVE 40" if it is not possible to get exactly 40 hours. In all cases, the return should contain exactly 8 characters.

The elements of time alternate: punch in time, punch out time, punch in time, … with the final element being the time I just punched in on my final shift.

 

Definition

    
Class: TimeCard
Method: leave
Parameters: String[]
Returns: String
Method signature: String leave(String[] time)
(be sure your method is public)
    
 
 

Constraints

time will contain an odd number of elements between 1 and 49 inclusive.
Each element of time will be formatted as above.
In each element of time hh will be between 01 and 12 inclusive.
In each element of time mm will be between 00 and 59 inclusive.
time will contain no shift that exceeds 20 hours in duration.
 

Examples

0)  
    
This is my one and only shift, and I am only allowed to work 20 hours on a shift.
1)  
    
I have worked 4 previous shifts of 8 hours, so I need 8 hours on this shift to make 40.
2)  
    
I have already worked 2 shifts of 20 hours so I already have exactly 40 hours. I should go home immediately.
3)  
    
 
4)  
    
 

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2005, TopCoder, Inc. All rights reserved.

下定决心 不知道这一次能不能坚持。。。

  好长时间没动过手了,coding 这东西是会生手的
  决定了,现在开始一段时间做点东西(一周一次吧先,住校问题),要不就废了
  高中的时候,动手的机会还是挺多的,现在学校的公共基础课搞得我头都大了,哎~~~
  不过大二就开始有专业基础课了,哈哈!!!不怕喽,本人对自己的专业还是挺有自信的,哈哈哈哈,有高中语文课上打下的牢固基础(语文可一窍不通喔),专业科应该不会像公共基础课那样狼狈吧
   电路好过,信号系统应该可以,C语言、工程制图已经过了,计算机软件基础第二学期就修掉它,模电和数字逻辑电路希望可以过(听说关人很厉害),把大一的没过的科也修掉,想办法把大三的微机原理和VHDL也修了,电磁场理论和概率论与随机过程就看情况了,hoho

  坚持,坚持!!!
  加油,加油!!!
  相信自己!!!

Practise – Inv 2001 R1 Point 250

Problem Statement