2016.2.26 ACM讨论群群赛 ABCDEF

来源:互联网 发布:链接优化百度百科 编辑:程序博客网 时间:2024/06/03 22:45

套题链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=107574#overview

难度类型:偏想法,前两题比较基础,数据结构和图论代码量较大。

A

题解

类型:模拟

根据优先级去模拟运算即可,Python好像都可以直接算出来。

#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <cstring>#include <stack>#include <queue>#include <string>#include <vector>#include <set>#include <map>#define fi first#define se secondusing namespace std;typedef long long LL;typedef pair<int,int> PII;// headchar op1[5];char op2[5];map<char, int> ma;void init() {    ma['+'] = ma['-'] = 0;    ma['*'] = ma['/'] = ma['%'] = 1;}int cal(int a, int b, char op) {    if (op == '+') return a + b;    if (op == '-') return a - b;    if (op == '*') return a * b;    if (op == '/') return a / b;    if (op == '%') return a % b;}int main() {    init();    int a, b, c, t;    scanf("%d", &t);    while (t--) {        scanf("%d%s%d%s%d", &a, op1, &b, op2, &c);        if (ma[op1[0]] < ma[op2[0]]) {            b = cal(b, c, op2[0]);            a = cal(a, b, op1[0]);        } else {            a = cal(a, b, op1[0]);            a = cal(a, c, op2[0]);        }        printf("%d\n", a);    }    return 0;}

B

题解

类型:图论,bfs

传送门:http://blog.csdn.net/xc19952007/article/details/50756724

C

题解

类型:技巧

传送门:http://blog.csdn.net/xc19952007/article/details/50756558

D

题解

类型:树状数组

传送门:http://blog.csdn.net/xc19952007/article/details/50756671

E

题解

类型:二分,模拟

传送门:http://blog.csdn.net/xc19952007/article/details/50756593

F

题解

类型:贪心

每次取最短的两段去合并,这个可以用一个堆去维护。

#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <cstring>#include <stack>#include <queue>#include <string>#include <vector>#include <set>#include <map>#define fi first#define se secondusing namespace std;typedef long long LL;typedef pair<int,int> PII;// headint main() {    int t, n, x;    scanf("%d", &t);    while (t--) {        scanf("%d", &n);        priority_queue<int> q;        for (int i = 0; i < n; i++) {            scanf("%d", &x);            q.push(-x);        }        int ans = 0;        while (q.size() > 1) {            int a = q.top();            q.pop();            int b = q.top();            q.pop();            ans -= a + b;            q.push(a + b);        }        printf("%d\n", ans);    }    return 0;}
0 0