一个直径为一米(常量)的钢质圆盘,水平放置,围绕中轴转动。 在距离圆心80厘米(常量)处的圆盘竖直上方有一个固定不动的激光发射器,向下发射对圆盘进行打孔。
圆盘初始匀速旋转,每秒钟转动x度,激光发射器每y秒钟发射一次给圆盘打孔,
圆盘每被打一个孔,旋转速度就会增加n倍(即为原速度的n+1倍)。
请问,在m秒钟内,圆盘一共会被打多少个孔。
说明:输入值:x,y,m,n
输入值:孔数(int)
大家给个思路
圆盘初始匀速旋转,每秒钟转动x度,激光发射器每y秒钟发射一次给圆盘打孔,
圆盘每被打一个孔,旋转速度就会增加n倍(即为原速度的n+1倍)。
请问,在m秒钟内,圆盘一共会被打多少个孔。
说明:输入值:x,y,m,n
输入值:孔数(int)
大家给个思路
解决方案 »
- DataSet.ReadXml与NetworkStream的问题
- 如何将VS2005的默认启动语言设置成C#,而不是C++?
- 请问如何复制选择的文件夹中的所有文件到另一文件夹
- 轻松解决Visual Studio 2005 开发环境遇到的几个疑难杂症问题
- 有没有ASP.net的数据生成器?
- 如何获取IE缓存文件
- 我用js给select控件赋值,当我点击服务器控件Button后,Select控件的值都丢失了?请问这是怎么回事呢?
- 如何调用DELPHI写的DLL呢?
- 我应该的用什么类型的变量接它
- 如何用C#开发一个基于http协议的发送邮件功能
- C#输入
- 如何截获webBrowser控件发送的数据以及接收到的数据??
1.孔的大小忽略
2.打完孔后,旋转速度瞬间提升到原来的N+1倍
3.直径1M应该是半径1M吧
最后的孔数应该就是m/y再减去重复打点的个数
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)
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;
}
}
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;
}
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;
}
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;
}
}
}
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;
}
}
}