USACO 2.2 Preface Numbering(模拟)

 罗马数字问题。记得以前做过很类似的,那个数据范围小,100以内,我把前100个数全写出来存数组了。。。这个3500,乱搞就行。。

 1 /*

 2 ID: cuizhe

 3 LANG: C++

 4 TASK: preface

 5 */

 6 #include <cstdio>

 7 #include <cstring>

 8 #include <cmath>

 9 #include <algorithm>

10 using namespace std;

11 int p[3600][10];

12 char str[10] = "IVXLCDM";

13 int main()

14 {

15     int i,j,n;

16     freopen("preface.in","r",stdin);

17     freopen("preface.out","w",stdout);

18     for(i = 1;i <= 3500;i ++)

19     {

20        for(j = 1;j <= 7;j ++)

21        p[i][j] = p[i-1][j];

22        if(i%10 <= 3)

23        {

24            p[i][1] += i%10;

25        }

26        else if(i%10 <= 8)

27        {

28            p[i][1] += abs(i%10-5);

29            p[i][2] +=  1;

30        }

31        else if(i%10 == 9)

32        {

33            p[i][3] += 1;

34            p[i][1] += 1;

35        }

36        if((i/10)%10 <= 3)

37        {

38            p[i][3] += (i/10)%10;

39        }

40        else if((i/10)%10 <= 8)

41        {

42            p[i][3] += abs((i/10)%10-5);

43            p[i][4] += 1;

44        }

45        else if((i/10)%10 == 9)

46        {

47            p[i][5] += 1;

48            p[i][3] += 1;

49        }

50        if((i/100)%10 <= 3)

51        {

52            p[i][5] += (i/100)%10;

53        }

54        else if((i/100)%10 <= 8)

55        {

56            p[i][5] += abs((i/100)%10-5);

57            p[i][6] += 1;

58        }

59        else if((i/100)%10 == 9)

60        {

61            p[i][7] += 1;

62            p[i][5] += 1;

63        }

64        if((i/1000)%10 <= 3)

65        {

66            p[i][7] += (i/1000)%10;

67        }

68     }

69     scanf("%d",&n);

70     for(i = 0;i <= 6;i ++)

71     {

72         if(p[n][i+1] == 0)

73         break;

74         printf("%c %d\n",str[i],p[n][i+1]);

75     }

76     return 0;

77 }

你可能感兴趣的:(number)