河南工业大学2017校赛题解
Posted Flowersea
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了河南工业大学2017校赛题解相关的知识,希望对你有一定的参考价值。
问题 A: 饶学妹的比赛
题意:
给你一场比赛每人提交的记录,计算最后的排名
题解:
模拟+排序
代码:
1 #include <map> 2 #include <set> 3 #include <cmath> 4 #include <queue> 5 #include <stack> 6 #include <cstdio> 7 #include <string> 8 #include <vector> 9 #include <cstdlib> 10 #include <cstring> 11 #include <sstream> 12 #include <iostream> 13 #include <algorithm> 14 #include <functional> 15 using namespace std; 16 #define rep(i,a,n) for (int i=a;i<n;i++) 17 #define per(i,a,n) for (int i=n-1;i>=a;i--) 18 #define all(x) (x).begin(),(x).end() 19 #define pb push_back 20 #define mp make_pair 21 #define lson l,m,rt<<1 22 #define rson m+1,r,rt<<1|1 23 typedef long long ll; 24 typedef vector<int> VI; 25 typedef pair<int, int> PII; 26 const ll MOD = 1e9 + 7; 27 const int INF = 0x3f3f3f3f; 28 const int MAXN = 1010; 29 // head 30 31 struct Node { 32 int id; 33 string name; 34 int a[20] = { 0 }; 35 int b[20] = { 0 }; 36 int num = 0; 37 int time = 0; 38 const bool operator<(const Node &t) const { 39 if (num != t.num) return num > t.num; 40 else if (time != t.time) return time < t.time; 41 else return id < t.id; 42 } 43 }p[MAXN]; 44 45 int main() { 46 int n, m, k; 47 cin >> n >> m >> k; 48 rep(i, 1, n + 1) { 49 p[i].id = i; 50 cin >> p[i].name; 51 } 52 while (m--) { 53 int timei, idi, pidi; 54 string s; 55 cin >> timei >> idi >> pidi >> s; 56 if (s == "AC") { 57 if (!p[idi].b[pidi]) { 58 p[idi].b[pidi] = 1; 59 p[idi].a[pidi] += timei; 60 } 61 } 62 else { 63 if (!p[idi].b[pidi]) 64 p[idi].a[pidi] += 20; 65 } 66 } 67 rep(i, 1, n + 1) { 68 rep(j, 1, k + 1) if (p[i].b[j]) { 69 p[i].num++; 70 p[i].time += p[i].a[j]; 71 } 72 } 73 sort(p + 1, p + 1 + n); 74 rep(i, 1, n + 1) 75 cout << p[i].name << ‘ ‘ << p[i].num << ‘ ‘ << p[i].time << endl; 76 return 0; 77 }
问题 B: 地狱飞龙
题意:
有一头龙从(0,0)往y轴正方向跑,有一人从(x,0)往x轴负方向跑,这头龙每秒对人造成k/d2的伤害(d为距离)
求这个人必须有多少HP,才永远不会死
题解:
就是一道数值积分,直接套模板就行了,但是:
这道题数据有误!
这道题数据有误!!
这道题数据有误!!!
你想啊,如果积分值为2.354,那不得有2.36的血才行吗,所以是不能四舍五入的,不然你就挂了
但是答案是四舍五入啊啊啊,
我们比赛时wa了50+都没想到是出题人sb啊
“AC”代码如下
代码:
1 #include <map> 2 #include <set> 3 #include <cmath> 4 #include <queue> 5 #include <stack> 6 #include <cstdio> 7 #include <string> 8 #include <vector> 9 #include <cstdlib> 10 #include <cstring> 11 #include <sstream> 12 #include <iostream> 13 #include <algorithm> 14 #include <functional> 15 using namespace std; 16 #define rep(i,a,n) for (int i=a;i<n;i++) 17 #define per(i,a,n) for (int i=n-1;i>=a;i--) 18 #define all(x) (x).begin(),(x).end() 19 #define pb push_back 20 #define mp make_pair 21 #define lson l,m,rt<<1 22 #define rson m+1,r,rt<<1|1 23 typedef long long ll; 24 typedef vector<int> VI; 25 typedef pair<int, int> PII; 26 const ll MOD = 1e9 + 7; 27 const int INF = 0x3f3f3f3f; 28 const int MAXN = 2010; 29 // head 30 31 const double EPS = 1e-6; 32 double v1, v2, x, k; 33 34 double f(double t){ 35 double d = v1*t*v1*t + (x - v2*t)*(x - v2*t); 36 return k / d; 37 } 38 39 inline double getAppr(double l, double r) { 40 return (f(l) + 4.0*f((l + r) / 2) + f(r)) * (r - l) / 6.0; 41 } 42 43 double Simpson(double l, double r) { 44 double sum = getAppr(l, r); 45 double mid = (l + r) / 2; 46 double suml = getAppr(l, mid); 47 double sumr = getAppr(mid, r); 48 return (fabs(sum - suml - sumr) < EPS) ? sum : Simpson(l, mid) + Simpson(mid, r); 49 } 50 51 int main() { 52 int T; 53 cin >> T; 54 while (T--) { 55 scanf("%lf%lf%lf%lf", &v1, &v2, &x, &k); 56 double ans = Simpson(0, 20000); 57 printf("%.2lf\n", ans); 58 } 59 return 0; 60 }
问题 C: 魔法宝石
题意:
创造第i个宝石需要a[i]膜法,或者可以两个合成一个,不需要膜法,问你合成每个的最小花费
题解:
反正就是最短路吧,xjb改一下dijkstra就好了
代码:
1 #include <map> 2 #include <set> 3 #include <cmath> 4 #include <queue> 5 #include <stack> 6 #include <cstdio> 7 #include <string> 8 #include <vector> 9 #include <cstdlib> 10 #include <cstring> 11 #include <sstream> 12 #include <iostream> 13 #include <algorithm> 14 #include <functional> 15 using namespace std; 16 #define rep(i,a,n) for (int i=a;i<n;i++) 17 #define per(i,a,n) for (int i=n-1;i>=a;i--) 18 #define all(x) (x).begin(),(x).end() 19 #define pb push_back 20 #define mp make_pair 21 #define lson l,m,rt<<1 22 #define rson m+1,r,rt<<1|1 23 typedef long long ll; 24 typedef vector<int> VI; 25 typedef pair<int, int> PII; 26 const ll MOD = 1e9 + 7; 27 const int INF = 0x3f3f3f3f; 28 const int MAXN = 1e5 + 7; 29 // head 30 31 vector<PII> C[MAXN]; 32 int d[MAXN]; 33 priority_queue<PII, vector<PII>, greater<PII> > que; 34 35 void dijkstra() { 36 while (!que.empty()) { 37 PII p = que.top(); que.pop(); 38 int v = p.second; 39 if (d[v] < p.first) continue; 40 d[v] = p.first; 41 rep(i, 0, C[v].size()) { 42 PII p = C[v][i]; 43 int a = v; 44 int b = p.first; 45 int c = p.second; 46 if (d[c] > d[a] + d[b]) { 47 d[c] = d[a] + d[b]; 48 que.push(mp(d[a] + d[b], c)); 49 } 50 } 51 } 52 } 53 54 int main() { 55 int T; 56 cin >> T; 57 while (T--) { 58 rep(i, 0, MAXN) C[i].clear(); 59 int n, m; 60 cin >> n >> m; 61 rep(i, 1, n + 1) { 62 int a; 63 scanf("%d", &a); 64 d[i] = a; 65 } 66 while (m--) { 67 int a, b, c; 68 scanf("%d%d%d", &a, &b, &c); 69 que.push(mp(d[a]+d[b], c)); 70 C[a].pb(mp(b, c)); 71 C[b].pb(mp(a, c)); 72 } 73 dijkstra(); 74 rep(i, 1, n + 1) { 75 printf("%d", d[i]); 76 if (i == n) printf("\n"); 77 else printf(" "); 78 } 79 } 80 return 0; 81 }
问题 D: rqy的键盘
题意:
为你给个字母按键的左右两边的按键是什么,没有就输出No letter.
题解:
模拟一下就好了
代码:
1 #include <map> 2 #include <set> 3 #include <cmath> 4 #include <queue> 5 #include <stack> 6 #include <cstdio> 7 #include <string> 8 #include <vector> 9 #include <cstdlib> 10 #include <cstring> 11 #include <sstream> 12 #include <iostream> 13 #include <algorithm> 14 #include <functional> 15 using namespace std; 16 #define rep(i,a,n) for (int i=a;i<n;i++) 17 #define per(i,a,n) for (int i=n-1;i>=a;i--) 18 #define all(x) (x).begin(),(x).end() 19 #define pb push_back 20 #define mp make_pair 21 #define lson l,m,rt<<1 22 #define rson m+1,r,rt<<1|1 23 typedef long long ll; 24 typedef vector<int> VI; 25 typedef pair<int, int> PII; 26 const ll MOD = 1e9 + 7; 27 const int INF = 0x3f3f3f3f; 28 const int MAXN = 2010; 29 // head 30 31 string s = " QWERTYUIOPASDFGHJKLZXCVBNM "; 32 33 struct Node { 34 char c, l, r; 35 }node[30]; 36 37 int main() { 38 rep(i, 1, 27) { 39 node[i].c = s[i]; 40 node[i].l = s[i - 1]; 41 node[i].r = s[i + 1]; 42 } 43 node[1].l = ‘0‘; 44 node[11].l = ‘0‘; 45 node[20].l = ‘0‘; 46 node[10].r = ‘0‘; 47 node[19].r = ‘0‘; 48 node[26].r = ‘0‘; 49 int T; 50 cin >> T; 51 while (T--) { 52 char x; 53 string dir; 54 cin >> x >> dir; 55 int pos = s.find(x, 0); 56 char ans; 57 if (dir == "Left") ans = node[pos].l; 58 else ans = node[pos].r; 59 if (ans == ‘0‘) cout << "No letter." << endl; 60 else cout << ans << endl; 61 } 62 return 0; 63 }
问题 F: Hmz 的女装
题意:
你有k种flower,你要编一个长度n的花环,每次要求你第l和第r个位置的必须一样,问你有多少种编法
题解:
这道题可以退化成 你有k种flower,你要编一个长度n的花环有多少种方法,然后就是找规律递推了,注意需要用long long
dp[i] = ((k - 1)*dp[i - 2] + (k - 2)*dp[i - 1]) % MOD;
代码:
1 #include <map> 2 #include <set> 3 #include <cmath> 4 #include <queue> 5 #include <stack> 6 #include <cstdio> 7 #include <string> 8 #include <vector> 9 #include <cstdlib> 10 #include <cstring> 11 #include <sstream> 12 #include <iostream> 13 #include <algorithm> 14 #include <functional> 15 using namespace std; 16 #define rep(i,a,n) for (int i=a;i<n;i++) 17 #define per(i,a,n) for (int i=n-1;i>=a;i--) 18 #define all(x) (x).begin(),(x).end() 19 #define pb push_back 20 #define mp make_pair 21 #define lson l,m,rt<<1 22 #define rson m+1,r,rt<<1|1 23 typedef long long ll; 24 typedef vector<int> VI; 25 typedef pair<int, int> PII; 26 const ll MOD = 1e9 + 7; 27 const int INF = 0x3f3f3f3f; 28 const int MAXN = 1e5 + 7; 29 // head 30 31 ll dp[MAXN]; 32 33 int main() { 34 ll n, m, k; 35 while (cin >> n >> m >> k) { 36 dp[2] = k - 1; 37 dp[3] = (k - 1)*(k - 2); 38 rep(i, 4, n) dp[i] = ((k - 1)*dp[i - 2] + (k - 2)*dp[i - 1]) % MOD; 39 while (m--) { 40 int l, r; 41 scanf("%d%d", &l, &r); 42 if (l > r) swap(l, r); 43 ll ans = k; 44 ans = (ans*dp[r - l]) % MOD; 45 ans = (ans*dp[n - r + l]) % MOD; 46 printf("%lld\n", ans); 47 } 48 } 49 return 0; 50 }
问题 G: 最大子段和
题意:
给你一个字符串,找出奇数长度的最大子段和
题解:
两次循环,分别从第1和第2个循环找一遍就好了
代码:
1 #include <map> 2 #include <set> 3 #include <cmath> 4 #include <queue> 5 #include <stack> 6 #include <cstdio> 7 #include <string> 8 #include <vector> 9 #include <cstdlib> 10 #include <cstring> 11 #include <sstream> 12 #include <iostream> 13 #include <algorithm> 14 #include <functional> 15 using namespace std; 16 #define rep(i,a,n) for (int i=a;i<n;i++) 17 #define per(i,a,n) for (int i=n-1;i>=a;i--) 18 #define all(x) (x).begin(),(x).end() 19 #define pb push_back 20 #define mp make_pair 21 #define lson l,m,rt<<1 22 #define rson m+1,r,rt<<1|1 23 typedef long long ll; 24 typedef vector<int> VI; 25 typedef pair<int, int> PII; 26 const ll MOD = 1e9 + 7; 27 const int INF = 0x3f3f3f3f; 28 const int MAXN = 1e5 + 7; 29 // head 30 31 int a[MAXN]; 32 33 int main() { 34 int T; 35 cin >> T; 36 while (T--) { 37 int n; 38 cin >> n; 39 int n1 = 0, n2 = 0; 40 rep(i, 1, n + 1) scanf("%d", a + i); 41 int sum = a[1], b = a[1]; 42 for (int i = 2; i < n; i += 2) { 43 b += a[i] + a[i + 1]; 44 if (b < a[i + 1]) b = a[i + 1]; 45 if (sum < b) sum = b; 46 } 47 int ans = sum; 48 sum = a[2], b = a[2]; 49 for (int i = 3; i < n; i += 2) { 50 b += a[i] + a[i + 1]; 51 if (b < a[i + 1]) b = a[i + 1]; 52 if (sum < b) sum = b; 53 } 54 ans = max(ans, sum); 55 cout << ans << endl; 56 } 57 return 0; 58 }
问题 H: ch追妹
题意:
给你一个图,你在a点,你的女神在b点,你要到你的女神那里,但是你每走一步,你的情敌就会砍断一条路
而且你的情敌还非常聪明,问你能不能到你的女神那里
题解:
这道题其实就是问你a和b之间有没有一条通路,如果没有就肯定到达不了
比如说你刚到b前一个点,差一步就到了,然后砍了
然后你绕远走,又差一步到了,又砍了。。
除非你直接走到了
代码:
1 #include <map> 2 #include <set> 3 #include <cmath> 4 #include <queue> 5 #include <stack> 6 #include <cstdio> 7 #include <string> 8 #include <vector> 9 #include <cstdlib> 10 #include <cstring> 11 #include <sstream> 12 #include <iostream> 13 #include <algorithm> 14 #include <functional> 15 using namespace std; 16 #define rep(i,a,n) for (int i=a;i<n;i++) 17 #define per(i,a,n) for (int i=n-1;i>=a;i--) 18 #define all(x) (x).begin(),(x).end() 19 #define pb push_back 20 #define mp make_pair 21 #define lson l,m,rt<<1 22 #define rson m+1,r,rt<<1|1 23 typedef long long ll; 24 typedef vector<int> VI; 25 typedef pair<int, int> PII; 26 const ll MOD = 1e9 + 7; 27 const int INF = 0x3f3f3f3f; 28 const int MAXN = 2010; 29 // head 30 31 int main() { 32 int T; 33 cin >> T; 34 while (T--) { 35 int n, m, a, b; 36 cin >> n >> m >> a >> b; 37 string ans = "chsad"; 38 while (m--) { 39 int x, y; 40 cin >> x >> y; 41 if (x == a && y == b || x == b && y == a) ans = "chhappy"; 42 } 43 cout << ans << endl; 44 } 45 return 0; 46 }
问题 I: 小天使改名
题意:
给你两个字符串a,b 问你b是不是由交换一对字母得到的
题解:
这道题有坑,就是还要考虑 如果a和b相等,但是a和b没有重复字母的情况,
这种情况也应该输出NO
代码:
1 #include <map> 2 #include <set> 3 #include <cmath> 4 #include <queue> 5 #include <stack> 6 #include <cstdio> 7 #include <string> 8 #include <vector> 9 #include <cstdlib> 10 #include <cstring> 11 #include <sstream> 12 #include <iostream> 13 #include <algorithm> 14 #include <functional> 15 using namespace std; 16 #define rep(i,a,n) for (int i=a;i<n;i++) 17 #define per(i,a,n) for (int i=n-1;i>=a;i--) 18 #define all(x) (x).begin(),(x).end() 19 #define pb push_back 20 #define mp make_pair 21 #define lson l,m,rt<<1 22 #define rson m+1,r,rt<<1|1 23 typedef long long ll; 24 typedef vector<int> VI; 25 typedef pair<int, int> PII; 26 const ll MOD = 1e9 + 7; 27 const int INF = 0x3f3f3f3f; 28 const int MAXN = 2010; 29 // head 30 31 int main() { 32 int T; 33 cin >> T; 34 while (T--) { 35 string a, b; 36 cin >> a >> b; 37 VI v; 38 rep(i, 0, a.length()) if (a[i] != b[i]) v.pb(i); 39 if (v.size() == 0) { 40 string s = a; 41 sort(all(s)); 42 int fg = 0; //如果两个字符串一样 但是没有出现相同字符 43 rep(i, 1, s.length()) if (s[i] == s[i - 1]) fg = 1; 44 if (fg) cout << "YES" << endl; 45 else cout << "NO" << endl; 46 } 47 else if (v.size() == 2) { 48 if (a[v[0]] == b[v[1]] && a[v[1]] == b[v[0]]) cout << "YES" << endl; 49 else cout << "NO" << endl; 50 } 51 else cout << "NO" << endl; 52 } 53 return 0; 54 }
问题 J: 爱看电视的LsF
题意:
给你一个坏掉几个数字键的遥控器,问你最少需要按多少次键能从a台到b台
题解:
比赛时模拟了好久之后,队友说这道题可以暴力写。。那就没什么好说的了
注意0的判断
代码:
1 #include <map> 2 #include <set> 3 #include <cmath> 4 #include <queue> 5 #include <stack> 6 #include <cstdio> 7 #include <string> 8 #include <vector> 9 #include <cstdlib> 10 #include <cstring> 11 #include <sstream> 12 #include <iostream> 13 #include <algorithm> 14 #include <functional> 15 using namespace std; 16 #define rep(i,a,n) for (int i=a;i<n;i++) 17 #define per(i,a,n) for (int i=n-1;i>=a;i--) 18 #define all(x) (x).begin(),(x).end() 19 #define pb push_back 20 #define mp make_pair 21 #define lson l,m,rt<<1 22 #define rson m+1,r,rt<<1|1 23 typedef long long ll; 24 typedef vector<int> VI; 25 typedef pair<int, int> PII; 26 const ll MOD = 1e9 + 7; 27 const int INF = 0x3f3f3f3f; 28 const int MAXN = 2010; 29 // head 30 31 int good[20]; 32 33 bool check(int x) { 34 if (x == 0) return good[x]; 35 while (x) { 36 if (!good[x % 10]) return false; 37 x /= 10; 38 } 39 return true; 40 } 41 42 int num_len(int x) { 43 int s = x == 0 ? 1 : 0; 44 while (x) x /= 10, s++; 45 return s; 46 } 47 48 int main() { 49 int n, s, t; 50 while (cin >> n >> s >> t) { 51 rep(i, 0, 10) good[i] = 1; 52 rep(i, 0, n) { 53 int t; 54 cin >> t; 55 good[t] = 0; 56 } 57 int ans = abs(t - s); 58 int step = ans; 59 rep(i, 0, step) { 60 int l = t - i; 61 int r = t + i; 62 if (l >= 0 && check(l)) ans = min(ans, i + num_len(l)); 63 if (check(r)) ans = min(ans, i + num_len(r)); 64 } 65 cout << ans << endl; 66 } 67 return 0; 68 }
以上是关于河南工业大学2017校赛题解的主要内容,如果未能解决你的问题,请参考以下文章