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. 【转载】如何使用docker部署c/c++程序

    原文地址:https://blog.csdn.net/len_yue_mo_fu/article/details/80189035 Docker介绍 Docker是一个开源的容器引擎,它有助于更快地交 ...

  2. RHEL 6和RHEL 7(CentOS 6和CentOS 7)恢复ROOT密码

    RedHat 6恢复Root密码: 1.启动RedHat 6的时候在这个界面按任意键 2.出现如下界面,按 e 3.出现如下界面,选择第二个--kernel,然后再按 e 4.出现如下界面,输入 空格 ...

  3. C#基于用户和角色的验证,服务端web 客户端wpf

    应用程序服务 <?xml version="1.0"?> <!--  For more information on how to configure your ...

  4. Windows 10开发基础——VS2015 Update1新建UWP项目,XAML设计器无法加载的解决

    这次,我们来解决一个问题...在使用Visual Studio 2015 Update 1的时候,新建一个UWP的项目,XAML设计器就会崩,具体异常信息如下图: 解决方法如下:下面圈出的那个路径就按 ...

  5. 苹果ios用js的Date()出现NaN问题解决办法

    原文:苹果ios用js的Date()出现NaN问题解决办法 ios使用如下方法获得NaN,安卓手机则是正常计算,解决方法是换个这个时间的格式 new Date("2017-04-28 23: ...

  6. WPF ListView 数据懒加载

    实现方式:当滑动条触底时,加载数据 xaml代码: <ListView ScrollViewer.ScrollChanged="ListView_ScrollChanged" ...

  7. mysql 配置 explicit_defaults_for_timestamp

    在之前的配置中,除了目录之外,唯独添加了这一项配置,为什么? 因为mysql中timestamp类型和其他的类型不一样: 在之前先了解一下current timestamp和on update cur ...

  8. ThreadPoolExecutor的一点理解 专题

    corePoolSize(maxActiveThreadSize):线程池大小,决定着新提交的任务是新开线程云执行还是放到任务队列中,也是线程池的最最核心的参数.一般线程池开始时是没有线程的,只有当任 ...

  9. 麻省理工的 Picture 语言:代码瘦身的秘诀

    直击现场 如今,机器学习算法已经进入了主流的计算机,而麻省理工学院正在研究一款让每日的编程变得更加简单的技术. MIT 研究者将在六月发布一款新的叫做 Picture 的编程语言,当计算机在视频或者图 ...

  10. 更改当前电源策略(使用SetActivePwrScheme API函数),自定义电源按钮动作(设置GLOBAL_POWER_POLICY)

    #include <windows.h> #include <Powrprof.h> #pragma comment(lib, "Powrprof.lib" ...