第六场组队赛总结
A题:http://acm.timus.ru/problem.aspx?space=1&num=1830
题目来源:URAL 1830~1840
这次组队赛我们队每个人都状态不好,刚来到就发现A题是跟之前个人赛题意一样的题目,不过当时赛后没有看怎么做。这题如果知道原理,也就是格雷码,那么这题就可以瞬间秒杀的。不过我的队友是这样推的,把它当作dp来做,划分小问题,然后累加求解。
这个解法在开始后整整两个钟才整理好思路,这个过程中,我切了一道相对比较水的bfs(H题),不过因为判断少了一个条件,sample都没对。不过,刚打完的时候,因为只错了一个数字,所以没发现,直接交了上去,WA了。然后仔细看了一遍才发现。debug了好几分钟,改了就过了!
然后就全力攻克A题,不断的验证思路是否正确。不过当时我们状态都相当一般,所以搞了很久,几乎都有放弃的心了。思路被验证出是正确的,小问题的划分也是对的,搞到最后只剩半个钟了,我才突发奇想,搞了个极端的数据,然后就发现这个算法的缺陷了.....囧!不过其实就是少了一个特判,也是一个十分特殊的判断。改过来以后再提交就通过了!T^T
剩下半个钟,我想到了I题是区间合并,当时觉得自己写区间合并太麻烦了,于是就直接抄了个模板,然后套上自己的输入。打完以后时间只剩几分钟了,与于是本地测sample过了以后就立马交上去。显然,没有1Y,然后就想到,自己的思路貌似错了,最后来不及改了。赛后和别人交流的时候,知道自己想法是对的,可惜一开始的区间处理不对....
最后我们以两题这个悲惨的结果垫底了.......
A:
1 #include <cstdio> 2 #include <cmath> 3 4 const int maxn = 51; 5 typedef __int64 ll; 6 7 char tmp[51]; 8 9 ll max2(ll a, ll b){return a > b ? a : b; } 10 11 int main(){ 12 ll a, b; 13 int n; 14 15 #ifndef ONLINE_JUDGE 16 freopen("in", "r", stdin); 17 #endif 18 scanf("%d", &n); 19 a = b = 0; 20 21 scanf("%s", tmp); 22 a += (ll)(tmp[n - 1] - '0') << (n - 1); 23 for (int i = n - 1; i > 0; i--){ 24 if (tmp[i - 1] != tmp[i]){ 25 tmp[i - 1] = '1'; 26 a += (ll)1 << (i - 1); 27 } 28 else tmp[i - 1] = '0'; 29 } 30 31 scanf("%s", tmp); 32 b += (ll)(tmp[n - 1] - '0') << (n - 1); 33 for (int i = n - 1; i > 0; i--){ 34 if (tmp[i - 1] != tmp[i]){ 35 tmp[i - 1] = '1'; 36 b += (ll)1 << (i - 1); 37 } 38 else tmp[i - 1] = '0'; 39 } 40 #ifndef ONLINE_JUDGE 41 printf("%I64d %I64d\n", a, b); 42 #endif 43 printf("%I64d\n", max2(a - b, b - a)); 44 45 return 0; 46 }
H:
1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <string> 5 #include <map> 6 #include <string> 7 #include <set> 8 9 using namespace std; 10 11 char team[101][3][25]; 12 map<string, int> num; 13 set<string> ss; 14 set<string>::iterator ii; 15 bool vis[101]; 16 char q[300][25]; 17 int front, back; 18 19 int main(){ 20 int n; 21 #ifndef ONLINE_JUDGE 22 freopen("in", "r", stdin); 23 #endif 24 25 scanf("%d", &n); 26 front = back = 0; 27 num.clear(); 28 ss.clear(); 29 memset(vis, false, sizeof(vis)); 30 31 for (int i = 0; i < n; i++){ 32 scanf("%s%s%s", team[i][0], team[i][1], team[i][2]); 33 for (int j = 0; j < 3; j++){ 34 if (ss.count(team[i][j]) == 0){ 35 if (!strcmp(team[i][j], "Isenbaev")) num[team[i][j]] = 0; 36 else num[team[i][j]] = -1; 37 ss.insert(team[i][j]); 38 } 39 } 40 } 41 42 strcpy(q[back], "Isenbaev"); 43 back++; 44 45 while (front != back){ 46 for (int i = 0; i < n; i++){ 47 if (vis[i]) continue; 48 int j; 49 50 for (j = 0; j < 3; j++){ 51 if (!strcmp(q[front], team[i][j])){ 52 break; 53 } 54 } 55 if (j < 3){ 56 for (j = 0; j < 3; j++){ 57 if (strcmp(team[i][j], q[front]) && num[team[i][j]] == -1){ 58 if (num[team[i][j]] == -1){ 59 strcpy(q[back], team[i][j]); 60 #ifndef ONLINE_JUDGE 61 printf("pop in %s\n", q[back]); 62 #endif 63 back++; 64 } 65 num[team[i][j]] = num[q[front]] + 1; 66 } 67 } 68 vis[i] = true; 69 } 70 } 71 front++; 72 } 73 74 for (ii = ss.begin(); ii != ss.end(); ii++){ 75 if (num[*ii] == -1)printf("%s undefined\n", (*ii).c_str()); 76 else printf("%s %d\n", (*ii).c_str(), num[*ii]); 77 } 78 79 return 0; 80 }
I:其实跟我刚开始的思路是一样的,不过我刚开始的时候打错了一点东西,而且还忘记了那个限制条件。加上去以后就过了!
1 #include <cstdio> 2 #include <algorithm> 3 #include <cmath> 4 #include <vector> 5 #include <map> 6 #include <queue> 7 #include <list> 8 #include <set> 9 #include <cstring> 10 #include <string> 11 12 using namespace std; 13 14 #define INF 0x7fffffff; 15 #define max4(a, b, c, d) (max2(a, b) > max2(c, d) ? max2(a, b) : max2(c, d)) 16 #define min4(a, b, c, d) (min2(a, b) < min2(c, d) ? min2(a, b) : min2(c, d)) 17 #define feq(a, b) fabs((a) - (b)) < eps 18 #define flq(a, b) (feq(a, b) || (a) < (b)) 19 #define reset(a) memset(a, 0, sizeof(a)) 20 #define fileout freopen("test.out", "w", stdout) 21 #define filein freopen("test.in", "r", stdin) 22 //segment tree 23 #define lson l, m, rt << 1 24 #define rson m + 1, r, rt << 1 | 1 25 #define root 1, n, 1 26 27 #define debug 1 28 29 const double eps = 1e-6; 30 const int maxn = 100001; 31 32 double max2(double a, double b){return a > b ? a : b;} 33 double min2(double a, double b){return a < b ? a : b;} 34 35 struct line{ 36 double s, t; 37 }l1[maxn], l2[maxn], ll[maxn]; 38 39 bool in[maxn]; 40 41 bool cmp(line a, line b){ 42 if (fabs(a.s - b.s) > eps) return a.s < b.s; 43 return a.t < b.t; 44 } 45 46 bool nocross(line a, line b){ 47 return a.s > b.t || b.s > a.t; 48 } 49 50 void me(line a[], int &k){ 51 int i, j, n = k; 52 k = 0; 53 sort(a, a + n, cmp); 54 memset(in, false, sizeof(in)); 55 for (i = 0; i < n; i++){ 56 if (!in[i]){ 57 in[i] = true; 58 a[k].s = a[i].s; 59 a[k].t = a[i].t; 60 for (j = i + 1; j < n; j++){ 61 if (nocross(a[k], a[j])) break; 62 if (a[k].t < a[j].t) a[k].t = a[j].t; 63 in[j] = true; 64 } 65 k++; 66 } 67 } 68 } 69 70 void calm(line a[], int n, line b[], int m, line c[], int &k){ 71 k = 0; 72 if (!n || !m) return; 73 int i = 0, j = 0, w; 74 while (i < n && j < m){ 75 if (a[i].s < b[j].s){ 76 for (w = j; b[w].s < a[i].t && w < m; w++){ 77 c[k].s = b[w].s; 78 c[k].t = min2(a[i].t, b[w].t); 79 k++; 80 } 81 j = w; 82 i++; 83 if (j && (!nocross(a[i], b[j - 1]))) j--; 84 } 85 else { 86 for (w = i; a[w].s < b[j].t && w < n; w++){ 87 c[k].s = a[w].s; 88 c[k].t = min2(a[w].t, b[j].t); 89 k++; 90 } 91 i = w; 92 j++; 93 if (i && (!nocross(a[i - 1], b[j]))) i--; 94 } 95 } 96 } 97 98 double p[maxn]; 99 100 int main() 101 { 102 #ifndef ONLINE_JUDGE 103 freopen("in", "r", stdin); 104 #endif 105 int n, m1, m2; 106 double L; 107 scanf("%lf%d", &L, &n); 108 for (int i = 0; i < n; i++) 109 scanf("%lf", &p[i]); 110 if (n <= 3){ 111 printf("%.0f\n", L); 112 return 0; 113 } 114 for (int i = 1; i < n; i++){ 115 l1[i - 1].s = max2(p[0] * 2, p[i]); 116 l1[i - 1].t = min2(p[i] * 2, L); 117 } 118 for (int i = n - 2; i >= 0; i--){ 119 l2[i - 1].t = min2(L - (L - p[n - 1]) * 2, p[i]); 120 l2[i - 1].s = max2(0, L - (L - p[i]) * 2); 121 } 122 123 m1 = m2 = n - 1; 124 me(l1, m1); 125 me(l2, m2); 126 calm(l1, m1, l2, m2, ll, n); 127 double sum = 0; 128 129 for (int i = 0; i < n; i++){ 130 sum += ll[i].t - ll[i].s; 131 } 132 printf("%.0f\n", L - sum); 133 134 return 0; 135 }
——written by Lyon