110,539
社区成员
发帖
与我相关
我的任务
分享
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;
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;
}
}
}