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先进】如何使用数据文件来保存程序

    在程序,有许多方法来存储和检索数据,本文,它描述了如何使用文件系统来保存数据编程和读取操作 我直接写了一个帮助类,进行文件的写入和读取操作 /** * 用于在文件里保存程序数据 * * @author ...

  2. 漫谈 KVC 与 KVO

    KVC 与 KVO 无疑是 Cocoa 提供给我们的一个非常强大的特性,使用熟练可以让我们的代码变得非常简洁并且易读.但 KVC 与 KVO 提供的 API 又是比较复杂的,绝对超出我们不经深究之前所 ...

  3. x86汇编指令脚本虚拟机

    简介 这是一个可以直接解释执行从ida pro里面提取出来的x86汇编代码的虚拟机. 非常精简,整体架构上不能跟那些成熟的虚拟机相比,主要目标是够用.能用.轻量就行,如果觉得代码架构设计的不是很好的话 ...

  4. C# 自定义泛型类,并添加约束

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  5. NULL指针区域(NULL定义为0-65535之间的任何数都可以)

    NULL指针区域0x00000000-0x0000FFFF:65535字节 这个区域的作用是用来帮助程序员发现内存分配失败后未检查就使用的错误.比如使用malloc分配内存失败,返回NULL,而又未做 ...

  6. WPF应用App.Config文件的保存路径

    App.Config文件有更改后,自动会保存到以下路径: C:\Users\你的系统用户名\AppData\Local\你的应用名\

  7. WPF使用WindowChrome实现自定义标题框功能

    代码: <Window x:Class="WpfDemo.MainWindow" xmlns="http://schemas.microsoft.com/winfx ...

  8. PopupWindow设置动画效果

    创建popupwindow的方法 Button menu; private void showPopupWindow() { //设置contentView float density = Densi ...

  9. 改善C#程序的建议1:非用ICloneable不可的理由

    原文:改善C#程序的建议1:非用ICloneable不可的理由 好吧,我承认,这是一个反标题,实际的情况是:我找不到一个非用ICloneable不可的理由.事实上,接口ICloneable还会带来误解 ...

  10. Capsule Network

    Capsule Network最大的特色在于vector in vector out & 动态路由算法. vector in vector out 所谓vector in vector out ...