zoukankan      html  css  js  c++  java
  • 河南工业大学2017校赛题解

    题目提交地址:http://218.28.220.249:50015/JudgeOnline/problemset.php?page=3

     

    问题 A: 饶学妹的比赛

    题意:

    给你一场比赛每人提交的记录,计算最后的排名

    题解:

    模拟+排序

    代码:

    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/d²的伤害(d为距离)

    求这个人必须有多少HP,才永远不会死

    题解:

    就是一道数值积分,直接套模板就行了,但是:

    这道题数据有误!

    这道题数据有误!!

    这道题数据有误!!!

    你想啊,如果积分值为2.354,那不得有2.36的血才行吗,所以是不能四舍五入的,不然你就挂了

    但是答案是四舍五入啊啊啊,

    我们比赛时wa了50+都没想到是出题人sb啊

    “AC”代码如下

    代码:

    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 ", ans); 58 } 59 return 0; 60

    问题 C: 魔法宝石

    题意:

    创造第i个宝石需要a[i]MP,或者可以两个合成一个,不需要MP,问你合成每个的最小MP

    题解:

    反正就是最短路吧,xjb改一下dijkstra就好了

    代码:

    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("
    ");
    77             else printf(" ");
    78         }
    79     }
    80     return 0;
    81

    问题 D: rqy的键盘

    题意:

    为你给个字母按键的左右两边的按键是什么,没有就输出No letter.

    题解:

    模拟一下就好了

    代码:

    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;

    代码:

    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
    ", ans);
    47         }
    48     }
    49     return 0;
    50

    问题 G: 最大子段和

    题意:

    给你一个字符串,找出奇数长度的最大子段和

    题解:

    两次循环,分别从第1和第2个循环找一遍就好了

    代码:

    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前一个点,差一步就到了,然后砍了

    然后你绕远走,又差一步到了,又砍了。。

    除非你直接走到了

    代码:

    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交换一对字母得到的

    题解:

    这道题有坑,就是还要考虑 如果a和b相等,但是a和b没有重复字母的情况,

    这种情况也应该输出NO

    代码:

    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的判断

    代码:

    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 }
  • 相关阅读:
    【Spring】9、Spring中的事件Event
    【Spring】8、Spring框架中的单例Beans是线程安全的么
    【Spring】7、拦截器HandlerInterceptor
    【Spring】5、利用自定义注解在SpringMVC中实现自定义权限检查
    【Spring】4、Spring中 @Autowired标签与 @Resource标签 的区别
    【Dubbo&&Zookeeper】2、 windows平台dubbo-admin管理平台搭建
    【Dubbo&&Zookeeper】4、 Java实现Dubbo服务提供者及消费者注册
    【Dubbo&&Zookeeper】3、Failed to read schema document 'http://code.alibabatech.com/schema/dubbo/dubbo.xsd'问题解决方法
    【Dubbo&&Zookeeper】1、Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)
    【Spring】3、BeanFactory 和 ApplicationContext的区别
  • 原文地址:https://www.cnblogs.com/baocong/p/6753362.html
Copyright © 2011-2022 走看看