UVA 11774 - Doom's Day

题目链接

题意:给定一个3^n*3^m的矩阵,要求每次按行优先取出,按列优先放回,问几次能回复原状

思路:没想到怎么推理,找规律答案是(n + m) / gcd(n, m),在topcoder上看到一个证明,例如以下:

We can associate at each cell a base 3-number, the log3(R) most significant digits is the index of the row of the cell and the log3(C) least significant digits is the index of his column.

What are the transformation now ?

position in row-major order is rC+c

position in column-major order is cR+r

We should shift down by log3(C) the most significant digits and shift up the least significant digits by log3(R).

C=3^6, R=3^4

now : rrrrcccccc (rrrr)(cccccc)

then: ccccccrrrr (cccc)(ccrrrr)

the first 4 digit are always the number of row (0-indexed) and the last 6 digit the number of column of the cell (0-indexed)

Now this process is valid for each possible r or c, so we can choose r=1 and c=0 and find a the length of this recurring cycle.

Calling L the length of this basic cycle, all other cycle are combination of this one so the only possible length are divisor of L, so the solution of our problem is (m+n)/L

rrrr=0001

cccccc=000000

day 0 : 0001000000 (0001)(000000)

day 1 : 0000000001 (0000)(000001)

day 2 : 0000010000 (0000)(010000)

day 3 : 0100000000 (0100)(000000)

day 4 : 0000000100 (0000)(000100)

day 5 : 0001000000 (0001)(000000)

For solving this problem we can find the the minimal x such that x*n mod (n+m)=0, this imply x=gcd(n, n+m)=gcd(n, m).

The solution of our original problem is (n+m)/x or (n+m)/gcd(n,m).

然后看了之后还是不理解啊,有哪个大神理解这个推理过程求指导一下。。

代码:

#include <stdio.h>
#include <string.h> int t;
long long n, m; long long gcd(long long a, long long b) {
if (!b) return a;
return gcd(b, a % b);
} int main() {
int cas = 0;
scanf("%d", &t);
while (t--) {
scanf("%lld%lld", &n, &m);
printf("Case %d: %lld\n", ++cas, (n + m) / gcd(n, m));
}
return 0;
}

UVA 11774 - Doom&#39;s Day(规律)的更多相关文章

  1. UVA - 11774 Doom's Day

    看样例猜结论hhhhhh,竟然蒙对了..(正确性待证明) #include<bits/stdc++.h> #define ll long long using namespace std; ...

  2. UVa 11774 (置换 找规律) Doom's Day

    我看大多数人的博客只说了一句:找规律得答案为(n + m) / gcd(n, m) 不过神题的题解还须神人写.. We can associate at each cell a base 3-numb ...

  3. 紫书 习题 10-13 UVa 11526(打表找规律+分步枚举)

    首先看这道题目,我预感商数肯定是有规律的排列的,于是我打表找一下规律 100 / 1 = 100 100 / 2 = 50  100 / 3 = 33  100 / 4 = 25  100 / 5 = ...

  4. UVa 102 - Ecological Bin Packing(规律,统计)

    题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...

  5. UVA 816 - Abbott&#39;s Revenge(BFS)

    UVA 816 - Abbott's Revenge option=com_onlinejudge&Itemid=8&page=show_problem&category=59 ...

  6. UVa 808 (建坐标系、找规律) Bee Breeding

    题意: 如图,按照图中的规律给这些格子编号.给出两个格子的编号,求从一个格子到另一个格子的最少步数.(一步只能穿过有有公共边的格子) 分析: 根据高中数学知识,选任意两个不共线的向量,就能表示平面上所 ...

  7. uva 11825 Hackers&#39; Crackdown (状压dp,子集枚举)

    题目链接:uva 11825 题意: 你是一个黑客,侵入了n台计算机(每台计算机有同样的n种服务),对每台计算机,你能够选择终止一项服务,则他与其相邻的这项服务都终止.你的目标是让很多其它的服务瘫痪( ...

  8. UVA 10831 - Gerg&#39;s Cake(数论)

    UVA 10831 - Gerg's Cake 题目链接 题意:说白了就是给定a, p.问有没有存在x^2 % p = a的解 思路:求出勒让德标记.推断假设大于等于0,就是有解,小于0无解 代码: ...

  9. UVA 12103 - Leonardo&#39;s Notebook(数论置换群)

    UVA 12103 - Leonardo's Notebook 题目链接 题意:给定一个字母置换B.求是否存在A使得A^2=B 思路:随意一个长为 L 的置换的k次幂,会把自己分裂成gcd(L,k) ...

随机推荐

  1. python(abi) RPM DEB Download

    python(abi) RPM DEB Download python(abi) RPM DEB Download

  2. linux中怎样设置DHCP

    linux怎样设置DHCP 环境:RH linux 9.0 使用linux下经常使用的dhcpd包. 最新版本号 dhcp3.0.5 下载地址: 下载 1.安装: 先拷贝dhcp-3.0.5.tar. ...

  3. Install Linux Kernel - AT91SAM9260EK

    两.AT91SAM9260EK 2.1下载 介绍页: http://www.at91.com/linux4sam/bin/view/Linux4SAM/LegacyLinuxKernel 下载页: a ...

  4. pygame系列

    在接下来的blog中,会有一系列的文章来介绍关于pygame的内容,pygame系列偷自http://www.cnblogs.com/hongten/p/hongten_pygame_install. ...

  5. Spring中Quartz动态设置cronExpression

    字段 允许值 允许的特殊字符 秒 0-59 , - * / 分 0-59 , - * / 小时 0-23 , - * / 日期 1-31 , - * ? / L W C 月份 1-12 或者 JAN- ...

  6. Java重命名文件

    File file = new File("D:\\aa\a.txt");     file.renameTo(new File("D:\\aa\\b.txt" ...

  7. POJ 1274 The Perfect Stall 水二分匹配

    主题链接:id=1274">点击打开链接 呵呵 #include<cstdio> #include<cstring> #include<cstdlib&g ...

  8. 使用JustDecompile修改程序集

    原文:使用JustDecompile修改程序集        JustDecompile是Telerik公司推出一个免费的.net反编译工具,支持插件,与Visual Studio 2010,2012 ...

  9. JS多语种方式

    方案: 在不同的移动平台(IOS.Android)上,并建立了HTML页面通信框架.主要业务逻辑HTML发展:我要支持多语言开发. 动机: 通过积极主动的信息方式,前一页完成初始化,获取当前语言选项. ...

  10. POJ 3450 Corporate Identity KMP解决问题的方法

    这个问题,需要一组字符串求最长公共子,其实灵活运用KMP高速寻求最长前缀. 请注意,意大利愿父亲:按照输出词典的顺序的规定. 另外要提醒的是:它也被用来KMP为了解决这个问题,但是很多人认为KMP使用 ...