Codeforces Round #155 (Div. 2)

第三个题,自己sb不解释啊。。想了1个小时+,愣是没想清楚过程,好在前两个还算比较稳,rating小升,第一次上1600+。。。

第一个题,题意很简单,刚想开敲,发现如果有很多重复的不好哈希,有点激动了,好在想了几分钟后,乱搞一种,边哈希,一边输出的办法,10分钟。

 1 #include <cstdio>

 2 #include <cstring>

 3 #include <string>

 4 #include <map>

 5 #include <queue>

 6 #include <vector>

 7 #include <algorithm>

 8 #include <iostream>

 9 using namespace std;

10 int p[1000000],o[5001];

11 int main()

12 {

13     int n,i,z;

14     freopen("input.txt","r",stdin);

15     freopen("output.txt","w",stdout);

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

17     for(i = 1;i <= 2*n;i ++)

18     {

19         scanf("%d",&p[i]);

20         o[p[i]] ++;

21     }

22     z = 0;

23     for(i = 1;i <= 5000;i ++)

24     {

25         if(o[i]%2 == 1)

26         {

27             z = 1;

28             break;

29         }

30     }

31     if(z)

32     {

33         printf("-1\n");

34         return 0;

35     }

36     memset(o,0,sizeof(o));

37     for(i = 1;i <= 2*n;i ++)

38     {

39         if(o[p[i]])

40         {

41             printf("%d %d\n",o[p[i]],i);

42             o[p[i]] = 0;

43         }

44         else

45         o[p[i]] = i;

46     }

47     return 0;

48 }

第二个题,看懂题,认真一点,就没问题,39分钟AC。

 1 #include <cstdio>

 2 #include <cstring>

 3 #include <string>

 4 #include <map>

 5 #include <queue>

 6 #include <vector>

 7 #include <algorithm>

 8 #include <iostream>

 9 using namespace std;

10 int p[1001];

11 int mon[14] = {31,28,31,30,31,30,31,31,30,31,30,31};

12 int sum[14];

13 int main()

14 {

15     int n,i,j,m,d,q,t;

16     freopen("input.txt","r",stdin);

17     freopen("output.txt","w",stdout);

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

19     sum[0] = mon[0];

20     for(i = 1;i <= 11;i ++)

21     sum[i] = sum[i-1]+mon[i];

22     for(i = 1;i <= n;i ++)

23     {

24         scanf("%d%d%d%d",&m,&d,&q,&t);

25         for(j = 1;j <= t;j ++)

26         {

27             if(m > 1)

28             p[100+sum[m-2]+d-j] += q;

29             else

30             p[100+d-j] += q;

31         }

32     }

33     int ans = 0;

34     for(i = 1;i <= 1000;i ++)

35     {

36         if(ans < p[i])

37         ans = p[i];

38     }

39     printf("%d\n",ans);

40     return 0;

41 }

悲剧啊。。。

 1 #include <cstdio>

 2 #include <cstring>

 3 #include <string>

 4 #include <map>

 5 #include <queue>

 6 #include <vector>

 7 #include <algorithm>

 8 #include <iostream>

 9 using namespace std;

10 char s1[100001],s2[100001];

11 int o1[301],o2[301],o4[301];

12 int key[100001];

13 int Abs(int a)

14 {

15     if(a < 0)

16     return -a;

17     else

18     return a;

19 }

20 int main()

21 {

22     int i,j,len,t,ans = 0;

23     freopen("input.txt","r",stdin);

24     freopen("output.txt","w",stdout);

25     scanf("%s%s",s1,s2);

26     len = strlen(s1);

27     for(i = 0;i <= len-1;i ++)

28     {

29         t = s1[i];

30         o1[t] ++;

31         t = s2[i];

32         o2[t] ++;

33     }

34     for(i = 1;i <= 200;i ++)

35     {

36         if(o1[i] != o2[i])

37         {

38             ans += Abs(o1[i]-o2[i]);

39         }

40     }

41     ans = ans/2;

42     printf("%d\n",ans);

43     for(i = 0;i <= len-1;i ++)

44     {

45         if(o1[s1[i]] > o2[s1[i]])

46         {

47             for(j = 'A';j <= 'Z';j ++)

48             {

49                 if(o1[j] < o2[j])

50                 {

51                     if(j < s1[i])

52                     {

53                         printf("%c",j);

54                         o1[j] ++;

55                         o1[s1[i]] --;

56                     }

57                     else if(o4[s1[i]] == o2[s1[i]])

58                     {

59                         printf("%c",j);

60                         o1[j] ++;

61                     }

62                     else

63                     {

64                         printf("%c",s1[i]);

65                         o4[s1[i]] ++;

66                     }

67                     break;

68                 }

69             }

70             if(j == 'Z'+1)

71             printf("%c",s1[i]);

72         }

73         else

74         printf("%c",s1[i]);

75     }

76     return 0;

77 }

 

你可能感兴趣的:(codeforces)