题目链接:
https://vjudge.net/contest/152755#overview
A - Skip the Class
HDU - 6015
思路:贪一贪
AC代码:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using namespace std;
struct ss
{
    string les;
    int val;
};
int cmp(ss x, ss y)
{
    if(x.les == y.les)
    return x.val > y.val;
    return x.les > y.les;
}
int main()
{
    int t, n, ans, flag;
    while(~scanf("%d",&t))
    {
        while(t--)
        {
            map<string, int> qq;
            ss f[105];
            ans = flag = 0;
            scanf("%d",&n);
            for(int i = 0; i < n; ++i)
                cin >> f[i].les >> f[i].val;
            sort(f, f+n, cmp);
            for(int i = 0; i < n; ++i)
            {
                //cout << f[i].les << endl;
                //cout << f[i].val << endl;
                qq[f[i].les]++;
                if(qq[f[i].les] <= 2) ans += f[i].val;
            }
            cout << ans << endl;
        }
    }
    return 0;
}
B - Count the Sheep
HDU - 6016
思维练习。(数据比较大,用cin会超时)
题意:有n只公羊和m只母羊,以及k个关系,k个关系为编号为x的公羊和编号为y的母羊是好朋友。问从任意一只羊开始沿着朋友关系数够4只羊的方法有多少种。
思路:可以把给出的关系构造成一个图来看,从任意一点出发,沿着关系网找到目标。拿第一个样例来说,(为方便观察把母羊编号为3和4)从公羊出发的不同方式为1324,1423,2314,2413共四种,同理,从母羊出发也是四种(把母羊看作1,2,把公羊看作3,4),到这里,我们能看出:从公羊出发的情况乘以二就是答案。而从公羊出发到不同母羊的情况数就等于(这个公羊的度-1)*(母羊的度-1)(度是指与这个点相连的点的个数).
AC代码:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using namespace std;
typedef long long LL;
const int maxn = 100005;
LL a[maxn], b[maxn], na[maxn], nb[maxn];
int main()
{
    int t;
    int n, m, k;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d",&n,&m,&k);
        memset(na, 0, sizeof(na));
        memset(nb, 0, sizeof(nb));
        for(int i = 0; i < k; ++i)
        {
            scanf("%lld%lld",&a[i],&b[i]);
            na[a[i]]++;
            nb[b[i]]++;
        }
        LL sum = 0;
        for(int i = 0; i < k; ++i)
            sum += (na[a[i]] - 1) * (nb[b[i]] - 1);
        printf("%lld\n",sum << 1);
    }
    return 0;
}
C - Lotus and Characters
HDU - 6011
开始以为是不要负数,自始至终一直在这样做。看两队1A了,继续提交,继续WA。
这道题看完样例后很多人会和我一样误认为把负数都不算上才能得出最优解,其实不然。给出两组测试数据就知道了:
| 1 | 3 -1 3 2 1 1 1 答案:8 | 
正确的做法是把所有数据从大到小排序,然后从前往后加,直到新加的数小于0时停止相加。其实理解了就很简单。
AC代码:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using namespace std;
struct ss
{
    int val;
    int amo;
};
int cmp(ss x, ss y)
{
    return x. val > y.val;
}
int main()
{
    int t, n;
    long long cnt, ans;
    while(~scanf("%d",&t))
    {
        while(t--)
        {
            cnt = ans = 0;
            ss f[30];
            scanf("%d",&n);
            for(int i = 0; i < n; ++i)
                scanf("%d%d",&f[i].val, &f[i].amo);
            sort(f, f+n, cmp);
            for(int i = 0; i < n; ++i)
            {
                for(int j = 0; j < f[i].amo; ++j)
                {
                    cnt += f[i].val;
                    if(cnt < 0) break;
                    ans += cnt;
                }
            }
            cout << ans << endl;
        }
    }
    return 0;
}
D - Lotus and Horticulture
HDU - 6012
思维。
在温室里种花,给出n朵花的适宜生长温度,如果温室温度在这范围内的话,成熟后的每朵花价值为a,高于所给温度,价值为b,低于所给温度,价值为c。问需要让温室温度为多少才能获得最大价值。
一开始让室内温度为-inf,此时答案为∑c,然后模拟温度上升,不断更新最大价值,直到达到所给的最大温度。
这个过程可以用map来实现,first为温度,second为价值。
(这里的温度可以是实数,所以用到了点小技巧:让温度都扩大两倍避免了出现小数的情况)
AC代码:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using namespace std;
typedef long long LL;
const int maxn = 50005;
int main()
{
    int t, n;
    int l, r, x, y, z;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        map<int, LL> s;
        while(n--)
        {
            scanf("%d%d%d%d%d",&l,&r,&x,&y,&z);
            s[0] += z;
            s[l * 2] += x - z;
            s[r * 2 + 1] += y - x;
        }
        LL ans = 0;
        LL tem = 0;
        for(map<int,LL>::iterator it = s.begin(); it != s.end(); ++it)
        {
            tem += it -> second;
            ans = max(ans, tem);
        }
        cout << ans << endl;
    }
    return 0;
}
E - The Third Cup is Free
HDU - 5999
一眼看出是贪心,然后全部浏览完一遍题目后,把这道题敲完交上,9minA了全场第一题。
AC代码:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using namespace std;
int a[100005];
int main()
{
    int t, n, ans, flag, cou = 0;
    while(~scanf("%d",&t))
    {
        while(t--)
        {
            ans = flag = 0;
            scanf("%d",&n);
            for(int i = 0; i < n; ++i)
                scanf("%d",&a[i]);
            sort(a, a+n);
            for(int i = n-1; i >= 0; --i)
            {
                if(flag == 2)
                {
                    flag = 0;
                    continue;
                }
                flag++;
                ans += a[i];
            }
            printf("Case #%d: ",++cou);
            cout << ans << endl;
        }
    }
    return 0;
}
F - Pseudoprime numbers
HDU - 1905
数论。
题目解法:先判断p是不是合数,是的话再判断a的p次方%p是否等于a,是输出yes,否输出no,简单地题套个快速幂模板一套带走..
AC代码:
| 1 | 
 | 
G - 小明系列问题――小明序列
HDU - 4521
最长上升子序列的O(nlogn)算法。
AC代码:
| 1 | 
 | 
H - Doing Homework again
HDU - 1789
上学期,江西师范新生赛见过这道题,当时排序是按的时间优先,后来看题解知道应该分数优先。这也是道贪心哦。
AC代码:
| 1 | 
 | 
I - 敌兵布阵
HDU - 1166
这个以为是模拟,结果TLE,赛后得知要用线段树或树状数组,会了的话这就是道裸题。
【补】AC代码:
| 1 | 
 | 
 
        