Welcome to Leon's Blog  
日历
<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678
统计
  • 随笔 - 30
  • 文章 - 0
  • 评论 - 51
  • 引用 - 0

导航

常用链接

留言簿(4)

随笔分类

随笔档案

ACM

搜索

  •  

最新评论

阅读排行榜

评论排行榜

 

     摘要:     这几天一直在修改这道题,一直都改不对,老是错误,提交不成功,我把自己的代码贴出来让大家帮忙看看,在这里谢过了! #include <stdio.h>#include <string.h>#include <stdlib.h>int result[4];int reNumbe...  阅读全文
posted @ 2008-06-29 16:09 Leon916 阅读(1088) | 评论 (6)编辑 收藏
 
      昨天开始做1423题,早上刚刚ac。其实这道题有好几种方法,后来看了大家讨论才去做的,不算是自己独立思考。
     第一种方法是根据stirling逼近来做,《计算机程序设计艺术》《算法导论》中给出了公式。
     第二种是是取对数,写了一个但是总是超时,后来看了这篇blog,后悔自己当初为什么不想办法改进自己的方法。
     算是留个纪念,下次注意!
posted @ 2008-06-04 08:56 Leon916 阅读(127) | 评论 (0)编辑 收藏
 
     今天做完1006题,第一次用枚举法,但是时间复杂度大,后来看到帖子说是用中国余数法。自己试着也写了一个,但是用时也过大,现在把代码贴出来,请大家帮忙改一改啊!谢谢了!
 1#include <stdio.h>
 2
 3int main(int argc, char* argv[])
 4{
 5    int p,e,i,d, index;
 6    int day;
 7    int x = 28*33*6;
 8    int y = 23*33*19;
 9    int z = 23*28*2;
10    index = 0;
11    
12
13    do
14    {
15        scanf("%d %d %d %d"&p,&e, &i, &d);
16        if(p == -1 && e == -1 && i == -1 && d == -1)
17            break;
18        p = p%23;
19        e = e%28;
20        i = i%33;
21        day = (p*+ e*+ i*z) % 21252;
22        if(day == d)
23            day += 21252;
24        printf("Case %d: the next triple peak occurs in %d days.\n"++index,day->= 0 ? day-d : day-d+21252);
25    }
while(1); 
26    return 0;
27}
posted @ 2008-05-30 20:43 Leon916 阅读(1209) | 评论 (4)编辑 收藏
 
     这是我做1005题的代码,希望大家看完之后能给予指导。
   
 1#include <stdio.h>
 2
 3#define PI 3.141592
 4
 5int Caculate(float x, float y)
 6{
 7    int r = (int)((x*+ y*y) * PI / 100);
 8    return  r*100 >= (x*+ y*y)*PI ? r : r+1;
 9}

10
11int main(int argc, char* argv[])
12{
13    int n, i;
14    float x,y;
15    int year;
16    scanf("%d"&n);
17    for(i = 1; i <= n; i++)
18    {
19        scanf("%f %f"&x, &y);
20        year = Caculate(x, y);
21        printf("Property %d: This property will begin eroding in year %d.\n", i, year);
22    }

23    printf("END OF OUTPUT.\n");
24    
25    return 0;
26}

27
28
posted @ 2008-05-29 08:40 Leon916 阅读(1174) | 评论 (4)编辑 收藏
 
    今天提交了1004,但总觉得题意好像没有这么简单。先贴上自己的代码,大家是怎么思考这道题的?

 1#include <stdio.h>
 2int main(int argc, char* argv[])
 3{
 4    int i;
 5    float sum = 0, temp;
 6    for(i = 0; i < 12; i++)
 7    {
 8        scanf("%f"&temp);
 9        sum += temp;
10    }

11    printf("$%.2f", sum/12);
12    return 0;
13}
posted @ 2008-05-25 20:12 Leon916 阅读(937) | 评论 (2)编辑 收藏
 
    今天做的这道题感觉上面很奇怪,按照题目要求写了代码,但总觉得哪里有什么地方不对,还请大家多多指教!
 1#include <stdio.h>
 2int main(int argc, char* argv[])
 3{
 4    float s,sum = 0;
 5    int i,j;
 6    while(scanf("%f"&sum) == 1)
 7    {
 8        if(sum != 0)
 9        {
10            j = 2; s = 0;
11            while(s < sum)
12            {
13                s += 1.0/j;
14                j++;
15            }

16            printf("%d card(s)\n", j-2);
17        }

18        else
19            break;
20    }

21        return 0;
22}
posted @ 2008-05-24 10:35 Leon916 阅读(1190) | 评论 (8)编辑 收藏
 
     摘要:       这道题我做的很郁闷,代码也写的不好、很长,方法也一般,有点麻烦,自己都觉得很烂,在提交的时候,发现别人的代码写的很简练,但是不知道自己该怎么改进,希望大家多多提意见,谢谢大家了!     1#include <string.h>  2#include&...  阅读全文
posted @ 2008-05-22 14:16 Leon916 阅读(1535) | 评论 (1)编辑 收藏
 
     昨天晚上写完了这道题,早上过来提交。 主要用到了插入排序算法,并且参看了桶排序算法,如果大家有什么好的想法,希望能够共享一下,嘿嘿!我的代码有哪里写的不好,也请大家指教!
 1#include <stdlib.h>
 2#include <stdio.h>
 3typedef struct dNANumber
 4{
 5    char ch[100];
 6    int count;
 7}
DNANumber;
 8
 9void Sort(DNANumber *arr, int rows)
10{
11    int i, j;
12    DNANumber temp;
13    for(i = 1; i < rows; i++)
14    {
15        temp = arr[i];
16        for(j = i-1; j >= 0; j--)
17        {
18            if(arr[j].count > temp.count)
19                arr[j+1= arr[j];
20            else 
21                break;
22        }

23        arr[j+1= temp;
24    }

25    return;
26}

27
28int Index(char ch)
29{
30    switch(ch)
31    {
32    case 'A':
33        return 0;
34    case 'C':
35        return 1;
36    case 'G':
37        return 2;
38    case 'T':
39        return 3;
40    }

41}

42
43void CountNumber(DNANumber *dna, int length)
44{
45    int count = 0;
46    int letter[4= {0,0,0,0};
47    int i, j;
48    int temp;
49    
50    for(i = 0; i < length; i++)
51    {
52        letter[Index(dna->ch[i])]++;
53    }

54
55    for(i = length-1; i >= 0; i--)
56    {
57        temp = Index(dna->ch[i]);
58        for(j = temp+1; j < 4; j++)
59        {
60            count += letter[j];
61        }

62        letter[temp]--;            
63    }

64    dna->count = count;
65    return;
66}

67int main(int argc, char* argv[])
68{
69    int length = 0, rows = 0;
70    int i;
71    DNANumber dnaArray[10000];
72    //DNANumber *dna;
73
74    scanf("%d %d"&length, &rows);
75    for(i = 0; i < rows; i++)
76    {
77        dnaArray[i].count=0;
78        scanf("%s", dnaArray[i].ch);
79        CountNumber(&dnaArray[i], length);        
80    }

81
82    Sort(dnaArray, rows);
83
84    for(i = 0; i < rows; i++)
85    {
86        printf("%s\n", dnaArray[i].ch);
87    }

88    return 0;
89}

90
91
92

posted @ 2008-05-20 08:24 Leon916 阅读(1225) | 评论 (1)编辑 收藏
 

   在上周开始做北大acm1002题,经过几天的分析和参考别人的代码,最后终于提交成功了。在这里把代码贴出来,和大家分享,也恳请大家指出写不好的地方。在网上搜到了另外一个人对这道题的解法,他是解法,推荐大家看看。

 1#include <stdlib.h>
 2#include <stdio.h>
 3typedef int TelNumber;
 4int toNumber[26= {2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,-1,7,7,8,8,8,9,9,9,-1};
 5
 6void SortNumber(TelNumber *tel, int left, int right)
 7{
 8    int j,i;
 9    TelNumber temp;
10    do
11    {
12        i = left;
13        j = right;
14        temp = tel[(i+j)/2];
15        do
16        {
17            while(tel[i] < temp) i++;
18            while(tel[j] > temp) j--;
19            if(i > j)
20                break;
21            if(i < j)
22            {
23                TelNumber t = tel[i];
24                tel[i] = tel[j];
25                tel[j] = t;
26            }

27            i++;j--;
28        }
while(i <= j);
29        
30        if(j-left <= right -i)
31        {
32            if(left < j)
33                SortNumber(tel,left, j);
34            left = i;
35        }

36        else
37        {
38            if(i < right)
39                SortNumber(tel, i, right);
40            right = j;
41        }

42    }
while(left < right);
43}

44
45int main(int argc, char* argv[])
46{
47    int count;
48    int i;
49    int t = 1;
50    int bSame = 0;
51    TelNumber tel[100000];
52    scanf("%d\n"&count);
53    for( i = 0; i < count;i++)
54    {
55        char ch;
56        tel[i] = 0;
57        while( ch = getchar(), ch != '\n')
58        {
59            if(ch == '-')
60                continue;
61            else if (ch >= '0' && ch <= '9')
62                tel[i] = tel[i]*10 + (ch-'0');
63            else if((ch >= 'A' && ch <= 'P'|| (ch >= 'R' && ch <= 'Y'))
64                tel[i] = tel[i]*10 + toNumber[ch-'A'];
65        }

66    }

67
68    SortNumber(tel, 0, count-1);
69    for(i = 0; i < count;)
70    {
71        for(t = i+1; (t < count) && (tel[i] == tel[t]); t++)
72            ;
73        if(t-> 1)
74        {
75            bSame = 1;
76            printf("%03d-%04d %d\n", tel[i]/10000, tel[i]%10000, t-i);
77        }

78        i=t;
79    }

80    if(bSame==0)
81         printf("No duplicates.\n");
82    return 1;
83}
posted @ 2008-05-19 10:44 Leon916 阅读(1455) | 评论 (4)编辑 收藏
 
     摘要: 今天下午做了一道acm的题,提交了10次都是WA,所以想请大家帮我看看到底哪里不正确,程序哪里写的不好!谢谢大家了!代码:   1#include <stdlib.h>  2#include <stdio.h>  3typedef struct telNumber ...  阅读全文
posted @ 2008-05-15 19:29 Leon916 阅读(218) | 评论 (0)编辑 收藏
仅列出标题
共3页: 1 2 3 
 
Copyright © Leon916 Powered by: 博客园 模板提供:沪江博客