HDU 5312 Sequence (规律题)】的更多相关文章

题意: 一个序列的第n项为3*n*(n-1)+1,而 n>=1,现在给一个正整数m,问其最少由多少个序列中的数组成? 思路: 首先,序列第1项是1,所以任何数都能构成了.但是最少应该是多少?对式子进行变形,6*(n*(n-1)/2)+1,看到了三角形数n*(n-1)/2,那么应该是6*(任意自然数)+x=m才对,因为最多只要3个三角形数就能组成任何自然数啦. 不妨试试m%6是多少?这样试图求x可以吗?因为任意自然数最多由3个组成,如果是k个,那么应该x>=k,别忘了还有个+1的项.x-k那部分…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5312 Sequence Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 1336    Accepted Submission(s): 410 Problem Description Today, Soda has learned a…
Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. Given A, B, and n, you are to calculate the value of f(n).   Input The input consists of multiple test cases. Each test case…
Problem Description Today, Soda has learned a sequence whose n-th (n≥) item )+. Now he wants to know if an integer m can be represented as the sum of some items of that sequence. If possible, what are the minimum items needed? For example, =+++=+++.…
Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2159    Accepted Submission(s): 614 Problem Description Here are two numbers A and B (0 < A <= B). If B cannot be divisible by A, and A an…
解题报告:规定数字1和数字2是Friend number,然后规定,若a和b是Friend number,那么a*b+a+b也是Friend number,输入一个数,让你判断这个数是否是Friend number. Friend number = (2^x)*(3^y)-1:如果判断出某个数能满足这个关系,则这个数就是Friend number. #include<cstdio> <<-; int main() { int n; while(scanf("%d"…
Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 137047    Accepted Submission(s): 33211 Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (…
UVa 1584 题目大意:给定一个含有n个字母的环状字符串,可从任意位置开始按顺时针读取n个字母,输出其中字典序最小的结果 解题思路:先利用模运算实现一个判定给定一个环状的串以及两个首字母位置,比较二者字典序大小的函数, 然后再用一层循环,进行n次比较,保存最小的字典序的串的首字母位置,再利用模运算输出即可 /* UVa 1584 Circular Sequence --- 水题 */ #include <cstdio> #include <cstring> //字符串s为环状,…
HDU 3397 Sequence operation 题目链接 题意:给定一个01序列,有5种操作 0 a b [a.b]区间置为0 1 a b [a,b]区间置为1 2 a b [a,b]区间0变成1,1变成0 3 a b 查询[a,b]区间1的个数 4 a b 查询[a,b]区间连续1最长的长度 思路:线段树线段合并.须要两个延迟标记一个置为01,一个翻转,然后因为4操作,须要记录左边最长0.1.右边最长0.1,区间最长0.1,然后区间合并去搞就可以 代码: #include <cstdi…
Given an m x n chessboard where you want to place chess knights. You have to find the number of maximum knights that can be placed in the chessboard such that no two knights attack each other. Those who are not familiar with chess knights, note that…