随笔 - 6  文章 - 3  trackbacks - 0
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(1)

随笔分类

随笔档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜

 1#include <stdio.h>
 2#define MAX 200
 3
 4typedef struct
 5{
 6    int num;
 7    int x[MAX];
 8    int y[MAX];
 9}
 fac;
10
11void factorization(fac *a, int x) // 质因数分解 
12{
13    int i, count;
14    
15    if (x <= 0)
16    {
17        a->num = 0;
18        return;
19    }

20    
21    if (x == 1)
22    {
23        a->num = 1;
24        a->x[0= a->y[0= 1;
25        return;
26    }

27    
28    a->num = 0;
29    
30    for (i = 2; i * i <= x; i++)
31    {
32        count = 0;
33        
34        while (x % i == 0)
35        {
36            x /= i;
37            count++;
38        }

39        
40        if (count != 0)
41        {
42            a->x[a->num] = i;
43            a->y[a->num++= count;
44        }

45    }

46    
47    if (x != 1
48    {
49        a->x[a->num] = x;
50        a->y[a->num++= 1
51    }

52}

53
54int main()
55{
56    int x, i;
57    fac f;
58    
59    while (scanf ("%d"&x) != EOF)
60    {
61        factorization(&f, x);
62        
63        if (f.num <= 0)
64        {
65            printf("Factorization Error!\n");
66            continue;
67        }

68        
69        printf("%d = %d ^ %d", x, f.x[0], f.y[0]);
70        for (i = 1; i < f.num; i++)
71            printf(" * %d ^ %d", f.x[i], f.y[i]);
72        printf("\n");
73    }

74    
75    return 0;
76}
posted @ 2011-01-06 00:31 姚冰 阅读(1866) | 评论 (0)编辑 收藏
     摘要:     1#include <stdio.h>  2#include <stdlib.h>  3#define MAX 200  4  5typedef struct  6{ &nbs...  阅读全文
posted @ 2011-01-06 00:15 姚冰 阅读(3867) | 评论 (1)编辑 收藏
     摘要: /**//***************************表达式模板****************************/#include<stack>#include<string>#include<iostream>using namespace std;int signMap[7][7]={  &...  阅读全文
posted @ 2009-04-17 21:00 姚冰 阅读(245) | 评论 (0)编辑 收藏
     摘要:   1#include<stdio.h>  2#include<math.h>  3  4const double eps=1e-6;  5  6//点(x,y)   7typedef struc...  阅读全文
posted @ 2009-04-14 10:58 姚冰 阅读(428) | 评论 (0)编辑 收藏
     摘要: 题目 有N种物品和一个容量为V的背包,每种物品都有无限件可用。第i种物品的费用是c[i],价值是w[i]。求解将哪些物品装入背包可使这些物品的费用总和不超过背包容量,且价值总和最大。 基本思路 这个问题非常类似于01背包问题,所不同的是每种物品有无限件。也就是从每种物品的角度考虑,与它相关的策略已并非取或不取两种,而是有取0件、取1件、取2件……等很多种。如果仍然按照...  阅读全文
posted @ 2009-04-07 20:16 姚冰 阅读(1342) | 评论 (0)编辑 收藏
     摘要: 题目 有N件物品和一个容量为V的背包。第i件物品的费用是c[i],价值是w[i]。求解将哪些物品装入背包可使价值总和最大。 基本思路 这是最基础的背包问题,特点是:每种物品仅有一件,可以选择放或不放。 用子问题定义状态:即f[i][v]表示前i件物品恰放入一个容量为v的背包可以获得的最大价值。则其状态转移方程便是: f[i][v]=max{f[i-1][v],f[i-1][v-c[i...  阅读全文
posted @ 2009-04-06 11:43 姚冰 阅读(900) | 评论 (2)编辑 收藏
仅列出标题