总结的来说,这次还是只有一道题,但是我是属于被第一题坑了。
Problem A
题目概述:
简单到死的代码题,就是题目给你一个式子,然后让你按照这个式子算给定的数,之后比较大小。
算法思想:
别问我为什么错了....因为我在double之间判断了大小....忽略了题目中所给的其一定能被250整除卧槽。但是其实看很多人double写上去也对了,这可能是因为他们算3/10的时候是3*double/10,我是double*0.3。应该是编译器内部的一些问题嗯。
代码部分:
#include <iostream> #include <stdio.h> #include <string> #include <string.h> #include <map> #include <cmath> #include <algorithm> using namespace std; int n; double a, b, c, d; int main() { cin >> a >> b >> c >> d; double mi = max(3*a/10, a - a / 250 * c); double va = max(3*b/10, b - b / 250 * d); if (mi > va) cout << "Misha" << endl; else if (mi < va) cout << "Vasya" << endl; else if (mi == va) cout << "Tie" << endl; return 0; }
Problem B
题目概述:
不想写概述啊不想写,大意就是给定一些字符串的链接组合,如果给定了B-C且之前有A-B的话就把它替换成A-C的组合。
算法思想:
我用的方法比较水,有一次开了两个map来做双向记录,开始给A-B组合的话就把pair<A,B>插到第一个map,把pair<B,A>插入第二个map,这样给定B-C时候的话就到第二个map里面检查是否有B,然后有的话做替换操作,没有的话模仿第一次插入就好了。
代码部分:
#include <iostream> #include <stdio.h> #include <string> #include <string.h> #include <map> #include <cmath> #include <algorithm> using namespace std; int n; int main() { cin >> n; map<string, string> mymap1; map<string, string> mymap2; for (int i = 0; i < n; i++) { string s1, s2; cin >> s1 >> s2; if (mymap2.count(s1)) { mymap1[mymap2[s1]] = s2; mymap2.insert(make_pair(s2, mymap2[s1])); } else { mymap1.insert(make_pair(s1, s2)); mymap2.insert(make_pair(s2,s1)); } } cout << mymap1.size() << endl; for (map<string, string>::iterator it = mymap1.begin(); it != mymap1.end(); ++it) { cout << it->first << " " << it->second << endl; } return 0; }
Problem C
题目概述:
好了,终于到了我比赛时候彻底不会做的一道题。这道题是说所给的是一个无向无环图,现在给定每一个顶点的degree (有几个顶点和他相连),以及它相邻顶点的亦或和,要求把所有边都输出出来。
算法思想:
开始读这道题的时候心里想的是卧槽这tm是啥啊这能算。
当然到比赛结束的时候心里都是这么想的。
一直到今天去查题解,然后终于明白了,卧槽原来是这么一回事。
首先题目是一个无环图!无环!那就说明必然存在有一个点的degree是为1的!那么去掉这个点(把与之相连的点的degree-1,xum减去这个点的index)剩下的肯定还是一个无!环!图!那么肯定还存在有一个点degree为1,所以重复上述操作!卧槽然后就做出来了。
值得注意的是在队列里面有可能加进去的时候degree为1,但是前一个剪完之后degree就为0了,这种情况要跳过。
代码部分:
#include <iostream> #include <stdio.h> #include <queue> using namespace std; int n; int deg[66666]; int xsum[66666]; int edge[66666][2]; int main() { queue<int> q; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d",°[i],&xsum[i]); if (deg[i] == 1) q.push(i); } int x = 0; while (!q.empty()) { int tmp = q.front(); q.pop(); if (deg[tmp] == 0) { continue; } int j = xsum[tmp]; deg[j]--; xsum[j] = xsum[j] ^ tmp; if (deg[j] == 1) { q.push(j); } edge[x][0] = tmp; edge[x][1] = j; x++; } cout << x << endl; for (int i = 0; i < x; i++) { cout << edge[i][0] << " " << edge[i][1] << endl; } return 0; }