UVa 1620 Lazy Susan (找规律)】的更多相关文章

题意:给 n 个数,每次可以把4个连续的数字翻转,问你能不能形成1-n的环状排列. 析:找一下奇偶性,写几个数试试,就会找到规律. 代码如下: #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <set> #include <qu…
题目: 把1~n(n≤500)放到一个圆盘里,每个数恰好出现一次.每次可以选4个连续的数字翻转顺序.问能不能变成1.2.3....n的顺序. 思路: 这样的题的规律真的是一点都不好推,看了网上的博客知道只有n为奇数且给出的序列的逆序数为奇数的时候,这种情况下是不能完成的,其余的情况都可以. 如果n为偶数,那么在这个环中总有4个连续的数字的逆序数是偶数,假设4个数的逆序数是x,翻转之后逆序数变成了6-x(为什么是6-x自己还没有搞懂),逆序数的变化为6-2x为偶数.最后升序的逆序数是0为偶数.根据…
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2544解题报告:小明有一个老式计算器,这个计算器只能显示n位数,现在小明输入一个数k,并且将这个数k一直做平方运算,当得到的结果大于n位的时候 ,这个计算器会自动取最高的n位,问这样一直进行下去能得到的最大的数是多少? 很显然,屏幕上显示的数会有一个周期,例如,当输入1 6 的时候,…
直接说几个比较明显的规律吧. k个小时以后,红气球的个数为3k. 单独观察一行: 令f(r, k)为k个小时后第r行红气球的个数. 如果r为奇数,f(r, k) = f((r+1)/2, k-1) * 2 如果r为偶数,f(r, k) = f(r/2, k-1) 令g(r, k)为k个小时后前r行红气球的个数. 如果r为偶数,g(r, k) = g(r/2, k-1) * 3; 如果r为奇数,g(r, k) = g(r-1, k) + f(r, k); 因此f和g都可以用递归求解. #inclu…
Problem B Number Sequence Input: standard input Output: standard output Time Limit: 1 second A single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number groups S1S2…Sk. Each group Sk con…
题目链接 #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <ctime> #include <cstdlib> #include <iostream> using namespace std; ]; ]; int main() { ,i,len,sum,ans; scanf("%d",&am…
题目:题目链接 思路:1到4是很容易写出来的,我们先考虑这四种情况的绘制顺序 1:ru 2:rulu 3:rululdlu 4:rululdluldrdldlu 不难发现,相较于前一行,每一次增加一倍数量,并且增加的这部分前一半和原来正好相反,后一半相同,根据这一性质,预处理出极端情况13的解答字符串,然后绘制即可,注意控制行尾空格 AC代码: #include <iostream> #include <cstdio> #include <cstring> #inclu…
原来做过的题再看还是没想出来,看来当时必然没有真正理解.这次回顾感觉理解更透彻了. 网上的题解差不多都是一个版本,而且感觉有点扯.根据n=20猜出来的? 好吧哪能根据一个就猜到那么变态的公式.其实这题稍微找下规律就好.当然可能没有公式法效率高,但理解起来更容易吧. 你用n=20的例子,那么我也用.但我的想法是这样的. sum = 0; 我们考虑 i 是多少时 n/i = 1: 20/1 = 20, 故i <= 20, 又20/2 = 10,  故i > 10, 即 10 < i <…
/** 题目:GCD XOR UVA 12716 链接:https://vjudge.net/problem/UVA-12716 题意:给定一个n,找多少对(a,b)满足1<=b<=a<=n,gcd(a,b)=a^b: 思路: 打表找规律发现:满足条件的结果一定满足,gcd(a,b) = a-b; 即:先确定每一个a以及它的约数c可以获得,b = a-c; 如果a^b=c 那么满足. 时间复杂度nlg(n) */ #include <iostream> #include &l…
题目传送门 /* 题意:汉诺塔问题变形,多了第四个盘子可以放前k个塔,然后n-k个是经典的汉诺塔问题,问最少操作次数 递推+高精度+找规律:f[k]表示前k放在第四个盘子,g[n-k]表示经典三个盘子,2 ^ (n - k) - 1 所以f[n] = min (f[k] * 2 + g[n-k]),n<=10000,所要要用高精度,另外打表能看出规律 */ /************************************************ * Author :Running_Ti…
我看大多数人的博客只说了一句:找规律得答案为(n + m) / gcd(n, m) 不过神题的题解还须神人写.. 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…
本文出自   http://blog.csdn.net/shuangde800 题目点击打开链接 题意: 汉诺塔游戏请看 百度百科 正常的汉诺塔游戏是只有3个柱子,并且如果有n个圆盘,至少需要2^n-1步才能达到目标. 但是在这题中,有4根柱子,并且按照下面规则来玩: 1. 先把圆盘顶部前k个盘子全部搬到第四根柱子上, 2. 然后把剩下的n-k个盘子在前3根柱子中按照经典的规则搬到某个柱子上(假设是a柱), 3. 最后再把那k个盘子搬到目标a柱上. 问按照这样的规则,最少需要几步? 思路: 我们…
题意:初始串为一个1,每一步会将每个0改成10,每个1改成01,因此1会依次变成01,1001,01101001,……输入n(n<=1000),统计n步之后得到的串中,"00"这样的连续两个0出现了多少次. 分析:找规律,输出n等于20之前所有的结果 得到结论,i为奇数时,a[i] = a[i - 1] * 2 - 1; i为偶数时,a[i] = a[i - 1] * 2 + 1. import java.util.*; import java.math.BigInteger;…
题目链接 Problem Description KazaQ wears socks everyday. At the beginning, he has n pairs of socks numbered from 1 to n in his closets. Every morning, he puts on a pair of socks which has the smallest number in the closets. Every evening, he puts this pa…
A Simple Problem with Integers 这个题目首先要打表找规律,这个对2018取模最后都会进入一个循环节,这个循环节的打表要用到龟兔赛跑. 龟兔赛跑算法 floyed判环算法 这个算法我觉得还是很有意思的,可以学习一下. 不过这个题目这个算法打表还是有点难写的. 由这个算法可以得到这个循环节的最大长度是6 最大入环距离是4. 为什么有些循环节不是6,还是可以用6呢,因为每个元素平方最大周期为6,且6是其他所有周期的公倍数. 然后学完之后还是不太会这个题目怎么写,2018…
这道题是有规律的博弈题目,,, 所以我们只需要找出规律来就ok了 牛人用sg函数暴力找规律,菜鸟手工模拟以求规律...[牢骚] if(m>=2) { if(n<=m) {first第一口就可以吃掉所有的.所以first必赢,} else {first无法一口吃掉所有的,所以second成了主动的了,如果first第一口吃掉k1个,那么明智的second只要吃掉k2个就可以了(n-k1-k2是偶数,也包括 0的),使得 剩下的数字是分成两个数字数目相等的堆,以后的工作便是first做什么,那么s…
已知有n个单位的水,问有几种方式把这些水喝完,每天至少喝1个单位的水,而且每天喝的水的单位为整数.看上去挺复杂要跑循环,但其实上,列举几种情况之后就会发现是找规律的题了= =都是2的n-1次方,而且这题输出二进制数就行了......那就更简单了,直接输出1,然后后面跟n-1个0就行了╮(╯_╰)╭ 下面AC代码 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm>…
2014多校 第八题 1008 2014 Multi-University Training Contest 8 4952 Number Transformation Number Transformation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 85 Accepted Submission(s): 31 Problem Descr…
http://codeforces.com/contest/456/problem/B CF#260 div2 B Fedya and Maths Codeforces Round #260 B. Fedya and Maths time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Fedya studies in a gymnasi…
题意:找字串中最长回文串的最小值的串 m=2的时候暴力打表找规律,打表可以用二进制枚举…
题目传送门 /* 水题 找规律输出 */ #include <cstdio> #include <iostream> #include <cstring> #include <string> #include <map> #include <algorithm> #include <vector> #include <set> #include <cmath> using namespace std…
Javabeans are delicious. Javaman likes to eat javabeans very much. Javaman has n boxes of javabeans. There are exactly i javabeans in the i-th box (i = 1, 2, 3,...n). Everyday Javaman chooses an integer x. He also chooses several boxes where the numb…
递归思想的条件:1.函数自己调用自己 2.函数必须有一个固定的返回值(如果没有这个条件会发生死循环) ----规律很重要 简单递归题目一: 设计一个函数计算一个整数的n次方,比如2的3次方,就是8 步骤: 1.定义方法,以及方法中的参数--power( int base ,int n ) 2.根据定义的方法来找规律: 函数终止条件:n==0时,返回1:n<0时,返回-1:红色箭头表示函数的执行过程,蓝色箭头表示函数达到条件后开始一层一层的返回值,具体代码如下: long power(int ba…
讨厌博弈,找规律找半天还是错的.... 1228: [SDOI2009]E&D Time Limit: 10 Sec Memory Limit: 162 MB Submit: 666 Solved: 380 [Submit][Status][Discuss] Description 小E 与小W 进行一项名为"E&D"游戏.游戏的规则如下:桌子上有2n 堆石子,编号为1..2n.其中,为了方便起见,我们将第2k-1 堆与第2k 堆(1 ≤ k ≤ n)视为同一组.第i堆…
Nim or not Nim? Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 3032 Description Nim is a two-player mathematic game of strategy in which players take turns removing objects from distinct heaps.…
题目传送门 /* 找规律/数位DP:我做的时候差一点做出来了,只是不知道最后的 is_one () http://www.cnblogs.com/crazyapple/p/3315436.html 数位DP:http://blog.csdn.net/libin56842/article/details/11580497 */ #include <cstdio> #include <iostream> #include <algorithm> #include <c…
题目地址:http://acm.sgu.ru/problem.php?contest=0&problem=126 /* 找规律,智商不够,看了题解 详细解释:http://blog.csdn.net/ahfywff/article/details/7432524 */ #include <cstdio> #include <cmath> #include <cstring> #include <string> #include <iostrea…
Problem about GCD Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 470    Accepted Submission(s): 77 Problem Description Given integer m. Find multiplication of all 1<=a<=m such gcd(a, m)=1 (cop…
Description Farmer John's N cows (1 <= N <= 100,000) are lined up in a row.Each cow is labeled with a number in the range 1...K (1 <= K <=10,000) identifying her breed. For example, a line of 14 cows might have these breeds: 1 5 3 2 5 1 3 4 4…
Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6012   Accepted: 3341 Description N children standing in circle who are numbered 1 through N clockwise are waiting their candies. Their teacher distributes the candies by in the following w…