暴力枚举 UVA 10976 Fractions Again?!】的更多相关文章

题目传送门 /* x>=y, 1/x <= 1/y, 因此1/k - 1/y <= 1/y, 即y <= 2*k */ #include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstring> #include <string> #include <map> #include <…
10976 Fractions Again It is easy to see that for every fraction in the form 1 k (k > 0), we can always find two positive integers x and y, x ≥ y, such that: 1 k = 1 x + 1 y Now our question is: can you write a program that counts how many such pairs…
[题意]:给你一个数k,求所有使得1/k = 1/x + 1/y成立的x≥y的整数对. [分析]:枚举所有在区间[k+1, 2k]上的 y 即可,当 1/k - 1/y 的结果分子为1即为一组解. [代码]: #include<bits/stdc++.h> using namespace std; int x[10005]; int y[10005]; #define LL long long int main() { int k,c; while(~scanf("%d",…
题目传送门 /* 暴力:对于每一个数都判断,是否数字全都使用过一遍 */ #include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstring> #include <string> #include <map> #include <set> #include <queue> usin…
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB3gAAAM+CAIAAAB31EfqAAAgAElEQVR4nOzdO7KtPJum69GEpAcVQQfSoA80ATddvDLSogMV9ICINLaJkUZZ2NvAKGtH4FcQZaZR9IFtvP96fy0OQkgCxuG+rO9bc86BACGJBw3xmgEAAAAAAAAAcPD/7Xg9XTAAAAAAAAAAwGcgaAYAAAAAAAAABCFoBgAAAAAAAAAEIWgGAAAAA…
直接暴力 没技巧 y应该从k+1开始循环,因为不然y-k<0的时候 你相当于(x*y) % (负数) 了. #include <iostream> using namespace std; ]; ]; int main() { int k,cnt; while(cin>>k) { cnt=; ;y<=*k;y++) { ) ) { X[cnt]=k*y/(y-k); Y[cnt]=y; cnt++; } } cout<<cnt<<endl; ;i…
UVA.10986 Fractions Again (经典暴力) 题意分析 同样只枚举1个,根据条件算出另外一个. 代码总览 #include <iostream> #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <sstream> #include <set> #include <map&g…
UVA 725 题意:0~9十个数组成两个5位数(或0开头的四位数),要求两数之商等于输入的数据n.abcde/fghij=n. 思路:暴力枚举,枚举fghij的情况算出abcde判断是否符合题目条件.(注意前导零的判断) 枚举的方法为 for(int i=1234;i<=100000/n;i++){}  #include<cstdio> #include<cstring> ]; bool check(int a,int b) { memset(num,,sizeof num…
UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 XOR的性质 GCD 由于题目只给出一个n,我们要求对数,能做的也始终暴力枚举a,b,这样就有n^2的复杂度,由于n很大,根本过不了. 于是我们就想用到其中一些性质,如XOR 与GCD,不妨假设 a xor b = c,并且根据题意还知道, gcd(a,b) = c,也就说明c一定是a的因子,所以在枚举的…
题目链接:https://vjudge.net/problem/UVA-10976 It is easy to see that for every fraction in the form 1k(k > 0), we can always find two positive integers x and y, x ≥ y, such that: 1/k=1/x+1/y Now our question is: can you write a program that counts how ma…