暴力枚举 UVA 10976 Fractions Again?!

题目传送门

 1 /*
 2     x>=y, 1/x <= 1/y, 因此1/k - 1/y <= 1/y, 即y <= 2*k
 3 */
 4 #include <cstdio>
 5 #include <iostream>
 6 #include <algorithm>
 7 #include <cmath>
 8 #include <cstring>
 9 #include <string>
10 #include <map>
11 #include <set>
12 #include <queue>
13 using namespace std;
14
15 const int MAXN  = 1e4 + 10;
16 const int INF = 0x3f3f3f3f;
17 struct NODE
18 {
19     int x, y;
20 }node[MAXN];
21
22 int main(void)        //UVA 10976 Fractions Again?!
23 {
24     //freopen ("UVA_10976.in", "r", stdin);
25
26     int k;
27     while (scanf ("%d", &k) == 1)
28     {
29         int cnt = 0;
30         for (int i=k+1; i<=2*k; ++i)
31         {
32             if ((i*k) % (i-k) == 0)
33             {
34                 node[++cnt].x = (i*k) / (i-k);
35                 node[cnt].y = i;
36             }
37         }
38
39         printf ("%d\n", cnt);
40         for (int i=1; i<=cnt; ++i)
41         {
42             printf ("1/%d = 1/%d + 1/%d\n", k, node[i].x, node[i].y);
43         }
44     }
45
46     return 0;
47 }
48
49 /*
50 2
51 1/2 = 1/6 + 1/3
52 1/2 = 1/4 + 1/4
53 8
54 1/12 = 1/156 + 1/13
55 1/12 = 1/84 + 1/14
56 1/12 = 1/60 + 1/15
57 1/12 = 1/48 + 1/16
58 1/12 = 1/36 + 1/18
59 1/12 = 1/30 + 1/20
60 1/12 = 1/28 + 1/21
61 1/12 = 1/24 + 1/24
62 */
时间: 2024-08-10 03:59:42

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

uva 10976 Fractions Again(简单枚举)

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

UVA 10976 Fractions Again?(枚举+数学)

题目大意: 就是说输入一个k,然后求出满足1/k = 1/x+1/y的所有形式,使得x>=y. 解题思路: 拿到这个题后,看到题目仅仅给了x>=y.这个条件,感觉无从下手,但是仔细想想就不难发现,只要我们 首先确定了枚举的范围,那么我们就能够在这个区间内,找到符合我们要求的解了. 推导: 因为x>=y,所以1/x<=1/y,由1/k-1/x=1/y -> 1/k-1/y <= 1/y -> y<=2k, 然后,由等式1/k = 1/x+1/y -> x

UVA 10976 Fractions Again?! 简单枚举题

#include<stdio.h> struct pairs{ int x,y; }; struct pairs pairs[10000]; int judge(int k,int i){ if((k*i)%(i-k)==0) return 1; else return 0; } int main(){ int k,count; while(scanf("%d",&k)!=EOF){ count=0; for(int i=k+1;i<=2*k;i++){ if

暴力枚举 UVA 725 Division

题目传送门 1 /* 2 暴力:对于每一个数都判断,是否数字全都使用过一遍 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 #include <cmath> 8 #include <cstring> 9 #include <string> 10 #include <map> 11 #include <set> 12

uva 10976 fractions again(水题)——yhx

1 #include<cstdio> 2 int a[30010],b[30010]; 3 int main() 4 { 5 int i,j,k,l,m,n,x,y,z; 6 while (scanf("%d",&k)==1) 7 { 8 n=0; 9 for (i=k+1;i<=2*k;i++) 10 if ((k*i)%(i-k)==0) 11 { 12 a[++n]=k*i/(i-k); 13 b[n]=i; 14 } 15 printf("%

Uva 10976 Fractions Again?!

直接暴力 没技巧 y应该从k+1开始循环,因为不然y-k<0的时候 你相当于(x*y) % (负数) 了. 1 #include <iostream> 2 using namespace std; 3 int X[10005]; 4 int Y[10005]; 5 int main() 6 { 7 int k,cnt; 8 while(cin>>k) 9 { 10 cnt=0; 11 for(int y=k+1;y<=2*k;y++) 12 { 13 if( ( (k*

UVA 725 UVA 10976 简单枚举

UVA 725 题意:0~9十个数组成两个5位数(或0开头的四位数),要求两数之商等于输入的数据n.abcde/fghij=n. 思路:暴力枚举,枚举fghij的情况算出abcde判断是否符合题目条件.(注意前导零的判断) 枚举的方法为 for(int i=1234;i<=100000/n;i++){} #include<cstdio> #include<cstring> int num[10]; bool check(int a,int b) { memset(num,0,

uva 565 - Pizza Anyone?(暴力枚举 + 二进制)

题目:uva 565 - Pizza Anyone?(暴力枚举 + 二进制) 题目大意:题目是说有一个人要帮他的朋友们定批萨,然后每个朋友都有自己的口味要求,问能不能定一个批萨然后满足每个朋友的至少一个要求. 能就输出所定批萨里面加的东西,,输出要求按字典序: 不能就输出:No pizza can satisfy these requests. 解题思路:这题里面有16种材料,每种材料只有取与不取的可能,这样就有 2^16 种( 0 - 2^16 - 1),枚举出每种情况然后在分别看是否能满足每

UVA 725 Division ( 找出 abcde / fghij = N的形式—— 暴力枚举 )

Division Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description Write a program that finds and displays all pairs of 5-digit numbers that between them use the digits 0 through 9 once each, such that the first number divide