一个直径为一米(常量)的钢质圆盘,水平放置,围绕中轴转动。 在距离圆心80厘米(常量)处的圆盘竖直上方有一个固定不动的激光发射器,向下发射对圆盘进行打孔。
圆盘初始匀速旋转,每秒钟转动x度,激光发射器每y秒钟发射一次给圆盘打孔,
圆盘每被打一个孔,旋转速度就会增加n倍(即为原速度的n+1倍)。
请问,在m秒钟内,圆盘一共会被打多少个孔。
说明:输入值:x,y,m,n
输入值:孔数(int)
大家给个思路

解决方案 »

  1.   

    旋转速度和y打一个孔有关系吗?如果没有就是m/y
      

  2.   

    这个题目应该加点限制:
    1.孔的大小忽略
    2.打完孔后,旋转速度瞬间提升到原来的N+1倍
    3.直径1M应该是半径1M吧
    最后的孔数应该就是m/y再减去重复打点的个数
      

  3.   

    稍微写了一下实现,只考虑最简单的精度,用int,要提高精度的话,可以换类型
    public int PunchCount(int x, int y, int m, int n)
    {
        List<int> lstAngle = new List<int>();    // 初始角度
        int iAngle = 0;    for (int i = 0; i < m; i++)
        {
            // 从零度开始,当前循环中一秒钟转动的角度,再加上前一秒的初始角度
            iAngle += (i * n + 1) * x;
            // 激光器打孔频率
            iAngle *= y;
            // 超过360度,相当于白转圈,直接无视,得到当前时间最后的角度
            iAngle %= 360;        // 如果在这一角度还没有打过孔,记录该角度
            if (!lstAngle.Contains(iAngle))
            {
                lstAngle.Add(iAngle);
            }
        }    // 输出所有孔数
        return lstAngle.Count;
    }测试:
    x = 100;
    y = 1;
    m = 3;
    n = 1;最后打了三个孔,分别在角度100,300,240(600)
      

  4.   

    5楼考虑重复的啊...我自己的,不知道对不对或者还有没考虑到的
        public class LaserBoring
        {
            public float X
            {
                get;
                set;
            }        public int Y
            {
                get;
                set;
            }        public float N
            {
                get;
                set;
            }        /// <summary>
            /// 初始化
            /// </summary>
            /// <param name="x">园每秒转的度数</param>
            /// <param name="y">激光发射的间隔时间</param>
            /// <param name="n">每次打孔后园转速增加的倍数</param>
            public LaserBoring(float x, int y, float n)
            {
                this.X = x;
                this.Y = y;
                this.N = n;
            }        /// <summary>
            /// 得到指定时间内的打孔次数
            /// </summary>
            /// <param name="m">时间(单位:秒)</param>
            /// <returns></returns>
            public Dictionary<double, double> GetBores(int m)
            {
                Dictionary<double, double> Bores = new Dictionary<double, double>();
                int times = (m - m % this.Y) / this.Y;//激光m秒内发射次数
                double temp = 1;
                for (int i = 0; i < times; i++)
                {
                    temp += this.X * this.Y * Math.Pow(this.N + 1, i);
                    temp = temp > 360 ? temp - 360 : temp;
                    if (!Bores.ContainsKey(temp))//此角度是否打过孔
                        Bores.Add(temp, temp);
                }
                return Bores;
            }
        }
      

  5.   

    忽略了个问题,没有考虑到y比m大的情况 修正下模型
    public int PunchCount(int x, int y, int m, int n)
    {// 在规定时间内,激光器还没有发射,一个孔都打不上
    if (y > m)
    {
    return 0;
    }List<int> lstAngle = new List<int>();// 初始角度
    int iAngle = 0;for (int i = 0; i < m; i++)
    {
    // 从零度开始,当前循环中一秒钟转动的角度,再加上前一秒的初始角度
    iAngle += (i * n + 1) * x;
    // 激光器打孔频率
    iAngle *= y;
    // 超过360度,相当于白转圈,直接无视,得到当前时间最后的角度
    iAngle %= 360;// 如果在这一角度还没有打过孔,记录该角度
    if (!lstAngle.Contains(iAngle))
    {
    lstAngle.Add(iAngle);
    }
    }// 输出所有孔数
    return lstAngle.Count;
    }
      

  6.   

    还是漏了一个问题,楼主思路是对的,应该用规定时间内的激光发射次数来循环,再次修正算法
    public int PunchCount(int x, int y, int m, int n)
    {// 在规定时间内,激光器还没有发射,一个孔都打不上
    if (y > m)
    {
    return 0;
    }List<int> lstAngle = new List<int>();// 初始角度
    int iAngle = 0;
    // 激光发射次数
    int shootCnt = m / y;// 打孔角度重复Check
    for (int i = 0; i < shootCnt ; i++)
    {
    // 从零度开始,当前循环中一秒钟转动的角度,再加上前一秒的初始角度
    iAngle += (i * n + 1) * x;
    // 激光器打孔频率
    iAngle *= y;
    // 超过360度,相当于白转圈,直接无视,得到当前时间最后的角度
    iAngle %= 360;// 如果在这一角度还没有打过孔,记录该角度
    if (!lstAngle.Contains(iAngle))
    {
    lstAngle.Add(iAngle);
    }
    }// 输出所有孔数
    return lstAngle.Count;
    }
      

  7.   


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace ConsoleApplication2
    {
        public class Program
        {
            int x;//圆盘转速每秒X度
            int y;//激光打孔每Y秒一次
            int m;//总时间M秒
            int n;//圆盘每被打一个孔,旋转速度就会增加n倍(即为原速度的n+1倍)        public Program()
            {        }        public static void Main(string[] args)
            {
                Program p = new Program();            while (true)
                {
                    Console.Write("输入x:");
                    string x = Console.ReadLine();
                    Console.Write("输入y:");
                    string y = Console.ReadLine();
                    Console.Write("输入m:");
                    string m = Console.ReadLine();
                    Console.Write("输入n:");
                    string n = Console.ReadLine();                try
                    {
                        p.x = int.Parse(x);
                        p.y = int.Parse(y);
                        p.m = int.Parse(m);
                        p.n = int.Parse(n);
                        break;
                    }
                    catch
                    {
                        Console.WriteLine("输入错误!");
                    }
                }            Console.WriteLine(p.calc());
            }        int calc()
            {
                int sum = 0;//打孔数
                List<int> list = new List<int>();//记录每一个孔的位置
                for (int i = 1; i <= m; i++)//共运行m秒
                {
                    if (i % y == 0)//每经过y秒
                    {
                        if (list.Count == 0)//第一次打孔
                        {
                            sum++;
                            list.Add(x * y);//记录位置
                            x = (n + 1) * x;//圆盘转速增加
                        }
                        else
                        {
                            bool b = true;//无位置重叠为true,重叠为false
                            for (int j = 0; j < list.Count; j++)
                            {
                                if (list[j] == (list[list.Count - 1] + x * y) % 360)//位置重叠
                                {
                                    b = false;
                                    break;
                                }
                            }
                            if (b)判断是否重叠,无重叠则打孔
                            {
                                sum++;
                                list.Add((list[list.Count - 1] + x * y) % 360);//记录此次打孔位置
                                x = (n + 1) * x;//圆盘转速增加
                            }
                        }
                    }
                }
                return sum;
            }
        }
    }
      

  8.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace ConsoleApplication2
    {
        public class Program
        {
            int x;//圆盘转速每秒X度
            int y;//激光打孔每Y秒一次
            int m;//总时间M秒
            int n;//圆盘每被打一个孔,旋转速度就会增加n倍(即为原速度的n+1倍)        public Program()
            {        }        public static void Main(string[] args)
            {
                Program p = new Program();            while (true)
                {
                    Console.Write("输入x:");
                    string x = Console.ReadLine();
                    Console.Write("输入y:");
                    string y = Console.ReadLine();
                    Console.Write("输入m:");
                    string m = Console.ReadLine();
                    Console.Write("输入n:");
                    string n = Console.ReadLine();                try
                    {
                        p.x = int.Parse(x);
                        p.y = int.Parse(y);
                        p.m = int.Parse(m);
                        p.n = int.Parse(n);
                        break;
                    }
                    catch
                    {
                        Console.WriteLine("输入错误!");
                    }
                }            Console.WriteLine(p.calc());
            }        int calc()
            {
                int sum = 0;//打孔数
                List<int> list = new List<int>();//记录每一个孔的位置
                for (int i = 1; i <= m; i++)//共运行m秒
                {
                    if (i % y == 0)//每经过y秒
                    {
                        if (list.Count == 0)//第一次打孔
                        {
                            sum++;
                            list.Add(x * y);//记录位置
                            x = (n + 1) * x;//圆盘转速增加
                        }
                        else
                        {
                            bool b = true;//无位置重叠为true,重叠为false
                            for (int j = 0; j < list.Count; j++)
                            {
                                if (list[j] == (list[list.Count - 1] + x * y) % 360)//位置重叠
                                {
                                    b = false;
                                    break;
                                }
                            }
                            if (b)//判断是否重叠,无重叠则打孔
                            {
                                sum++;
                                list.Add((list[list.Count - 1] + x * y) % 360);//记录此次打孔位置
                                x = (n + 1) * x;//圆盘转速增加
                            }
                        }
                    }
                }
                return sum;
            }
        }
    }