SPOJ 3899. Finding Fractions 连分数】的更多相关文章

连分数乱搞,我反正是一眼没看出结果 某巨巨把这题讲解的比较详细 : http://blog.csdn.net/gogdizzy/article/details/8727386 令k = [a/b] 然后对于a/b < p/q < c/d 就能得到 (a-bk)/b < (p-qk)/q < (c-dk)/d  即 a'/b < p'/q < c'/d ----------------------每项都是<1的 因为显然 a/b < 1 这时如果c/d>…
SPOJ上的每个题目都做得我泪牛满面. 这个题目也是的.题目意思是给你两个分数a/b和c/d,要你求出一个分数p/q,使得a/b<p/q<c/d,且p最小. 看完题目后半天都没有任何思路哦.于是无奈只好去网上找题解咯. 终于找到一个神牛的题解,并且自己终于把那个东西给看懂了. 下面写下我自己的理解吧. 首先对于我们不要急于求分子,我们只要求出分母q,分子就可以直接用q*a/b+1表示了(想想为什么呢?因为要最小的). 那么要求这个分母,首先把第一个分数变成0-1之间,即k=a/b,a-=b*k…
任意门:http://codeforces.com/gym/100641/attachments Con + tin/(ued + Frac/tions) Time Limit: 3000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 217     Accepted Submission(s): 27 Description The (simple) contin…
Many students cruise along just fine in math until fourth grade or so. Then, they hit a wall -- fractions. cruise:巡航,巡游,漫游 fraction:分数,片段The wall is about to get taller. With mastery of the topic seen as a crucial stepping stone to progressing in mat…
2588: Spoj 10628. Count on a tree Time Limit: 12 Sec  Memory Limit: 128 MBSubmit: 5217  Solved: 1233[Submit][Status][Discuss] Description 给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k),你需要回答u xor lastans和v这两个节点间第K小的点权.其中lastans是上一个询问的答案,初始为0,即第一个询问的u是明文. Input 第一…
传送门 Description Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer n he can represent fraction   as a sum of three distinct positive fractions in form . Help Vladik with that, i.e for a g…
题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ..., an and a number of d-queries. A d-query is a pair (i, j) (1 ≤ i ≤ j ≤ n). For each d-query (i, j), you have to return the number of distinct elem…
题目链接: Finding Hotels Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 102400/102400 K (Java/Others) Problem Description There are N hotels all over the world. Each hotel has a location and a price. M guests want to find a hotel with an accept…
SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50000) integers between -10000 and 10000. On this sequence you have to apply M (M <= 50000) operations: modify the i-th element in the sequence or for giv…
这题是学主席树的时候就想写的,,, 但是当时没写(懒) 现在来填坑 = =日常调半天lca(考虑以后背板) 主席树还是蛮好写的,但是代码出现重复,不太好,导致调试的时候心里没底(虽然事实证明主席树部分没出问题) #include <cstdio> #include <algorithm> using namespace std; ]; ]; ,N=,lastans=; ],nex[],list[]; ],h[],fir[],root[],f[],pos[]; ],near[],rm…
题目大意:给你一个长度为n的字符串,求出所有不同长度的字符串出现的最大次数. n<=250000 如:abaaa 输出: 4 2 1 1 1 spoj上的时限卡的太严,必须使用O(N)的算法那才能过掉,所以采用后缀自动机解决. 一个字符串出现的次数,即为后缀自动机中该字符串对应的节点的right集合的大小,right集合的大小等于子树中叶子节点的数目. 令dp[i]表示长度为i的字符串出现的最大次数.dp[i]可以通过在后缀链接树中从叶子节点到根节点依次求出. 最后,按长度从大到小,用dp[i]…
D. On Sum of Fractions Let's assume that v(n) is the largest prime number, that does not exceed n; u(n) is the smallest prime number strictly greater than n. Find . Input The first line contains integer t (1 ≤ t ≤ 500) — the number of testscases. Eac…
Fun With Fractions Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users: 152, Accepted users: 32 Problem 12878 : No special judgement Problem description A rational number can be represented as the ratio of two integ…
原文 Finding the Best Programmer's Font…
http://www.spoj.com/problems/SUBLEX/ 好难啊. 建出后缀自动机,然后在后缀自动机的每个状态上记录通过这个状态能走到的不同子串的数量.该状态能走到的所有状态的f值的和+1就是当前状态的f值. 最后对于询问的k,从root开始走顺便加加减减就可以了. #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int in() { int k =…
http://www.spoj.com/problems/LCS2/ 这道题想了好久. 做法是对第一个串建后缀自动机,然后用后面的串去匹配它,并在走过的状态上记录走到这个状态时的最长距离.每匹配完一个串要对每个状态往它的parent更新,因为状态记录的最长距离一定大于parent的val值,所以parent的最长距离直接赋为val即可. #include<cstdio> #include<cstring> #include<algorithm> using namesp…
http://www.spoj.com/problems/NSUBSTR/ clj课件里的例题 用结构体+指针写完模板后发现要访问所有的节点,改成数组会更方便些..于是改成了数组... 这道题重点是求一个状态的\(|Right|\)值,只要用parent树中当前节点的所有孩子来更新它即可. 为了保证一个节点的parent一定被所有孩子全部更新,需要保证在序列中一个节点的parent一定在它的左边(从右往左扫来更新). 这就需要对\(val\)值排序,因为spoj时限卡得紧,所以用基数排序. #i…
Time Limit: 1000MS   Memory Limit: 1572864KB   64bit IO Format: %lld & %llu Description Being a completist and a simplist, kid Yang Zhe cannot solve but get Wrong Answer from most of the OI problems. And he refuse to write two program of same kind at…
传送门: 这是一道treap的模板题,不要问我为什么一直在写模板题 依旧只放代码 Treap 版 //SPOJ 3273 //by Cydiater //2016.8.31 #include <iostream> #include <cstring> #include <ctime> #include <cmath> #include <cstdlib> #include <string> #include <algorithm…
Octal Fractions Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 149  Solved: 98 Description Fractions in octal (base 8) notation can be expressed exactly in decimal notation. For example, 0.75 in octal is 0.963125 (7/8 + 5/64) in decimal. All octal num…
题目链接:http://www.spoj.com/problems/PHRASES/en/ 题意:给定n个字符串,求一个最长的子串至少在每个串中的不重叠出现次数都不小于2.输出满足条件的最长子串长度 思路:根据<<后缀数组——处理字符串的有力工具>>的思路,先将 n个字符串连起来, 中间用不相同的且没有出现在字符串中的字符隔开, 求后缀数组. 然后二分答案, 再将后缀分组.判断的时候, 要看是否有一组后缀在每个原来的字符串中至少出现两次, 并且在每个原来的字符串中, 后缀的起始位置…
题目链接:http://www.spoj.com/problems/REPEATS/en/ 题意:首先定义了一个字符串的重复度.即一个字符串由一个子串重复k次构成.那么最大的k即是该字符串的重复度.现在给定一个长度为n的字符串,求最大重复次数. 思路:根据<<后缀数组——处理字符串的有力工具>>的思路,先穷举长度L,然后求长度为L 的子串最多能连续出现几次.首先连续出现1 次是肯定可以的,所以这里只考虑至少2 次的情况.假设在原字符串中连续出现2 次,记这个子字符串为S,那么S 肯…
题目链接:http://www.spoj.com/problems/SUBST1/en/ 题意:给定一个字符串,求不相同的子串个数. 思路:直接根据09年oi论文<<后缀数组——出来字符串的有力工具>>的解法. 此题和SPOJ DISUBSTR一样,至少数据范围变大了. #define _CRT_SECURE_NO_DEPRECATE #include<iostream> #include<cstdio> #include<cstring> #i…
题目链接:http://www.spoj.com/problems/DISUBSTR/en/ 题意:给定一个字符串,求不相同的子串个数. 思路:直接根据09年oi论文<<后缀数组——出来字符串的有力工具>>的解法. 还有另一种思想:总数为n*(n-1)/2,height[i]是两个后缀的最长公共前缀,所以用总数-height[i]的和就是答案 #define _CRT_SECURE_NO_DEPRECATE #include<iostream> #include<…
题目 Source http://www.spoj.com/problems/TSUM/ Description You're given a sequence s of N distinct integers.Consider all the possible sums of three integers from the sequence at three different indicies.For each obtainable sum output the number of diff…
Octal Fractions Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6669   Accepted: 3641 Description Fractions in octal (base 8) notation can be expressed exactly in decimal notation. For example, 0.75 in octal is 0.953125 (7/8 + 5/64) in d…
COT - Count on a tree #tree You are given a tree with N nodes.The tree nodes are numbered from 1 to N.Each node has an integer weight. We will ask you to perform the following operation: u v k : ask for the kth minimum weight on the path from node u …
Query on a tree Time Limit: 5000ms Memory Limit: 262144KB   This problem will be judged on SPOJ. Original ID: QTREE64-bit integer IO format: %lld      Java class name: Main Prev Submit Status Statistics Discuss Next Font Size: + - Type:   None Graph…
C. Vladik and fractions 题目链接 http://codeforces.com/contest/743/problem/C 题面 Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer n he can represent fraction as a sum of three distinct posit…
1215 - Finding LCM Time Limit: 2 second(s) Memory Limit: 32 MB LCM is an abbreviation used for Least Common Multiple in Mathematics. We say LCM (a, b, c) = L if and only if L is the least integer which is divisible by a, b and c. You will be given a,…