码迷,mamicode.com
首页 > 其他好文 > 详细

Educational Codeforces Round 29(6/7)

时间:2017-10-17 01:08:57      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:最小值   splay   none   opened   cat   second   bsp   前缀   event   

1、Quasi-palindrome

  题意:问一个字符串(你可以添加前导‘0’或不添加)是否是回文串

  思路:将给定的字符串的前缀‘0’和后缀‘0’都去掉,然后看其是否为回文串

技术分享
 1 #include<iostream>
 2 using namespace std;
 3 int main()
 4 {
 5     int num;
 6     scanf("%d", &num);
 7     while (num / 10 != 0 && num % 10 == 0) num /= 10;
 8     int tmp = 0;
 9     int tnum = num;
10     while (tnum)
11     {
12         tmp = tmp * 10 + tnum % 10;
13         tnum /= 10;
14     }
15     if (tmp == num) printf("YES\n");
16     else printf("NO\n");
17 
18     return 0;
19 }
View Code

2、Kayaking

  题意:给出2*n个人的体重,有n-1辆双人车和2辆单人车,问每辆双人车上两个人的体重之差的和最小是多少

  思路:先把体重从小到大排序,然后枚举不坐双人车的两个人,算出剩下的人的最小体重差的和,取最小值。

技术分享
 1 #include<iostream>
 2 #include<algorithm>
 3 using namespace std;
 4 int wt[120];
 5 const int INF = 1e9;
 6 int main()
 7 {
 8     int n;
 9     scanf("%d", &n);
10     for (int i = 1; i <= 2 * n; i++)
11     {
12         scanf("%d", &wt[i]);
13     }
14     sort(wt + 1, wt + 2 * n + 1);
15 
16     int sum = INF;
17     for (int i = 1; i < 2 * n; i++)
18     {
19         for (int j = i + 1; j <= 2 * n; j++)
20         {
21             int tsum = 0;
22             for (int k = 1; k <= 2 * n;)
23             {
24                 while(k == i||k==j)
25                 {
26                     k++;
27                 }
28                 int w1 = wt[k];
29                 k++;
30                 while(k == j||k==i)
31                 {
32                     k++;
33                 }
34                 tsum += wt[k] - w1;
35                 k++;
36             }
37             sum = min(sum, tsum);
38         }
39     }
40     printf("%d\n", sum);
41     return 0;
42 }
View Code

3、1-2-3

  题意:给出Alice和Bob的出拳依据及他们第一次的出拳,问k轮后Alice和Bob的得分

  思路:找到循环节。

技术分享
  1 #include<iostream>
  2 #include<map>
  3 using namespace std;
  4 int alice[3][3];
  5 int bob[3][3];
  6 map<pair<int, int>, int>mp;
  7 map<int, pair<int, int> >score;
  8 int  a, b;
  9 long long k;
 10 int main()
 11 {
 12     scanf("%I64d%d%d", &k, &a, &b);
 13     for (int i = 0; i < 3; i++)
 14     {
 15         for (int j = 0; j < 3; j++)
 16         {
 17             scanf("%d", &alice[i][j]);
 18             alice[i][j]--;
 19         }
 20     }
 21     for (int i = 0; i < 3; i++)
 22     {
 23         for (int j = 0; j < 3; j++)
 24         {
 25             scanf("%d", &bob[i][j]);
 26             bob[i][j]--;
 27         }
 28     }
 29     int apoint = 0, bpoint = 0;
 30     int prea, preb;
 31     int kk = 0;
 32     int T,ta,tb,st;
 33     a--, b--;
 34     while (kk < k)
 35     {
 36         if (kk == 0)
 37         {
 38             prea = a;
 39             preb = b;
 40             if (a == 0 && b == 2|| a== 2 && b == 1||a==1&&b==0) apoint++;
 41             else if (b == 0 && a == 2 || b == 2 && a == 1 || b == 1 && a == 0)bpoint++;
 42             mp[make_pair(a, b)] = ++kk;
 43         }
 44         else
 45         {
 46             int aa = alice[prea][preb], bb = bob[prea][preb];
 47             if (st=mp[make_pair(aa, bb)])
 48             {
 49                 T = kk - st + 1;
 50                 pair<int, int>t1, t2;
 51                 if (T == 1)
 52                 {
 53                     t1 = score[st];
 54                     if (st > 1)
 55                     {
 56                         t2 = score[st - 1];
 57                         ta = t1.first - t2.first;
 58                         tb = t1.second - t2.second;
 59                     }
 60                     else
 61                     {
 62                         ta = t1.first, tb = t1.second;
 63                     }
 64                 }
 65                 else
 66                 {
 67                     if (st > 1)
 68                     {
 69                         t1 = score[st - 1];
 70                         t2 = score[kk];
 71                         ta = t2.first - t1.first;
 72                         tb = t2.second - t1.second;
 73                     }
 74                     else
 75                     {
 76                         t1 = score[kk];
 77                         ta = t1.first, tb = t1.second;
 78                     }
 79                 }
 80                 break;
 81             }
 82             if (aa == 0 && bb == 2 || aa == 2 && bb == 1 || aa == 1 && bb == 0) apoint++;
 83             else if (bb == 0 && aa == 2 || bb == 2 && aa == 1 || bb == 1 && aa == 0)bpoint++;
 84             mp[make_pair(aa, bb)] = ++kk;
 85             prea = aa, preb = bb;
 86         }
 87         score[kk] = make_pair(apoint, bpoint);
 88     }
 89     if (kk == k) printf("%d %d\n", apoint, bpoint);
 90     else
 91     {
 92         long long suma = 0, sumb = 0;
 93         if (st == 1) suma += 1ll*k / T*ta, sumb += 1ll*k / T*tb;
 94         else
 95         {
 96             pair<int, int>tmp = score[st - 1];
 97             suma += tmp.first, sumb += tmp.second;
 98             k -= st-1;
 99             suma += 1ll * k / T*ta, sumb += 1ll * k / T*tb;
100         }
101         if (k%T)
102         {
103             if (st == 1)
104             {
105                 pair<int, int>t = score[k%T];
106                 suma += t.first, sumb += t.second;
107             }
108             else
109             {
110                 pair<int, int>t1 = score[st-1];
111                 pair<int, int>t2 = score[k%T+st-1];
112                 suma += t2.first - t1.first, sumb += t2.second - t1.second;
113             }
114         }
115         printf("%I64d %I64d\n", suma, sumb);
116     }
117     return 0;
118 }
View Code

 

Educational Codeforces Round 29(6/7)

标签:最小值   splay   none   opened   cat   second   bsp   前缀   event   

原文地址:http://www.cnblogs.com/ivan-count/p/7679644.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!