Codeforces Rockethon 2014 解题报告

这次题目好难读各种专业词汇。。。把做出来的题贴一下把。

Problem A Genetic Engineering

思路:遍历一遍然后求出长度为奇数个的一样字母长度,即为答案。

代码如下:

 1 /**************************************************
 2  * Author     : xiaohao Z
 3  * Blog     : http://www.cnblogs.com/shu-xiaohao/
 4  * Last modified : 2014-02-17 01:53
 5  * Filename     : Rockethon_2014_A_1.cpp
 6  * Description     : 
 7  * ************************************************/
 8 
 9 #include <iostream>
10 #include <cstdio>
11 #include <cstring>
12 #include <cstdlib>
13 #include <cmath>
14 #include <algorithm>
15 #include <queue>
16 #include <stack>
17 #include <vector>
18 #include <set>
19 #include <map>
20 #define MP(a, b) make_pair(a, b)
21 #define PB(a) push_back(a)
22 
23 using namespace std;
24 typedef long long ll;
25 typedef pair<int, int> pii;
26 typedef pair<unsigned int,unsigned int> puu;
27 typedef pair<int, double> pid;
28 typedef pair<ll, int> pli;
29 typedef pair<int, ll> pil;
30 
31 const int INF = 0x3f3f3f3f;
32 const double eps = 1E-6;
33 const int LEN = 110;
34 char str[LEN];
35 
36 int main()
37 {
38 //    freopen("in.txt", "r", stdin);
39     
40     while(cin >> str){
41         int len = strlen(str), ans = 0, lc = 0;
42         char c = str[0];
43         for(int i=0; i<len; i++){
44             if(str[i] == c) lc++;
45             else {
46                 if(lc%2==0) ans ++;
47                 lc = 1;c = str[i];
48             }
49         }
50         if(lc%2==0) ans++;
51         printf("%d
", ans);
52     }
53     return 0;
54 }
View Code

Problem B Word Folding

题意:题目中告诉你了折叠的方法,然后问你折出来一列上都为同一个字母最高的高度为多少。注意当中不能有空档

思路:我们可以发现只要两个相同的字母相隔为奇数就能折上去,即得到比原来长度+1的一列,这样问题就转化为lis。

代码如下:

 1 /**************************************************
 2  * Author     : xiaohao Z
 3  * Blog     : http://www.cnblogs.com/shu-xiaohao/
 4  * Last modified : 2014-02-17 01:53
 5  * Filename     : Rockethon_2014_B_1.cpp
 6  * Description     : 
 7  * ************************************************/
 8 
 9 #include <iostream>
10 #include <cstdio>
11 #include <cstring>
12 #include <cstdlib>
13 #include <cmath>
14 #include <algorithm>
15 #include <queue>
16 #include <stack>
17 #include <vector>
18 #include <set>
19 #include <map>
20 #define MP(a, b) make_pair(a, b)
21 #define PB(a) push_back(a)
22 
23 using namespace std;
24 typedef long long ll;
25 typedef pair<int, int> pii;
26 typedef pair<unsigned int,unsigned int> puu;
27 typedef pair<int, double> pid;
28 typedef pair<ll, int> pli;
29 typedef pair<int, ll> pil;
30 
31 const int INF = 0x3f3f3f3f;
32 const double eps = 1E-6;
33 const int LEN = 1010;
34 char str[LEN];
35 int dp[LEN];
36 
37 int main()
38 {
39     //freopen("in.txt", "r", stdin);
40 
41     while(cin >> str){
42         int len = strlen(str);
43         for(int i=0; i<len; i++){
44             dp[i] = 1;
45             for(int j=0; j<i; j++){
46                 if(str[i] == str[j] && (i-j)%2==1) dp[i] = max(dp[i], dp[j]+1);
47             }
48         }
49         int ans = 0;
50         for(int i=0; i<len; i++) ans = max(ans, dp[i]);
51         printf("%d
" ,ans);
52     }
53     return 0;
54 }
View Code

Problem C The Tournament (C1,C2)

题意:一个人打竞标赛,一共有n个对手期望排名在k前面。每个对手初始有一个值p,和打赢他的预计花费e。这个人必须和每个对手打仅一场,有两种情况:1.花费e打赢他自己p+1 2.花费0输掉,对手p+1。问你达到期望的最小花费。

思路:我们可以发现在枚举打赢的人的个数时,即可使用贪心算法。当对手p<i-1(i为枚举值从0-n)时对手排名必定在后面,p>i时对手排名必定在前面。所以对于p=i和i-1的按照花费排序,挑最小的打。大概思路就是这样,细节看代码(复杂度n^2)

代码如下:

 1 /**************************************************
 2  * Author     : xiaohao Z
 3  * Blog     : http://www.cnblogs.com/shu-xiaohao/
 4  * Last modified : 2014-02-17 01:54
 5  * Filename     : Rockethon_2014_C_2.cpp
 6  * Description     : 
 7  * ************************************************/
 8 
 9 #include <iostream>
10 #include <cstdio>
11 #include <cstring>
12 #include <cstdlib>
13 #include <cmath>
14 #include <algorithm>
15 #include <queue>
16 #include <stack>
17 #include <vector>
18 #include <set>
19 #include <map>
20 #define MP(a, b) make_pair(a, b)
21 #define PB(a) push_back(a)
22 
23 using namespace std;
24 typedef long long ll;
25 typedef pair<int, int> pii;
26 typedef pair<unsigned int,unsigned int> puu;
27 typedef pair<int, double> pid;
28 typedef pair<ll, int> pli;
29 typedef pair<int, ll> pil;
30 
31 const int INF = 0x3f3f3f3f;
32 const double eps = 1E-6;
33 const int LEN = 102;
34 int n, k;
35 struct O{
36     int p, e;
37 };
38 O op[LEN];
39 int top[LEN], flag[LEN];
40 
41 bool cmp1(O a, O b){return a.e < b.e;}
42 
43 int main()
44 {
45 //    freopen("in.txt", "r", stdin);
46 
47     while(scanf("%d%d", &n, &k)!=EOF){
48         for(int i=0; i<n; i++) {
49             scanf("%d%d", &op[i].p, &op[i].e);
50                top[i] = op[i].p;        
51         }
52         sort(op, op+n, cmp1);
53         sort(top, top+n);
54         int ans = INF;
55         for(int i=0; i<=n; i++){
56             int cnt = 0, ta = 0, pm = lower_bound(top, top+n, i-1)-top;
57             memset(flag, 0, sizeof flag);
58             for(int j=0; j<n; j++){
59                 if(op[j].p == i || op[j].p == i-1){
60                     if((n-pm) < k || cnt==i) break;
61                     pm++;
62                     cnt++;
63                     flag[j] = 1;
64                     ta += op[j].e;
65                 }
66             }
67             for(int j=0; j<n; j++){
68                 if(!flag[j]){
69                     if(cnt==i) break;
70                     ta += op[j].e;
71                     cnt++;
72                 }
73             }
74             if((n-pm) < k) ans = min(ans, ta);
75         }
76         if(ans != INF)printf("%d
", ans);
77         else printf("-1
");
78     }
79     return 0;
80 }
View Code

Problem D Supercollider (D1)

题意:若干横向量和竖向量,两个向量横竖当相交时找出向量交点到四个顶点中的最小值再找出这个最小值在所有向量对中的最大值。

思路:小数据直接暴力枚举。比较水

代码如下:

 1 /**************************************************
 2  * Author     : xiaohao Z
 3  * Blog     : http://www.cnblogs.com/shu-xiaohao/
 4  * Last modified : 2014-02-17 01:55
 5  * Filename     : Rockethon_2014_D_1.cpp
 6  * Description     : 
 7  * ************************************************/
 8 
 9 #include <iostream>
10 #include <cstdio>
11 #include <cstring>
12 #include <cstdlib>
13 #include <cmath>
14 #include <algorithm>
15 #include <queue>
16 #include <stack>
17 #include <vector>
18 #include <set>
19 #include <map>
20 #define MP(a, b) make_pair(a, b)
21 #define PB(a) push_back(a)
22 
23 using namespace std;
24 typedef long long ll;
25 typedef pair<int, int> pii;
26 typedef pair<unsigned int,unsigned int> puu;
27 typedef pair<int, double> pid;
28 typedef pair<ll, int> pli;
29 typedef pair<int, ll> pil;
30 
31 const int INF = 0x3f3f3f3f;
32 const double eps = 1E-6;
33 const int LEN = 1010;
34 struct P{
35     int x, y, v;
36 };
37 P row[LEN], col[LEN];
38 int n, m;
39 
40 int main()
41 {
42     //freopen("in.txt", "r", stdin);
43 
44     while(scanf("%d%d", &n, &m)!=EOF){
45         for(int i=0; i<n; i++) scanf("%d%d%d", &col[i].x, &col[i].y, &col[i].v);
46         for(int i=0; i<m; i++) scanf("%d%d%d", &row[i].x, &row[i].y, &row[i].v);
47         int ans = 0;
48         for(int i=0; i<n; i++){
49             for(int j=0; j<m; j++){
50                 P zh;
51                 zh.x = col[i].x;
52                 zh.y = row[j].y;
53                 if(zh.x < row[j].x || zh.x > row[j].x+row[j].v || zh.y < col[i].y || zh.y > col[i].y+col[i].v) continue;
54                 int a = min(abs(zh.y-col[i].y), abs(zh.y-(col[i].y+col[i].v)));
55                 int b = min(abs(zh.x-row[j].x), abs(zh.x-(row[j].x+row[j].v)));
56                 int temp = min(a, b);
57                 ans = max(temp, ans);
58             }
59         }
60         printf("%d
", ans);
61     }
62     return 0;
63 }
View Code
奔跑吧!少年!趁着你还年轻
原文地址:https://www.cnblogs.com/shu-xiaohao/p/3552070.html