逻辑题

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


大家给个思路
...全文
246 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
打死不掉牙 2010-03-23
  • 打赏
  • 举报
回复
不符合逻辑的题目,呵呵!
TimDavid 2010-03-23
  • 打赏
  • 举报
回复
经理说,上面写代码的都应该得零分。
题目都没看清。
着急干啥....
直径1m,在离圆心0.8m的地方打孔...
无论过都是一个没打上....
lcyjackson 2010-03-23
  • 打赏
  • 举报
回复
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;
}
}
}
lcyjackson 2010-03-23
  • 打赏
  • 举报
回复

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;
}
}
}

liyoubaidu 2010-03-23
  • 打赏
  • 举报
回复
重复的算吗?
lcyjackson 2010-03-23
  • 打赏
  • 举报
回复
直径是1米,半径就是50厘米,那在距离圆心80厘米的地方打洞,能打到圆盘上吗
c_xp2006 2010-03-23
  • 打赏
  • 举报
回复
还是漏了一个问题,楼主思路是对的,应该用规定时间内的激光发射次数来循环,再次修正算法
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;
}
c_xp2006 2010-03-23
  • 打赏
  • 举报
回复
忽略了个问题,没有考虑到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;
}
悟__空 2010-03-23
  • 打赏
  • 举报
回复
好像一个孔都打不上吧?!
直径1米,距离圆心80厘米处不是在圆盘的外面么?
蜜_Lumia 2010-03-23
  • 打赏
  • 举报
回复
我看不懂。。。
cxy0303 2010-03-22
  • 打赏
  • 举报
回复
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;
}
}
BigRytian 2010-03-22
  • 打赏
  • 举报
回复
太有才了
c_xp2006 2010-03-22
  • 打赏
  • 举报
回复
稍微写了一下实现,只考虑最简单的精度,用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)
JustOneLastKiss 2010-03-22
  • 打赏
  • 举报
回复
这个题目应该加点限制:
1.孔的大小忽略
2.打完孔后,旋转速度瞬间提升到原来的N+1倍
3.直径1M应该是半径1M吧
最后的孔数应该就是m/y再减去重复打点的个数
cxy0303 2010-03-22
  • 打赏
  • 举报
回复
直径1米是大小,在80处打孔啊

还有要考虑重复的,如果转速过快的哈,,有可能打在同一个孔上
mail_ylei 2010-03-22
  • 打赏
  • 举报
回复
直径为1米 怎么后面又来 距圆心80厘米 ?????/
criedshy 2010-03-22
  • 打赏
  • 举报
回复
旋转速度和y打一个孔有关系吗?

如果没有就是m/y

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧