博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[TopCoder] SRM_594_DIV2.250
阅读量:4349 次
发布时间:2019-06-07

本文共 1831 字,大约阅读时间需要 6 分钟。

好长一段时间没写博客了,实在是想不出有什么好写的。近期也有对自己的职业做了一点思考,还是整理不出个所以然来,很是烦躁 ...

 

研究TopCoder已经有一小段时间了,都是在做之前的题目,还没有实际参加过比赛。以后应该会开设一个topcoder的分类专门写一些里面的一些题目,就当做笔记来写 ...

比较喜欢这种解题的方式,有一些题目还是很有挑战性的,这次先贴出一题做一下暖身。(SRM 594 DIV 2)

 

1、这是道250分的题,原题是:

Fox Ciel is now in high school. The seats in her classroom are arranged into an n by m matrix. The rows are numbered from 0 to n-1 (front to back) and the columns from 0 to m-1 (left to right).At the beginning, Ciel can choose any of the seats. Then, at the end of each week Ciel will shift one row to the back and one column to the right, wrapping around whenever necessary. Formally, if her current seat is in row r and column c, then her seat next week will be the one in row ((r+1) modulo n) and column ((c+1) modulo m).Fox Ciel now wonders whether she can sit in all the seats in the classroom if she follows the above procedure. As we already mentioned, she can start in any of the seats. Also, she can attend the school for as many weeks as she wants to. Return "Possible" if she can sit in all the seats and "Impossible" otherwise.

请原谅我蹩脚的英语水平,我只能偷偷地打开Google翻译一下,大致理解一下应该是以下的意思:

某个家伙在上高中,教室里有n×m个座位,编号从0开始。这货一开始可以随便选一个座位,假设为(x, y),一个星期后,他就要换到现在座位的右后方一个位置,即(x+1, y+1),如果此时他正好坐在最边上,那就从对边的地方开始,即如果x+1=n => x=0; 如果y+1=m => y=0; 换成计算公式就是((x+1)%n, (y+1)%m)。假设这货还有nnnnnnnn个星期要上课(好悲剧的说),那么在给定的n, m下,请问他是否有可能坐完所有座位(真够蛋疼的)。

 

首先先将题目抽象一下,根据题意,可以知道:

1、根据地球是圆的,绕一圈后会回到原点这个定律(-_-! 哪来的定律?有毛线关系?),这家伙无论一开始选择什么座位,到最后还是会回到这个位置,所以可以忽略"选择第一个座位"的问题。

2、程序结束的标志是,他回到原来的位置时,已经坐完所有座位,or 还没坐完所有座位。

 

题目另外给出了参数n、m的值范围是:2-10;

测试数据:

n=2, m=3, result = Possible

n=2, m=2, result = Impossible

n=4, m=6, result = Impossible

n=3, m=6, result = Impossible

n=5, m=7, result = Possible

n=10, m=10, result = Impossible

 

最暴力的做法是,一个大循环,当回到第一个位置时,判断是否已经遍历了所有位置。

用一个list模拟保存已坐过的位置,根据题目给的公式计算:

转载于:https://www.cnblogs.com/liushicheng1/p/3412526.html

你可能感兴趣的文章
iReport采用JDBC的方式连接Oracle
查看>>
MongoDB 数据库的可视化
查看>>
AOP中的相关概念
查看>>
【转】内存溢出、内存泄漏、内存越界、缓冲区溢出、栈溢出
查看>>
监控系统信息模块psutil
查看>>
python tokenizer
查看>>
类的成员修饰符
查看>>
A - Race to 1 Again
查看>>
HDU 1754 I hate it
查看>>
实现滑动出现删除按钮的代码
查看>>
windows提权exp列表
查看>>
一个老软件测试工程师的日志(转)
查看>>
结对编程
查看>>
Android studio来开发移动App--SQA计划和系统测试规程
查看>>
模式学习(一)
查看>>
高精度计算(二)
查看>>
二位几何运算类
查看>>
ZOJ 3622 Magic Number 打表找规律
查看>>
BZOJ 1079: [SCOI2008]着色方案 记忆化搜索
查看>>
cdoj 1136 邱老师玩游戏 树形背包
查看>>