HDU degree 6380 & HDU 6385 rect

2018 “百度之星”程序设计大赛 - 初赛(B)
HDU 6380 degree

#include
#include 
#include
#include
#include
using namespace std;
const int N=2*1e5+10;
int fa[N];
int de[N];
int find(int a)
{
    return fa[a]==a?a:fa[a]=find(fa[a]);
}

int main()
{
    int T;
    int n,m,k;
    int a,b;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d%d",&n,&m,&k);
        for(int i=0;i0;
        for(int i=0;iscanf("%d%d",&a,&b);
            de[a]++;de[b]++;
            int ua=find(a);
            int ub=find(b);
            if(ua!=ub) ua>ub?fa[ua]=fa[ub]:fa[ub]=fa[ua];
        }
        int cnt=0;
        sort(de,de+n);
        for(int i=0;iint uf=find(i);
            if(uf==i) cnt++; 
            //cout<
        }
        int ans=de[n-1]+cnt-1;
        if(ans+k>n-1) printf("%d\n",n-1);
        else printf("%d\n",ans+k);
    }
    return 0;
}

HDU 6385 rect

#include
#include
using namespace std;
typedef long long ll;
int main()
{
    ll x,y,n,a,b;
    ll t;
    scanf("%lld",&t);
    while(t--)
    {
        ll ans=0;
        scanf("%lld%lld%lld",&x,&y,&n);
        for(int i=0;iscanf("%lld%lld",&a,&b);
            int h=min(a,x-a);
            int s=min(b,y-b);
            ans+=min(h,s);
        }
        printf("%lld\n",ans);
    }
    return 0;
}

你可能感兴趣的:(HDU)