2016.2.26 ACM讨论群群赛 ABCDEF

套题链接: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 second
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
// head
char 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.youkuaiyun.com/xc19952007/article/details/50756724

C

题解

类型:技巧

传送门:http://blog.youkuaiyun.com/xc19952007/article/details/50756558

D

题解

类型:树状数组

传送门:http://blog.youkuaiyun.com/xc19952007/article/details/50756671

E

题解

类型:二分,模拟

传送门:http://blog.youkuaiyun.com/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 second
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
// head

int 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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值