Andrew Stankevich's Contest (1)

 

国庆第一天放假,但是Uva果断上不去,数据库好像又崩了.那就看看ASC吧.其实是第一次做俄罗斯的多校.原来watashi把俄罗斯的所有多校全部刷过一遍..
果然牛x,这个世界上其实没有天才,努力的人多了,就有了天才,orz之.

 

Chinese Girls' Amusement

/*这道题还是找规律的题目,

但实际上我更想知道如何证明*/



如果n是2m+1形式的,那么k=m就是答案;

如果n是4m形式的,那么k=2m-1就是答案;

如果n是4m+2形式的,那么k=2m-1就是答案。

证明略,需要简单的高精度。

 

 1 #include <cstdio>

 2 #include <cstring>

 3 #define CLR( a, b )     memset( a, b, sizeof(a) )

 4 #define MAXN 2020

 5 

 6 char buf[MAXN];

 7 

 8 char* Div2(char *p, int l)

 9 {

10     for(int i=0; i < l; i++)

11     {

12         if(p[i] & 1)

13             p[i + 1] += 10;

14         p[i] >>= 1;

15     }

16     p[l] = 0;

17     while(*p == 0)  ++p;

18     return p;

19 }

20 

21 char* Sub1(char *p, int l)

22 {

23     int i = l - 1;

24     while(p[i] == 0)

25         p[i--] = 9;

26     --p[i];

27     while(*p == 0)  p++;

28     return p;

29 }

30 

31 void Orz()

32 {

33     while(~scanf("%s",buf))

34     {

35         char *p = NULL;

36         int len = strlen(buf);

37         for(int i=0; i < len; i++)

38             buf[i] = buf[i] - '0';

39         if( buf[len-1] & 1 )

40             p = Div2(buf, len);

41         else

42         {

43             p = Div2(buf, len);

44             p = Sub1(buf, len);

45             if( !(buf[len-1] & 1) )

46                 p = Sub1(buf, len);

47         }

48         for(int i=0;i < len; i++)

49             buf[i] += '0';

50         puts(p);

51     }

52     getchar();

53 }

54 

55 int main()

56 {

57     Orz();

58     return 0;

59 }
代码君

 

你可能感兴趣的:(test)