BestCoder Round #92 (hdu 6015 6016)

比赛链接

A题主要是map的使用,比赛的时候问了下队友,下次要记住了

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

LL T,n;
map<string,int> mp1,mp2;

int main()
{
    cin>>T;
    while(T--)
    {
        mp1.clear();mp2.clear();
        cin>>n;
        for(int i=0;i<n;i++)
        {
            string str;
            int t;
            cin>>str>>t;
            if(mp1[str]<t)
            {
                mp2[str]=mp1[str];
                mp1[str]=t;
            }
            else if(mp2[str]<t)
            {
                mp2[str]=t;
            }
        }
        int ans=0;
        for(map<string,int>::iterator it=mp1.begin();it!=mp1.end();++it)
            ans+=it->second;
        for(map<string,int>::iterator it=mp2.begin();it!=mp2.end();++it)
            ans+=it->second;
        cout<<ans<<endl;
    }
}
hdu_6015

B题算是道组合数学吧,枚举可能满足条件的 -B-C- (也即-C-B),以BC为中间二点的满足条件的序列数=(du[B]-1)*(du[C]-1)*2

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

LL du[200005];
struct Edge
{
    LL u,v;
}e[100005];

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    LL T,n,m,k;
    cin>>T;
    while(T--)
    {
        memset(du,0,sizeof(du));
        cin>>n>>m>>k;
        for(int i=0;i<k;i++)
        {
            LL u,v;
            cin>>u>>v;
            du[u]++,du[n+v]++;
            e[i]=(Edge){u,v+n};
        }
        LL ans=0;
        for(int i=0;i<k;i++)
            ans+=(du[e[i].u]-1)*(du[e[i].v]-1)*2;
        cout<<ans<<endl;
    }
}
hdu_6016
原文地址:https://www.cnblogs.com/Just--Do--It/p/6442931.html