http://codeforces.com/problemset/problem/305/B

题意:就是判断 p / q 等不等于那条式子算出来的值。

思路:一开始看到 1e18 的数据想了好久还是不会,暴力了一发显然错了。后来倒着想,就是 p / q(整除)的值一定要大于等于 a[i],否则就不行,每次判断完之后更新 p / q 即可,注意要判分母是否为0,因为这个RE了一次。思维僵化很严重,如果活跃一点估计很快就想出来了。吸取教训。

 #include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <iostream>
#include <stack>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long LL;
#define N 100010
#define INF 0x3f3f3f3f
#define MOD 1000000007
LL a[];
LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; } int main()
{
LL p, q; int flag = ;
cin >> p >> q;
int n; cin >> n;
for(int i = ; i <= n; i++) cin >> a[i];
LL yue = gcd(p, q); p /= yue; q /= yue;
for(int i = ; i <= n; i++) {
if(q == ) { flag = ; break; }
LL num = p / q;
if(num < a[i]) { flag = ; break; }
p -= a[i] * q;
swap(p, q);
yue = gcd(p, q); p /= yue; q /= yue;
}
swap(p, q);
if(p == && flag) puts("YES");
else puts("NO");
return ;
}

Codeforces 305B:Continued Fractions(思维+gcd)的更多相关文章

  1. CF 305B——Continued Fractions——————【数学技巧】

    B. Continued Fractions time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  2. Codeforces 979 D. Kuro and GCD and XOR and SUM(异或和,01字典树)

    Codeforces 979 D. Kuro and GCD and XOR and SUM 题目大意:有两种操作:①给一个数v,加入数组a中②给出三个数x,k,s:从当前数组a中找出一个数u满足 u ...

  3. Continued Fractions CodeForces - 305B (java+高精 / 数学)

    A continued fraction of height n is a fraction of form . You are given two rational numbers, one is ...

  4. Maximal GCD CodeForces - 803C (数论+思维优化)

    C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  5. codeforces 798 C. Mike and gcd problem(贪心+思维+数论)

    题目链接:http://codeforces.com/contest/798/problem/C 题意:给出一串数字,问如果这串数字的gcd大于1,如果不是那么有这样的操作,删除ai, ai + 1 ...

  6. Mike and gcd problem CodeForces - 798C (贪心思维+数论)

    题目链接 比较棒的一道题, 题意: 给你一个N个数的数组,让你用尽量少的操作使整个数组的gcd大于1,即gcd(a1 ,a2,,,,an) > 1 如果可以输出YES和最小的次数,否则输出NO ...

  7. 【CodeForces 803 C】Maximal GCD(GCD+思维)

    You are given positive integer number n. You should create such strictly increasingsequence of k pos ...

  8. codeforces 1030D Vasya and Triangle【思维+gcd】

    题目:戳这里 题意:选出三个点构成三角形,要求面积为n*m/k. 解题思路:因为三个点的坐标都是正整数,根据三角形面积公式(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))/2=n* ...

  9. 2014-2015 ACM-ICPC East Central North America Regional Contest (ECNA 2014) A、Continued Fractions 【模拟连分数】

    任意门:http://codeforces.com/gym/100641/attachments Con + tin/(ued + Frac/tions) Time Limit: 3000/1000 ...

随机推荐

  1. [Android] 环境优化配置Android Studio发展NDK

    ======================================================== 作者:qiujuer 博客:blog.csdn.net/qiujuer 站点:www. ...

  2. iOS_9_scrollView分页

    最后效果图: BeyondViewController.h // // BeyondViewController.h // 8_scrollVIew分页浏览 // // Created by beyo ...

  3. WPF控件获得焦点时去除虚线框

    原文:WPF控件获得焦点时去除虚线框 <Setter Property="FocusVisualStyle" Value="{x:Null}" />

  4. WPF Layout 系统概述——Arrange

    原文:WPF Layout 系统概述--Arrange Arrange过程概述 普通基类属性对Arrange过程的影响 我们知道Measure过程是在确定DesiredSize的大小,以便Arrang ...

  5. laravel在wamp中输入地址后总是无法访问

    在wamp中的apache中conf的httpd.conf #LoadModule rewrite_module modules/mod_rewrite.so 改为 LoadModule rewrit ...

  6. WPF生成二维码

    WPF可以通过ZXing.Net库来实现二维码的功能. 可以通过NuGet安装: Install-Package ZXing.Net 二维码的实现代码: #region 二维码的方法 /// < ...

  7. ORACLE RAC+OGG配置

    实验环境主机名   IP地址rac01     192.168.56.10rac02     192.168.56.20rac-scan 192.168.56.30 目标库:ora-ogg  192. ...

  8. uwp开发:数据绑定——值转换器 的简单使用

    原文:uwp开发:数据绑定--值转换器 的简单使用 今天,我在做最近正在开发的“简影”uwp应用时遇到一个问题,其中有个栏目,叫做“画报”,是分组显示一组一组的 图片,每组图片在界面上只显示9个,点击 ...

  9. Bamboo 0.2.11 发布,HAProxy 自动配置

    Bamboo 0.2.11 发布,此版本更新内容如下: 新特性 提供更多的模板字符串函数:strings.Split,  strings.Join,strings.Replace, strings.T ...

  10. Delphi驱动开发研究第一篇--实现原理

    Delphi能不能开发Windows的驱动程序(这里的驱动程序当然不是指VxD了^_^)一直是广大Delphi fans关注的问题.姑且先不说能或者不能,我们先来看看用Delphi开发驱动程序需要解决 ...