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 ...
随机推荐
- TCP/IP详解 卷一(第十八章 TCP连接的建立和终止)
建立连接 建立一个TCP连接时会发生下述情况 1.客户TCP发送一个SYN(同步)分节,它告诉服务器将在(待建立)连接中发送的数据的初始序列号. 2.服务器确认(ACK)客户的SYN,同时自己也得发送 ...
- Oracle 导入导出数据库
imp userid=yrsuser/yrsuser2587 fromuser=yrsuser touser=yrsuser file=E:\yrs.dmp exp userid=yrsuser/yr ...
- Hbase笔记3 shell命令
http://www.jb51.net/article/31172.htm 这个文章写得挺好 1.HBase的shell就和我们用Mysql的终端是一个意思,比如我们安装好Mysql,配置好了环境变量 ...
- 使用transform和transition制作CSS3动画
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...
- 初窥Servlet
1. Servlet简介 Servlet是sun公司提供的一门用于开发动态web资源的技术.sun公司在其API中提供了一个servlet接口,用户若想要发一个动态web资源,只需要完成以下两步即可: ...
- python 三个双引号
有的内容被上面三个双引号和下面三个双引号包围了,这些内容不执行.即,下面aaa的部分不执行. """ aaaa; """
- msyql5.5修改配置文件开启慢查询日志
修改/etc/my.cnf文件 在[mysqld]下面修改或添加配置(在别处不起作用) slow_query_log = on slow_query_log_file = /usr/local/mys ...
- nginx 使用ngx_cache_purge清除缓存
location ~ ^/myclear(/.*) { allow 10.0.0.0/8; allow 10.28.100.0/24; allow 127.0.0.1; deny all; pro ...
- Python之内置类型
python有6大内置类型 数字.序列.映射.类.实例.异常. 下面就慢慢来说明: 1.数字 有3个明确的数字类型,整型,浮点型及复数.另外,布尔是整型的一个子类型. (另外标准库还包含额外的数字类型 ...
- 标准库 - 输入输出处理(input and output facilities) lua
标准库 - 输入输出处理(input and output facilities)责任编辑:cynthia作者:来自ITPUB论坛 2008-02-18 文本Tag: Lua [IT168 技术文档] ...