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. Ctrl-A全选

    Ctrl-A全选这点事(C#,WinForm)   所有的文本框,不管单行多行都Ctrl-A全选就好了吧?是啊,很方便.Windows的软件基本都是这样.可为什么我们自己制作的WinForm就默认不是 ...

  2. 读取USB HDD(USB移动硬盘信息)序列号的代码

    读取USB HDD(USB移动硬盘)序列号的代码,型号及分位. 使用Visual Studio 2010编译成功. 代码使用了CrystalDiskInfo中的代码smartata.c中相关代码: 例 ...

  3. hdu 2451 Simple Addition Expression(数位DP )成败在于细节

    亚洲区域赛的题,简单的数位DP题,注重细节. 任何细节都有可能导致wa,所以没有绝对的水题. 把握好细节,此题便A. #include<stdio.h> __int64 getans(__ ...

  4. Django之逆向解析url

    Django中提供了一个关于URL的映射的解决方案,你可以做两个方向的使用: 1.有客户端的浏览器发起一个url请求,Django根据URL解析,把url中的参数捕获,调用相应的试图, 获取相应的数据 ...

  5. mysql-merge合并表

    merge表 注意: 1 每个子表的结构必须一致,主表和子表的结构需要一致, 2 每个子表的索引在merge表中都会存在,所以在merge表中不能根据该索引进行唯一性检索. 3 子表需要是MyISAM ...

  6. cocos2dx 制作单机麻将(一)

    今天開始打算解说下cocos2dx下怎样制作国标麻将 前半部分先解说麻将的逻辑部分,由于都是代码,可能会比較枯燥无聊. 这部分讲完后,你也能够用其它游戏引擎来制作麻将 后半部分,就解说余下的cocos ...

  7. C#如何在钉钉开发平台

    C#如何在钉钉开发平台中创建部门   钉钉是阿里巴巴专为中小企业和团队打造的沟通.协同的多端平台,钉钉开放平台旨在为企业提供更为丰富的办公协同解决方案.通过钉钉开放平台,企业或第三方合作伙伴可以帮助企 ...

  8. 三点半们耐热i哦好家哦i囧囧【

    http://pan.baidu.com/share/link?shareid=3011665141&uk=338692646&third=15                http ...

  9. VS2010升级VS2013后,出现没有定义类型“PowerPacks.ShapeContainer”错误解决方法

    开发说明: http://msdn.microsoft.com/zh-tw/library/microsoft.visualbasic.powerpacks.aspx Microsoft.Visual ...

  10. atitit.java方法属性赋值and BeanUtils 1.6.1 .copyProperty的bug

    atitit.java分配给属性值方法and BeanUtils 1.6.1 .copyProperty的bug 1. core.setProperty(o, "materialId&quo ...