UVALive - 7045 Last Defence 【数学】
题目链接
题意
给出两个数
递推式是 |s[i - 1] - s[i - 2]|
然后求这个数列 出现的不同数字的个数
思路
因为 X 和 Y 是整数
那么 我们可以理解为
Y = aX + b
也就是说 会是这样一个数列
(aX + b) (x) ((a - 1) X + b) ((a - 2)X + b) x b
然后 我们发现 最后的 x b
是一个递归的子问题
可以把 x b 看成新的 x y
递归下去
我们发现出口 实际上是 b == 0 的时候
然后对于每一次的迭代 答案都是 (kx + b) / x 也就是 k
当 b 等于0 的时候 迭代结束 答案要加上1 以为最后的0 是没有加上的
然后注意一下 当 给出的初始数字 存在0的时候 要讨论一下
AC代码
#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <list>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits>
#define CLR(a, b) memset(a, (b), sizeof(a));
#define pb push_back
#define bug puts("***bug***");
#define fi first
#define se second
#define L(on) (on<<1)
#define R(on) (L(on) | 1)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define syn_close ios::sync_with_stdio(false); cin.tie(0);
#define sp system("pause");
#define gets gets_s
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <string, int> psi;
typedef pair <string, string> pss;
typedef pair <double, int> pdi;
const double PI = acos(-1.0);
const double EI = exp(1.0);
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fll;
const int maxn = (int)1e5 + 10;
const ll MOD = (ll)1000000000;
int main()
{
int t; cin >> t;
for (int tt = 1; tt <= t; tt++)
{
printf("Case #%d: ", tt);
ll n, m; scanf("%lld%lld", &n, &m);
if (n == 0 || m == 0)
printf("%d\n", n == m ? 1 : 2);
else
{
ll ans = 1;
if (n < m) swap(n, m);
while (m)
{
ans += n / m;
ll tmp = m;
m = n % m;
n = tmp;
}
printf("%lld\n", ans);
}
}
}
UVALive - 7045 Last Defence 【数学】的更多相关文章
- UVALive 7045 Last Defence
ProblemK. Last Defence Description Given two integersA and B. Sequence S is defined as follow: • S0 ...
- UVALive 5058 Counting BST 数学
B - Counting BST Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit S ...
- UVaLive 7500 Boxes and Balls (数学)
题意:给定 n 个球,每次从每篮子里拿出来一个放在一个新篮子里,并移除相同的,按球的个数进行排序,问你用最多几个球能完成循环. 析:数学问题,很容易发现前n项和就是最多的球数,所以我们只要找最大的n项 ...
- UVALive 7147 World Cup(数学+贪心)(2014 Asia Shanghai Regional Contest)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...
- UVaLive 6628 Grachten (水题,数学)
题意:给定一个平面图形并且且给了几条连,求一条. 析:简单么,三角形相似,很简单就AC. 代码如下: #pragma comment(linker, "/STACK:1024000000,1 ...
- UVaLive 6862 Triples (数学+分类讨论)
题意:给定一个n和m,问你x^j + y^j = z^j 的数量有多少个,其中0 <= x <= y <= z <= m, j = 2, 3, 4, ... n. 析:是一个数 ...
- UVaLive 7362 Farey (数学,欧拉函数)
题意:给定一个数 n,问你0<= a <=n, 0 <= b <= n,有多少个不同的最简分数. 析:这是一个欧拉函数题,由于当时背不过模板,又不让看书,我就暴力了一下,竟然A ...
- UVaLive 7359 Sum Kind Of Problem (数学,水题)
题意:给定一个n,求前 n 个正整数,正奇数,正偶数之和. 析:没什么好说的,用前 n 项和公式即可. 代码如下: #pragma comment(linker, "/STACK:10240 ...
- Gym 101194E / UVALive 7901 - Ice Cream Tower - [数学+long double][2016 EC-Final Problem E]
题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...
随机推荐
- STL学习笔记(非变动性算法)
辅助函数 本节跟以后几节将对所有STL算法逐一详细讨论.为了简化这些例子,我们使用了一些辅助函数,分别用于对容器进行输出跟插入操作. #ifndef ALGOSTUFF_HPP #define ALG ...
- windows快捷键之打开网络连接
在Win 7"開始"->"执行"对话框输入"cmd"例如以下图红框所看到的,再点击"确定"button. 步骤 ...
- java如何实现多个线程并发运行
随着计算机技术的发展,编程模型也越来越复杂多样化.但多线程编程模型是目前计算机系统架构的最终模型.随着CPU主频的不断攀升,X86架构的硬件已经成为瓶,在这种架构的CPU主频最高为4G.事实上目前3. ...
- jdk1.6 升级到 jdk1.7
将 jdk1.6 升级到 jdk1.7 下载jdk-7u11-linux-x64.tar.gz tar zxvf jdk-7u11-linux-x64.tar.gz mkdir /usr/l ...
- 让UITableView进入编辑模式
1.UITableView对象有一个editing属性,设为YES时,该对象会进入编辑模式(editing mode).表格视图进入编辑模式后,用户可以管理表格中得行,如改变行的排列顺序.增加行或删除 ...
- Spring 应用外部属性文件 配置 context 错误
在Spring配置文件中出现通配符的匹配很全面, 但无法找到元素 'context:property-placeholder' 的声明这个错误,其实主要是我们在引入命名空间时没有正确引入它的DTD解析 ...
- SpringCloud系列一:微服务理解
1. 单体架构 一个归档包(例如war格式)包含所有功能的应用程序,通常称为单体应用. > 复杂性高:模块多,模块的边界模糊,依赖关系不清楚,代码质量参差不齐. > 技术债务:随着时间推移 ...
- Wormholes - poj 3259 (Bellman-Ford算法)
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 34934 Accepted: 12752 Description W ...
- 【转】【Python + selenium】linux和mac环境,驱动器chromedriver和测试报告HTMLTestRunner放置的位置
感谢: 作者:gz_tester,文章:<linux和mac环境,chromedriver和HTMLTestRunner放置的位置> 使用场景 配置python selenium 环境 使 ...
- cvm母机宕机重启后数据库修复
下午正在开周会,然后收到短信,说是X.X.X.X的机器ping不通了,一轮测试过后,发现是某台数据库服务器挂了,先不急着重启,问下tencent客服... 乖乖的好家伙,母机的主板坏了....一个小时 ...